Skip to content

Commit c8a8fa2

Browse files
authored
Fix Interval.splitAt datetime sorting (#1524)
1 parent 1b8679e commit c8a8fa2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/interval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export default class Interval {
320320
const sorted = dateTimes
321321
.map(friendlyDateTime)
322322
.filter((d) => this.contains(d))
323-
.sort(),
323+
.sort((a, b) => a.toMillis() - b.toMillis()),
324324
results = [];
325325
let { s } = this,
326326
i = 0;

test/interval/many.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ test("Interval#splitAt ignores times outside the interval", () => {
301301
expect(oneAfterOneDuring[1]).toEqual(todayFrom(11, 13));
302302
});
303303

304+
test("Interval#splitAt handles DST shifts", () => {
305+
const zone = "Europe/Berlin";
306+
const dayStart = DateTime.fromISO("2023-10-29T00:00:00+02:00", { zone });
307+
const dayEnd = DateTime.fromISO("2023-10-30T00:00:00+01:00", { zone });
308+
const dstShiftStart = DateTime.fromISO("2023-10-29T02:00:00+02:00", { zone });
309+
const dstShiftEnd = DateTime.fromISO("2023-10-29T02:00:00+01:00", { zone });
310+
311+
const splitByDSTStartAndEnd = Interval.fromDateTimes(dayStart, dayEnd)
312+
.splitAt(dstShiftStart, dstShiftEnd)
313+
.map((i) => i.toISO());
314+
315+
expect(splitByDSTStartAndEnd).toEqual([
316+
"2023-10-29T00:00:00.000+02:00/2023-10-29T02:00:00.000+02:00",
317+
"2023-10-29T02:00:00.000+02:00/2023-10-29T02:00:00.000+01:00",
318+
"2023-10-29T02:00:00.000+01:00/2023-10-30T00:00:00.000+01:00",
319+
]);
320+
});
321+
304322
//-------
305323
// #splitBy()
306324
//-------

0 commit comments

Comments
 (0)