@kermank/slots
Version:
A TypeScript library for handling time slots, scheduling, and timezone operations
45 lines (44 loc) • 2.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const luxon_1 = require("luxon");
const time_of_day_rule_1 = require("../../src/rules/time-of-day-rule");
describe('createTimeOfDayRule timezone handling', () => {
it('should only block slots between 9 AM - 5 PM in their respective timezones', () => {
// Rule blocks 9 AM to 5 PM
const rule = (0, time_of_day_rule_1.createTimeOfDayRule)({ hour: 9 }, { hour: 17 });
// Test slots in UTC
const utcDuringBusinessHours = {
start: luxon_1.DateTime.fromObject({ hour: 13 }, { zone: 'UTC' }), // 1 PM UTC
end: luxon_1.DateTime.fromObject({ hour: 14 }, { zone: 'UTC' }), // 2 PM UTC
metadata: {}
};
const utcOutsideBusinessHours = {
start: luxon_1.DateTime.fromObject({ hour: 7 }, { zone: 'UTC' }), // 7 AM UTC
end: luxon_1.DateTime.fromObject({ hour: 8 }, { zone: 'UTC' }), // 8 AM UTC
metadata: {}
};
// Test slots in New York
const nyDuringBusinessHours = {
start: luxon_1.DateTime.fromObject({ hour: 13 }, { zone: 'America/New_York' }), // 1 PM NY
end: luxon_1.DateTime.fromObject({ hour: 14 }, { zone: 'America/New_York' }), // 2 PM NY
metadata: {}
};
const nyOutsideBusinessHours = {
start: luxon_1.DateTime.fromObject({ hour: 7 }, { zone: 'America/New_York' }), // 7 AM NY
end: luxon_1.DateTime.fromObject({ hour: 8 }, { zone: 'America/New_York' }), // 8 AM NY
metadata: {}
};
const result = rule([
utcDuringBusinessHours,
utcOutsideBusinessHours,
nyDuringBusinessHours,
nyOutsideBusinessHours
]);
// Slots during business hours (9 AM - 5 PM) should be blocked
expect(result).toContain(utcDuringBusinessHours);
expect(result).toContain(nyDuringBusinessHours);
// Slots outside business hours should not be blocked
expect(result).not.toContain(utcOutsideBusinessHours);
expect(result).not.toContain(nyOutsideBusinessHours);
});
});