Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Interval.splitAt datetime sorting #1524

Merged
merged 1 commit into from Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/interval.js
Expand Up @@ -312,7 +312,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
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