diff --git a/server/src/repositories/memory.repository.ts b/server/src/repositories/memory.repository.ts index cffd8559a..ac9410e7a 100644 --- a/server/src/repositories/memory.repository.ts +++ b/server/src/repositories/memory.repository.ts @@ -17,6 +17,7 @@ import { AssetFileType, AssetOrderWithRandom, AssetVisibility } from 'src/enum.j import { type YearMonthDay } from 'src/repositories/asset.repository.js'; import { DB } from 'src/schema/index.js'; import { MemoryTable } from 'src/schema/tables/memory.table.js'; +import { asLocalTime } from 'src/utils/date.js'; const asMakeDate = (eb: ExpressionBuilder, { year, month, day }: YearMonthDay) => eb.fn('make_date', [sql`${year}::int`, sql`${month}::int`, sql`${day}::int`]); @@ -51,7 +52,7 @@ export class MemoryRepository implements IBulkAsset { .where((where) => where.or([where('hideAt', 'is', null), where('hideAt', '>=', dto.for!)])), ) .$if(dto.isUpcoming !== undefined, (qb) => { - const now = DateTime.now().toJSDate(); + const now = asLocalTime(DateTime.now()); return dto.isUpcoming ? qb.where('showAt', '>', now) : qb.where((where) => where.or([where('showAt', 'is', null), where('showAt', '<=', now)])); diff --git a/server/src/utils/date.spec.ts b/server/src/utils/date.spec.ts index 1cffa91a1..48982360c 100644 --- a/server/src/utils/date.spec.ts +++ b/server/src/utils/date.spec.ts @@ -1,5 +1,6 @@ +import { DateTime } from 'luxon'; import { afterEach, describe, expect, it, vi } from 'vitest'; -import { asDateString, asDateTimeString, isLeapDayObserved } from 'src/utils/date.js'; +import { asDateString, asDateTimeString, asLocalTime, isLeapDayObserved } from 'src/utils/date.js'; describe('asDateString', () => { afterEach(() => { @@ -64,3 +65,10 @@ describe('asDateTimeString', () => { expect(asDateTimeString(date)).toBe('2000-01-15T12:00:00.000Z'); }); }); + +describe('asLocalTime', () => { + it('should keep the wall-clock time and reinterpret it as UTC', () => { + const date = DateTime.fromISO('2026-10-06T08:00:00', { zone: 'America/New_York' }) as DateTime; + expect(asLocalTime(date).toISOString()).toBe('2026-10-06T08:00:00.000Z'); + }); +}); diff --git a/server/src/utils/date.ts b/server/src/utils/date.ts index 523074ae6..011605580 100644 --- a/server/src/utils/date.ts +++ b/server/src/utils/date.ts @@ -32,3 +32,5 @@ export const mergeTimeZone = (dateTimeOriginal?: string | null, timeZone?: strin ? DateTime.fromISO(dateTimeOriginal, { zone: 'UTC' }).setZone(timeZone ?? undefined) : undefined; }; + +export const asLocalTime = (date: DateTime) => date.setZone('UTC', { keepLocalTime: true }).toJSDate();