Skip to content

Commit

Permalink
Merge pull request #10 from Optick-Labs/main
Browse files Browse the repository at this point in the history
Fix day slots when they cross DST bounds
  • Loading branch information
huzaifahj authored Apr 18, 2024
2 parents 7d0b064 + c255f5b commit bf70102
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
48 changes: 48 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,54 @@ test("Bounds and day slot aren't the same timezone, so days of the week differ",
]);
});

test("Day slot across Daylight savings time", () => {
const { allSlots } = getSlots({
from: DateTime.fromObject({ year: 2024, month: 3, day: 10, hour: 1 }, { zone: "America/Los_Angeles" }).toISO(),
to: DateTime.fromObject({ year: 2024, month: 3, day: 10, hour: 7 }, { zone: "America/Los_Angeles" }).toISO(),
availability: [
{
day: "Sunday",
from: "05:00",
to: "06:00",
timezone: "America/Los_Angeles",
},
],
duration: 60,
});

expect(allSlots).toEqual([
// PST is -8
{
from: DateTime.fromISO("2024-03-10T01:00:00.000-08:00").toUTC().toISO(),
to: DateTime.fromISO("2024-03-10T02:00:00.000-08:00").toUTC().toISO(),
available: false,
},
// The 2-3 slot doesn't exist

// PDT is -7
{
from: DateTime.fromISO("2024-03-10T03:00:00.000-07:00").toUTC().toISO(),
to: DateTime.fromISO("2024-03-10T04:00:00.000-07:00").toUTC().toISO(),
available: false,
},
{
from: DateTime.fromISO("2024-03-10T04:00:00.000-07:00").toUTC().toISO(),
to: DateTime.fromISO("2024-03-10T05:00:00.000-07:00").toUTC().toISO(),
available: false,
},
{
from: DateTime.fromISO("2024-03-10T05:00:00.000-07:00").toUTC().toISO(),
to: DateTime.fromISO("2024-03-10T06:00:00.000-07:00").toUTC().toISO(),
available: true,
},
{
from: DateTime.fromISO("2024-03-10T06:00:00.000-07:00").toUTC().toISO(),
to: DateTime.fromISO("2024-03-10T07:00:00.000-07:00").toUTC().toISO(),
available: false,
},
]);
});

test("Helper variables", async () => {
// false, true
const {
Expand Down
12 changes: 6 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ export function getSlots(config: {
from: DateTime.fromISO(date, {
zone: slot.timezone,
})
.plus({
hours: Number(slot.from.split(":")[0]),
minutes: Number(slot.from.split(":")[1]),
.set({
hour: Number(slot.from.split(":")[0]),
minute: Number(slot.from.split(":")[1]),
})
.toISO(),
to: DateTime.fromISO(date, {
zone: slot.timezone,
})
.plus({
hours: Number(slot.to.split(":")[0]),
minutes: Number(slot.to.split(":")[1]),
.set({
hour: Number(slot.to.split(":")[0]),
minute: Number(slot.to.split(":")[1]),
})
.toISO(),
metadata: slot.metadata,
Expand Down

0 comments on commit bf70102

Please sign in to comment.