Problem
export const PromoInCurrentDay = (date: Date) => {
return () => date.toDateString() === new Date().toDateString();
};
Two issues:
- Ignores time injection. Every other helper uses
ctx.currentDate (fed by options.dateNow); this one reads the real clock directly. Apps that inject server-synced time via dateNow (and tests with mocked time) get inconsistent behavior.
- Timezone shift.
new Date('2024-06-01') parses as UTC midnight; toDateString() renders it in the local timezone. For users west of UTC that is May 31, so the promo shows on the wrong day (and does not show on the intended one).
Where
src/promo-manager/core/condition/condition-helpers.ts — PromoInCurrentDay
Fix: compare against dayjs(ctx.currentDate) and compare calendar days explicitly.
Problem
Two issues:
ctx.currentDate(fed byoptions.dateNow); this one reads the real clock directly. Apps that inject server-synced time viadateNow(and tests with mocked time) get inconsistent behavior.new Date('2024-06-01')parses as UTC midnight;toDateString()renders it in the local timezone. For users west of UTC that isMay 31, so the promo shows on the wrong day (and does not show on the intended one).Where
src/promo-manager/core/condition/condition-helpers.ts—PromoInCurrentDayFix: compare against
dayjs(ctx.currentDate)and compare calendar days explicitly.