Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohd-akram committed Jan 30, 2023
1 parent b767694 commit 88f3ba5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
node-version: [18.9]
node-version: [18.13]

steps:
- uses: actions/checkout@v2
Expand Down
14 changes: 7 additions & 7 deletions test/datetime/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,34 +376,34 @@ test("DateTime#toLocaleString() returns something different for invalid DateTime

test("DateTime#toLocaleString() shows things in the right IANA zone", () => {
expect(dt.setZone("America/New_York").toLocaleString(DateTime.DATETIME_SHORT)).toBe(
"5/25/1982, 5:23 AM"
"5/25/1982, 5:23AM"
);
});

test("DateTime#toLocaleString() shows things in the right fixed-offset zone", () => {
expect(dt.setZone("UTC-8").toLocaleString(DateTime.DATETIME_SHORT)).toBe("5/25/1982, 1:23 AM");
expect(dt.setZone("UTC-8").toLocaleString(DateTime.DATETIME_SHORT)).toBe("5/25/1982, 1:23AM");
});

test("DateTime#toLocaleString() shows things in the right fixed-offset zone when showing the zone", () => {
expect(dt.setZone("UTC-8").toLocaleString(DateTime.DATETIME_FULL)).toBe(
"May 25, 1982 at 1:23 AM GMT-8"
"May 25, 1982 at 1:23AM GMT-8"
);
});

test("DateTime#toLocaleString() shows things with UTC if fixed-offset zone with 0 offset is used", () => {
expect(dt.setZone("UTC").toLocaleString(DateTime.DATETIME_FULL)).toBe(
"May 25, 1982 at 9:23 AM UTC"
"May 25, 1982 at 9:23AM UTC"
);
});

test("DateTime#toLocaleString() does the best it can with unsupported fixed-offset zone when showing the zone", () => {
expect(dt.setZone("UTC+4:30").toLocaleString(DateTime.DATETIME_FULL)).toBe(
"May 25, 1982 at 9:23 AM UTC"
"May 25, 1982 at 9:23AM UTC"
);
});

test("DateTime#toLocaleString uses locale-appropriate time formats", () => {
expect(dt.reconfigure({ locale: "en-US" }).toLocaleString(DateTime.TIME_SIMPLE)).toBe("9:23 AM");
expect(dt.reconfigure({ locale: "en-US" }).toLocaleString(DateTime.TIME_SIMPLE)).toBe("9:23AM");
expect(dt.reconfigure({ locale: "en-US" }).toLocaleString(DateTime.TIME_24_SIMPLE)).toBe("09:23");

// France has 24-hour time by default
Expand All @@ -429,7 +429,7 @@ test("DateTime#toLocaleString() accepts a zone even when the zone is set", () =>
timeZoneName: "short",
timeZone: "America/Los_Angeles",
})
).toBe("2:23 AM PDT");
).toBe("2:23AM PDT");
});

//------
Expand Down
60 changes: 30 additions & 30 deletions test/datetime/toFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ test("DateTime#toFormat('DDDD') returns a long date representation", () => {
});

test("DateTime#toFormat('t') returns a short time representation", () => {
expect(dt.toFormat("t")).toBe("9:23 AM");
expect(dt.set({ hour: 13 }).toFormat("t")).toBe("1:23 PM");
expect(dt.toFormat("t")).toBe("9:23AM");
expect(dt.set({ hour: 13 }).toFormat("t")).toBe("1:23PM");
expect(dt.reconfigure({ locale: "fr" }).toFormat("t")).toBe("09:23");
expect(dt.set({ hour: 13 }).reconfigure({ locale: "fr" }).toFormat("t")).toBe("13:23");
});
Expand All @@ -384,8 +384,8 @@ test("DateTime#toFormat('T') returns a short 24-hour time representation", () =>
});

test("DateTime#toFormat('tt') returns a medium time representation", () => {
expect(dt.toFormat("tt")).toBe("9:23:54 AM");
expect(dt.set({ hour: 13 }).toFormat("tt")).toBe("1:23:54 PM");
expect(dt.toFormat("tt")).toBe("9:23:54AM");
expect(dt.set({ hour: 13 }).toFormat("tt")).toBe("1:23:54PM");
expect(dt.reconfigure({ locale: "fr" }).toFormat("tt")).toBe("09:23:54");
expect(dt.set({ hour: 13 }).reconfigure({ locale: "fr" }).toFormat("tt")).toBe("13:23:54");
});
Expand Down Expand Up @@ -414,16 +414,16 @@ test("DateTime#toFormat('TTT') returns a medium time representation", () => {
});

