export const runWithFrozenDate = async <T>(
    timestampMs: number,
    runner: () => Promise<T>
): Promise<T> => {
    const OriginalDate = Date;
    class FrozenDate extends Date {
        constructor(...args: any[]) {
            if (args.length === 0) {
                super(timestampMs);
                return;
            }
            super(...(args as [any]));
        }
        static now(): number {
            return timestampMs;
        }
    }

    (globalThis as any).Date = FrozenDate as any;
    try {
        return await runner();
    } finally {
        (globalThis as any).Date = OriginalDate;
    }
};

