-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add duration instantiation test
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { test, expect } from "vitest"; | ||
const { Duration } = require("./Duration"); | ||
|
||
test("fromISOString test", async () => { | ||
const fullDate = Duration.fromISOString("P1Y2M3DT4H5M6S"); | ||
expect(fullDate.toISOString()).toEqual("P1Y2M3DT4H5M6S"); | ||
expect(fullDate.toPostgres()).toEqual( | ||
"1 years 2 months 3 days 4 hours 5 minutes 6 seconds" | ||
); | ||
const dateOnly = Duration.fromISOString("P2Y3M4D"); | ||
expect(dateOnly.toISOString()).toEqual("P2Y3M4D"); | ||
expect(dateOnly.toPostgres()).toEqual("2 years 3 months 4 days"); | ||
const timeOnly = Duration.fromISOString("PT4H5M6S"); | ||
expect(timeOnly.toISOString()).toEqual("PT4H5M6S"); | ||
expect(timeOnly.toPostgres()).toEqual("4 hours 5 minutes 6 seconds"); | ||
const years = Duration.fromISOString("P10Y"); | ||
expect(years.toISOString()).toEqual("P10Y"); | ||
expect(years.toPostgres()).toEqual("10 years"); | ||
const months = Duration.fromISOString("P20M"); | ||
expect(months.toISOString()).toEqual("P20M"); | ||
expect(months.toPostgres()).toEqual("20 months"); | ||
const days = Duration.fromISOString("P31D"); | ||
expect(days.toISOString()).toEqual("P31D"); | ||
expect(days.toPostgres()).toEqual("31 days"); | ||
const hours = Duration.fromISOString("PT4H"); | ||
expect(hours.toISOString()).toEqual("PT4H"); | ||
expect(hours.toPostgres()).toEqual("4 hours"); | ||
const minutes = Duration.fromISOString("PT61M"); | ||
expect(minutes.toISOString()).toEqual("PT61M"); | ||
expect(minutes.toPostgres()).toEqual("61 minutes"); | ||
const seconds = Duration.fromISOString("PT76S"); | ||
expect(seconds.toISOString()).toEqual("PT76S"); | ||
expect(seconds.toPostgres()).toEqual("76 seconds"); | ||
}); |