Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
fix(DateService): fix flakiness in UTC-diff-zone
Browse files Browse the repository at this point in the history
The test for betweenHours() failed between 00:00 and 02:00 in Norwegian
summer time (UTC+2) because the wrong day was used. Fixed by
constructing dates with the supplied timezone.
  • Loading branch information
LarsSelbekk committed Jul 19, 2024
1 parent 1821e86 commit d4d3f48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/blc/date.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,24 @@ describe("DateService", () => {

describe("betweenHours()", () => {
it("should return true if date is between from hour and to hour", () => {
const date = moment().hour(12).minute(15).seconds(22).toDate();
const date = moment()
.tz("Europe/Oslo")
.hour(12)
.minute(15)
.seconds(22)
.toDate();

return expect(dateService.betweenHours(date, 8, 18, "Europe/Oslo")).to.be
.true;
});

it("should return false if date is not between from hour and to hour", () => {
const date = moment().hour(7).minute(15).seconds(22).toDate();
const date = moment()
.tz("Europe/Oslo")
.hour(7)
.minute(15)
.seconds(22)
.toDate();

return expect(dateService.betweenHours(date, 8, 18, "Europe/Oslo")).to.be
.false;
Expand Down
4 changes: 2 additions & 2 deletions src/blc/date.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class DateService {
toHour: number,
location: MomentLocation,
): boolean {
const from = moment.tz().hour(fromHour).minute(0).second(0);
const to = moment.tz().hour(toHour).minute(0).second(0);
const from = moment.tz(location).hour(fromHour).minute(0).second(0);
const to = moment.tz(location).hour(toHour).minute(0).second(0);

return this.between(date, from.toDate(), to.toDate(), location);
}
Expand Down

0 comments on commit d4d3f48

Please sign in to comment.