Spaces:
Sleeping
Sleeping
File size: 915 Bytes
73e0e3c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import { EventSubscriber, EntitySubscriberInterface } from 'typeorm';
/**
* SQLite stores Python's datetime.utcnow() as bare strings like
* "2026-06-19 14:45:00.123456" (no timezone indicator). Node's Date
* constructor treats these as LOCAL time, baking in the dev machine's
* UTC offset before TypeORM sets the entity property. This subscriber
* undoes that offset so all date fields are correct UTC, matching the
* pg-type-parser fix on the PostgreSQL path.
*/
@EventSubscriber()
export class SqliteDateSubscriber implements EntitySubscriberInterface {
afterLoad(entity: object) {
for (const [key, val] of Object.entries(entity)) {
if (val instanceof Date && !isNaN(val.getTime())) {
const offsetMs = val.getTimezoneOffset() * 60_000;
if (offsetMs !== 0) {
(entity as Record<string, unknown>)[key] = new Date(val.getTime() - offsetMs);
}
}
}
}
}
|