Skip to content

Commit

Permalink
test: add duration instantiation test
Browse files Browse the repository at this point in the history
  • Loading branch information
RutZap committed Jan 21, 2025
1 parent bf079e1 commit 578e985
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/functions-runtime/src/Duration.test.js
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");
});

0 comments on commit 578e985

Please sign in to comment.