test("DateTime#toFormat('f') returns a short date/time representation without seconds", () => {
expect(dt.toFormat("f")).toBe("5/25/1982, 9:23 AM");
expect(dt.set({ hour: 13 }).toFormat("f")).toBe("5/25/1982, 1:23 PM");
expect(dt.toFormat("f")).toBe("5/25/1982, 9:23AM");
expect(dt.set({ hour: 13 }).toFormat("f")).toBe("5/25/1982, 1:23PM");
expect(dt.reconfigure({ locale: "fr" }).toFormat("f")).toBe("25/05/1982 09:23");
expect(dt.set({ hour: 13 }).reconfigure({ locale: "fr" }).toFormat("f")).toBe("25/05/1982 13:23");
});

test("DateTime#toFormat('ff') returns a medium date/time representation without seconds", () => {
expect(dt.toFormat("ff")).toBe("May 25, 1982, 9:23 AM");
expect(dt.set({ hour: 13 }).toFormat("ff")).toBe("May 25, 1982, 1:23 PM");
expect(dt.set({ month: 8 }).toFormat("ff")).toBe("Aug 25, 1982, 9:23 AM");
expect(dt.toFormat("ff")).toBe("May 25, 1982, 9:23AM");
expect(dt.set({ hour: 13 }).toFormat("ff")).toBe("May 25, 1982, 1:23PM");
expect(dt.set({ month: 8 }).toFormat("ff")).toBe("Aug 25, 1982, 9:23AM");
expect(dt.reconfigure({ locale: "fr" }).toFormat("ff")).toBe("25 mai 1982, 09:23");
expect(dt.set({ month: 2 }).reconfigure({ locale: "fr" }).toFormat("ff")).toBe(
"25 févr. 1982, 09:23"
Expand All @@ -434,9 +434,9 @@ test("DateTime#toFormat('ff') returns a medium date/time representation without
});

test("DateTime#toFormat('fff') returns a medium date/time representation without seconds", () => {
expect(ny.toFormat("fff")).toBe("May 25, 1982 at 9:23 AM EDT");
expect(ny.set({ hour: 13 }).toFormat("fff")).toBe("May 25, 1982 at 1:23 PM EDT");
expect(ny.set({ month: 8 }).toFormat("fff")).toBe("August 25, 1982 at 9:23 AM EDT");
expect(ny.toFormat("fff")).toBe("May 25, 1982 at 9:23AM EDT");
expect(ny.set({ hour: 13 }).toFormat("fff")).toBe("May 25, 1982 at 1:23PM EDT");
expect(ny.set({ month: 8 }).toFormat("fff")).toBe("August 25, 1982 at 9:23AM EDT");
expect(ny.reconfigure({ locale: "fr" }).toFormat("fff")).toBe("25 mai 1982 à 09:23 UTC−4");
expect(ny.set({ month: 2 }).reconfigure({ locale: "fr" }).toFormat("fff")).toBe(
"25 février 1982 à 09:23 UTC−5"
Expand All @@ -447,37 +447,37 @@ test("DateTime#toFormat('fff') returns a medium date/time representation without
});

test("DateTime#toFormat('ffff') returns a long date/time representation without seconds", () => {
expect(ny.toFormat("ffff")).toBe("Tuesday, May 25, 1982 at 9:23 AM Eastern Daylight Time");
expect(ny.toFormat("ffff")).toBe("Tuesday, May 25, 1982 at 9:23AM Eastern Daylight Time");
expect(ny.set({ hour: 13 }).toFormat("ffff")).toBe(
"Tuesday, May 25, 1982 at 1:23 PM Eastern Daylight Time"
"Tuesday, May 25, 1982 at 1:23PM Eastern Daylight Time"
);
expect(ny.set({ month: 2 }).toFormat("ffff")).toBe(
"Thursday, February 25, 1982 at 9:23 AM Eastern Standard Time"
"Thursday, February 25, 1982 at 9:23AM Eastern Standard Time"
);
expect(ny.reconfigure({ locale: "fr" }).toFormat("ffff")).toBe(
"mardi 25 mai 1982 à 09:23 heure d’été de l’Est"
"mardi 25 mai 1982 à 09:23 heure d’été de l’Est nord-américain"
);
expect(ny.set({ month: 2 }).reconfigure({ locale: "fr" }).toFormat("ffff")).toBe(
"jeudi 25 février 1982 à 09:23 heure normale de l’Est nord-américain"
);
expect(ny.set({ hour: 13 }).reconfigure({ locale: "fr" }).toFormat("ffff")).toBe(
"mardi 25 mai 1982 à 13:23 heure d’été de l’Est"
"mardi 25 mai 1982 à 13:23 heure d’été de l’Est nord-américain"
);
});

test("DateTime#toFormat('F') returns a short date/time representation with seconds", () => {
expect(dt.toFormat("F")).toBe("5/25/1982, 9:23:54 AM");
expect(dt.set({ hour: 13 }).toFormat("F")).toBe("5/25/1982, 1:23:54 PM");
expect(dt.toFormat("F")).toBe("5/25/1982, 9:23:54AM");
expect(dt.set({ hour: 13 }).toFormat("F")).toBe("5/25/1982, 1:23:54PM");
expect(dt.reconfigure({ locale: "fr" }).toFormat("F")).toBe("25/05/1982 09:23:54");
expect(dt.set({ hour: 13 }).reconfigure({ locale: "fr" }).toFormat("F")).toBe(
"25/05/1982 13:23:54"
);
});

test("DateTime#toFormat('FF') returns a medium date/time representation with seconds", () => {
expect(dt.toFormat("FF")).toBe("May 25, 1982, 9:23:54 AM");
expect(dt.set({ hour: 13 }).toFormat("FF")).toBe("May 25, 1982, 1:23:54 PM");
expect(dt.set({ month: 8 }).toFormat("FF")).toBe("Aug 25, 1982, 9:23:54 AM");
expect(dt.toFormat("FF")).toBe("May 25, 1982, 9:23:54AM");
expect(dt.set({ hour: 13 }).toFormat("FF")).toBe("May 25, 1982, 1:23:54PM");
expect(dt.set({ month: 8 }).toFormat("FF")).toBe("Aug 25, 1982, 9:23:54AM");
expect(dt.reconfigure({ locale: "fr" }).toFormat("FF")).toBe("25 mai 1982, 09:23:54");
expect(dt.set({ month: 2 }).reconfigure({ locale: "fr" }).toFormat("FF")).toBe(
"25 févr. 1982, 09:23:54"
Expand All @@ -488,9 +488,9 @@ test("DateTime#toFormat('FF') returns a medium date/time representation with sec
});

test("DateTime#toFormat('FFF') returns a medium date/time representation without seconds", () => {
expect(ny.toFormat("FFF")).toBe("May 25, 1982 at 9:23:54 AM EDT");
expect(ny.set({ hour: 13 }).toFormat("FFF")).toBe("May 25, 1982 at 1:23:54 PM EDT");
expect(ny.set({ month: 8 }).toFormat("FFF")).toBe("August 25, 1982 at 9:23:54 AM EDT");
expect(ny.toFormat("FFF")).toBe("May 25, 1982 at 9:23:54AM EDT");
expect(ny.set({ hour: 13 }).toFormat("FFF")).toBe("May 25, 1982 at 1:23:54PM EDT");
expect(ny.set({ month: 8 }).toFormat("FFF")).toBe("August 25, 1982 at 9:23:54AM EDT");
expect(ny.reconfigure({ locale: "fr" }).toFormat("FFF")).toBe("25 mai 1982 à 9:23:54 UTC−4");
expect(ny.set({ month: 2 }).reconfigure({ locale: "fr" }).toFormat("FFF")).toBe(
"25 février 1982 à 9:23:54 UTC−5"
Expand All @@ -501,21 +501,21 @@ test("DateTime#toFormat('FFF') returns a medium date/time representation without
});

test("DateTime#toFormat('FFFF') returns a long date/time representation without seconds", () => {
expect(ny.toFormat("FFFF")).toBe("Tuesday, May 25, 1982 at 9:23:54 AM Eastern Daylight Time");
expect(ny.toFormat("FFFF")).toBe("Tuesday, May 25, 1982 at 9:23:54AM Eastern Daylight Time");
expect(ny.set({ hour: 13 }).toFormat("FFFF")).toBe(
"Tuesday, May 25, 1982 at 1:23:54 PM Eastern Daylight Time"
"Tuesday, May 25, 1982 at 1:23:54PM Eastern Daylight Time"
);
expect(ny.set({ month: 2 }).toFormat("FFFF")).toBe(
"Thursday, February 25, 1982 at 9:23:54 AM Eastern Standard Time"
"Thursday, February 25, 1982 at 9:23:54AM Eastern Standard Time"
);
expect(ny.reconfigure({ locale: "fr" }).toFormat("FFFF")).toBe(
"mardi 25 mai 1982 à 9:23:54 heure d’été de l’Est"
"mardi 25 mai 1982 à 9:23:54 heure d’été de l’Est nord-américain"
);
expect(ny.set({ month: 2 }).reconfigure({ locale: "fr" }).toFormat("FFFF")).toBe(
"jeudi 25 février 1982 à 9:23:54 heure normale de l’Est nord-américain"
);
expect(ny.set({ hour: 13 }).reconfigure({ locale: "fr" }).toFormat("FFFF")).toBe(
"mardi 25 mai 1982 à 13:23:54 heure d’été de l’Est"
"mardi 25 mai 1982 à 13:23:54 heure d’été de l’Est nord-américain"
);
});

Expand Down
34 changes: 17 additions & 17 deletions test/interval/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test("Interval#toString returns an unfriendly string for invalid intervals", ()
//------

test("Interval#toLocaleString defaults to the DATE_SHORT format", () =>
expect(interval.toLocaleString()).toBe("5/25/198210/14/1983"));
expect(interval.toLocaleString()).toBe("5/25/1982 – 10/14/1983"));

test("Interval#toLocaleString returns an unfriendly string for invalid intervals", () =>
expect(invalid.toLocaleString()).toBe("Invalid Interval"));
Expand Down Expand Up @@ -49,7 +49,7 @@ test("Interval#toLocaleString accepts numbering system settings from the start D
interval.start.reconfigure({ numberingSystem: "beng" }),
interval.end
).toLocaleString()
).toBe("৫/২৫/১৯৮২১০/১৪/১৯৮৩");
).toBe("৫/২৫/১৯৮২ – ১০/১৪/১৯৮৩");
});

test("Interval#toLocaleString accepts ouptput calendar settings from the start DateTime", () => {
Expand All @@ -58,11 +58,11 @@ test("Interval#toLocaleString accepts ouptput calendar settings from the start D
interval.start.reconfigure({ outputCalendar: "islamic" }),
interval.end
).toLocaleString()
).toBe("8/2/14021/8/1404 AH");
).toBe("8/2/1402 – 1/8/1404 AH");
});

test("Interval#toLocaleString accepts options to the formatter", () => {
expect(interval.toLocaleString({ weekday: "short" })).toBe("TueFri");
expect(interval.toLocaleString({ weekday: "short" })).toBe("Tue – Fri");
});

test("Interval#toLocaleString can override the start DateTime's locale", () => {
Expand All @@ -71,7 +71,7 @@ test("Interval#toLocaleString can override the start DateTime's locale", () => {
interval.start.reconfigure({ locale: "be" }),
interval.end
).toLocaleString({}, { locale: "fr" })
).toBe("25/05/198214/10/1983");
).toBe("25/05/1982 – 14/10/1983");
});

test("Interval#toLocaleString can override the start DateTime's numbering system", () => {
Expand All @@ -80,7 +80,7 @@ test("Interval#toLocaleString can override the start DateTime's numbering system
interval.start.reconfigure({ numberingSystem: "beng" }),
interval.end
).toLocaleString({ numberingSystem: "mong" })
).toBe("᠕/᠒᠕/᠑᠙᠘᠒᠑᠐/᠑᠔/᠑᠙᠘᠓");
).toBe("᠕/᠒᠕/᠑᠙᠘᠒ – ᠑᠐/᠑᠔/᠑᠙᠘᠓");
});

