fix: memory upcoming query (#32166)
fix: memory upcoming query (#32164) (cherry picked from commit e49a5bb8c99abbf9944ca3d84220427d340c6786) Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
co-authored by
Jason Rasmussen
parent
62bcb0601f
commit
1aede8d8c3
@@ -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<DB, 'asset'>, { 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)]));
|
||||
|
||||
@@ -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<true>;
|
||||
expect(asLocalTime(date).toISOString()).toBe('2026-10-06T08:00:00.000Z');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<true>) => date.setZone('UTC', { keepLocalTime: true }).toJSDate();
|
||||
|
||||
Reference in New Issue
Block a user