A Yaak plugin that provides Day.js date/time manipulation functions as template functions for API testing and development.
A Yaak plugin that provides Day.js date/time manipulation functions as template functions for API testing and development.
This plugin extends Yaak with powerful date/time manipulation capabilities using Day.js, a lightweight alternative to Moment.js.
dayjsConverts dates to ISO format or UTC JSON format.
Parameters:
dateTime (optional): Base date/time string. Leave empty for current date/timetoUTCTime (optional): Convert to UTC formatExamples:
{{dayjs()}} - Current date/time in local format{{dayjs("2024-01-15")}} - Specific date in local format{{dayjs("2024-01-15", true)}} - Specific date in UTC formatdayjs.formatFormats dates using custom format strings.
Parameters:
dateTime: Base date/time stringformat: Format pattern (optional, defaults to “YYYY-MM-DD HH:mm:ss”)Examples:
{{dayjs.format("2024-01-15T12:00:00", "MMM DD, YYYY")}} - “Jan 15, 2024”{{dayjs.format("2024-01-15T12:00:00", "dddd, MMMM Do YYYY")}} - “Monday, January 15th 2024”dayjs.fromShows relative time from one date to another.
Parameters:
dateTime: Target date/timefromDate: Reference date/timeExamples:
{{dayjs.from("2024-01-15", "2024-01-10")}} - “5 days ago”{{dayjs.from("2024-02-01", "2024-01-01")}} - “in a month”dayjs.toISOStringConverts dates to ISO 8601 string format.
Parameters:
dateTime: Date/time string to convertExamples:
{{dayjs.toISOString("2024-01-15T12:00:00")}} - “2024-01-15T12:00:00.000Z”Use the template functions anywhere in your HTTP requests:
POST {{baseUrl}}/api/events
Content-Type: application/json
Authorization: Bearer {{authToken}}
{
"created_at": "{{dayjs()}}",
"formatted_date": "{{dayjs.format("2024-01-15", "MMM DD, YYYY")}}",
"relative_time": "{{dayjs.from("2024-01-15", "2024-01-10")}}"
}
The plugin automatically validates input dates. If an invalid date is provided, it will:
This plugin includes the following Day.js plugins:
| Pattern | Example Output | Description |
|---|---|---|
YYYY-MM-DD |
2024-01-15 | ISO date |
HH:mm:ss |
14:30:45 | 24-hour time |
MMM DD, YYYY |
Jan 15, 2024 | Short date |
dddd, MMMM Do YYYY |
Monday, January 15th 2024 | Full date |
YYYY-MM-DDTHH:mm:ss.SSSZ |
2024-01-15T14:30:45.123Z | ISO datetime |
git clone https://github.com/aleksanderwalczuk/yaak-dayjs-plugin.git
cd yaak-dayjs-plugin
pnpm install
pnpm build
pnpm test
pnpm lint
pnpm lint:fix
pnpm testUNLICENSED
Aleksander Walczuk - ohleg@windowslive.com