test("Interval#toLocaleString can override the start DateTime's output calendar", () => {
Expand All @@ -89,7 +89,7 @@ test("Interval#toLocaleString can override the start DateTime's output calendar"
interval.start.reconfigure({ outputCalendar: "islamic" }),
interval.end
).toLocaleString({}, { outputCalendar: "coptic" })
).toBe("9/17/16982/3/1700 ERA1");
).toBe("9/17/1698 – 2/3/1700 ERA1");
});

test("Interval#toLocaleString shows things in the right IANA zone", () => {
Expand All @@ -98,64 +98,64 @@ test("Interval#toLocaleString shows things in the right IANA zone", () => {
interval.start.setZone("Australia/Melbourne"),
interval.end
).toLocaleString(DateTime.DATETIME_SHORT)
).toBe("5/25/1982, 7:00 PM – 10/14/1983, 11:30 PM");
).toBe("5/25/1982, 7:00 PM – 10/14/1983, 11:30PM");
});

test("Interval#toLocaleString shows things in the right fixed-offset zone", () => {
expect(
Interval.fromDateTimes(interval.start.setZone("UTC-8"), interval.end).toLocaleString(
DateTime.DATETIME_SHORT
)
).toBe("5/25/1982, 1:00 AM – 10/14/1983, 5:30 AM");
).toBe("5/25/1982, 1:00 AM – 10/14/1983, 5:30AM");
});

