fyliu's picture
Claude Opus 4.6
Add benchmark mode: freeze system date to 2026-04-01 for deterministic behavior
bc18056
Raw History Blame Contribute Delete
1.32 kB
/** When set, all "now" references use this fixed date instead of Date.now(). */
let _benchmarkDate: string | null = null;
export function setBenchmarkDate(isoDate: string | null): void {
_benchmarkDate = isoDate;
}
export function getNow(): Date {
return _benchmarkDate ? new Date(_benchmarkDate + 'T00:00:00') : new Date();
}
export function toDateString(d: Date): string {
return d.toISOString().split('T')[0];
}
export function addDays(d: Date, n: number): Date {
const result = new Date(d);
result.setDate(result.getDate() + n);
return result;
}
export function getDefaultDepartureDate(): string {
return toDateString(addDays(getNow(), 14));
}
export function getDefaultReturnDate(): string {
return toDateString(addDays(getNow(), 21));
}
export function getMaxBookingDate(): string {
const d = getNow();
d.setMonth(d.getMonth() + 12);
return toDateString(d);
}
export function getDaysInMonth(year: number, month: number): number {
return new Date(year, month, 0).getDate();
}
export function getFirstDayOfMonth(year: number, month: number): number {
return new Date(year, month - 1, 1).getDay();
}
export function formatMonthYear(year: number, month: number): string {
return new Date(year, month - 1).toLocaleDateString('en-US', {
month: 'long',
year: 'numeric',
});
}