Skip to content

Commit

Permalink
Fix Interval.splitAt datetime sorting (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajaco authored Oct 14, 2023
1 parent 1b8679e commit c8a8fa2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export default class Interval {
const sorted = dateTimes
.map(friendlyDateTime)
.filter((d) => this.contains(d))
.sort(),
.sort((a, b) => a.toMillis() - b.toMillis()),
results = [];
let { s } = this,
i = 0;
Expand Down
18 changes: 18 additions & 0 deletions test/interval/many.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ test("Interval#splitAt ignores times outside the interval", () => {
expect(oneAfterOneDuring[1]).toEqual(todayFrom(11, 13));
});

test("Interval#splitAt handles DST shifts", () => {
const zone = "Europe/Berlin";
const dayStart = DateTime.fromISO("2023-10-29T00:00:00+02:00", { zone });
const dayEnd = DateTime.fromISO("2023-10-30T00:00:00+01:00", { zone });
const dstShiftStart = DateTime.fromISO("2023-10-29T02:00:00+02:00", { zone });
const dstShiftEnd = DateTime.fromISO("2023-10-29T02:00:00+01:00", { zone });

const splitByDSTStartAndEnd = Interval.fromDateTimes(dayStart, dayEnd)
.splitAt(dstShiftStart, dstShiftEnd)
.map((i) => i.toISO());

expect(splitByDSTStartAndEnd).toEqual([
"2023-10-29T00:00:00.000+02:00/2023-10-29T02:00:00.000+02:00",
"2023-10-29T02:00:00.000+02:00/2023-10-29T02:00:00.000+01:00",
"2023-10-29T02:00:00.000+01:00/2023-10-30T00:00:00.000+01:00",
]);
});

//-------
// #splitBy()
//-------
Expand Down

0 comments on commit c8a8fa2

Please sign in to comment.