test("Interval#toLocaleString shows things in the right fixed-offset zone when showing the zone", () => {
expect(
Interval.fromDateTimes(interval.start.setZone("UTC-8"), interval.end).toLocaleString(
DateTime.DATETIME_FULL
)
).toBe("May 25, 1982 at 1:00 AM GMT-8October 14, 1983 at 5:30 AM GMT-8");
).toBe("May 25, 1982 at 1:00AM GMT-8 – October 14, 1983 at 5:30AM GMT-8");
});

test("Interval#toLocaleString shows things with UTC if fixed-offset with 0 offset is used", () => {
expect(
Interval.fromDateTimes(interval.start.setZone("UTC"), interval.end).toLocaleString(
DateTime.DATETIME_FULL
)
).toBe("May 25, 1982 at 9:00 AM UTCOctober 14, 1983 at 1:30 PM UTC");
).toBe("May 25, 1982 at 9:00AM UTC – October 14, 1983 at 1:30PM UTC");
});

test("Interval#toLocaleString does the best it can with unsupported fixed-offset zone when showing the zone", () => {
expect(
Interval.fromDateTimes(interval.start.setZone("UTC+4:30"), interval.end).toLocaleString(
DateTime.DATETIME_FULL
)
).toBe("May 25, 1982 at 9:00 AM UTCOctober 14, 1983 at 1:30 PM UTC");
).toBe("May 25, 1982 at 9:00AM UTC – October 14, 1983 at 1:30PM UTC");
});

