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:
2026-08-19 01:43:50 +03:30
parent d6958b2e48
commit 80167c622c
38 changed files with 833 additions and 392 deletions

View 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:0017: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);
});
});