bugfix: appointment hours now use the client timezone on UTC servers.
Logical API errors throw stable codes so users see translated messages instead of a generic bad request. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
29
backend/src/common/zoned-civil-time.spec.ts
Normal file
29
backend/src/common/zoned-civil-time.spec.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { appointmentWithinWorkingHours } from './working-hours';
|
||||
import { isValidIanaTimeZone, zonedWeekdayAndMinutes } from './zoned-civil-time';
|
||||
|
||||
describe('zoned civil time', () => {
|
||||
it('accepts IANA zones and rejects garbage', () => {
|
||||
expect(isValidIanaTimeZone('Asia/Tehran')).toBe(true);
|
||||
expect(isValidIanaTimeZone('Europe/Amsterdam')).toBe(true);
|
||||
expect(isValidIanaTimeZone('Not/AZone')).toBe(false);
|
||||
});
|
||||
|
||||
it('maps a UTC instant to Tehran wall-clock (no DST)', () => {
|
||||
// 2026-08-20 09:45 Asia/Tehran = 06:15 UTC (the production 400 case)
|
||||
const instant = new Date('2026-08-20T06:15:00.000Z');
|
||||
const zoned = zonedWeekdayAndMinutes(instant, 'Asia/Tehran');
|
||||
expect(zoned.jsWeekday).toBe(4); // Thursday
|
||||
expect(zoned.minuteOfDay).toBe(9 * 60 + 45);
|
||||
});
|
||||
|
||||
it('treats morning Tehran slots as inside 08:00–17:00 hours', () => {
|
||||
const start = new Date('2026-08-20T06:15:00.000Z');
|
||||
const end = new Date('2026-08-20T06:45:00.000Z');
|
||||
expect(
|
||||
appointmentWithinWorkingHours(start, end, [{ startMinute: 8 * 60, endMinute: 17 * 60 }], 'Asia/Tehran'),
|
||||
).toBe(true);
|
||||
expect(
|
||||
appointmentWithinWorkingHours(start, end, [{ startMinute: 8 * 60, endMinute: 17 * 60 }], 'UTC'),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user