test("Interval#toLocaleString uses locale-appropriate time formats", () => {
expect(
Interval.after(interval.start.reconfigure({ locale: "en-US" }), { hour: 2 }).toLocaleString(
DateTime.TIME_SIMPLE
)
).toBe("9:0011:00 AM");
).toBe("9:00 – 11:00AM");
expect(
Interval.after(interval.start.reconfigure({ locale: "en-US" }), { hour: 2 }).toLocaleString(
DateTime.TIME_24_SIMPLE
)
).toBe("09:0011:00");
).toBe("09:00 – 11:00");

// France has 24-hour by default
expect(
Interval.after(interval.start.reconfigure({ locale: "fr" }), { hour: 2 }).toLocaleString(
DateTime.TIME_SIMPLE
)
).toBe("09:0011:00");
).toBe("09:00 – 11:00");
expect(
Interval.after(interval.start.reconfigure({ locale: "fr" }), { hour: 2 }).toLocaleString(
DateTime.TIME_24_SIMPLE
)
).toBe("09:0011:00");
).toBe("09:00 – 11:00");

// Spain does't prefix with "0" and doesn't use spaces
expect(
Expand All @@ -172,7 +172,7 @@ test("Interval#toLocaleString uses locale-appropriate time formats", () => {

test("Interval#toLocaleString sets the separator between days for same-month dates", () => {
expect(Interval.after(interval.start, { day: 2 }).toLocaleString(DateTime.DATE_MED)).toBe(
"May 2527, 1982"
"May 25 – 27, 1982"
);
});

Expand Down

0 comments on commit 88f3ba5

Please sign in to comment.