fix: make sure tour.startDate is given in UTC
This commit is contained in:
parent
0fa97c53b1
commit
1996ab31d5
|
|
@ -1,5 +1,5 @@
|
|||
import { parse, parseISO } from 'date-fns';
|
||||
import { fromZonedTime } from 'date-fns-tz';
|
||||
import { parse, parseISO, subMilliseconds } from 'date-fns';
|
||||
import { fromZonedTime, getTimezoneOffset } from 'date-fns-tz';
|
||||
|
||||
export const parseDateTime = (format: string) => (value: string) =>
|
||||
!!value ? parse(value, format, new Date()) : value;
|
||||
|
|
@ -11,6 +11,12 @@ export const parseZonedDateTime =
|
|||
|
||||
export const parseCETDateTime = parseZonedDateTime('Europe/Berlin');
|
||||
|
||||
export const subTimeZone = (value: string) =>
|
||||
subMilliseconds(
|
||||
new Date(value),
|
||||
getTimezoneOffset('Europe/Berlin', new Date(value)),
|
||||
);
|
||||
|
||||
export const parseInteger = (value = '') => parseInt(value);
|
||||
|
||||
export const parseFloat = (value = '') =>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { TourSource } from '@prisma/client';
|
||||
import { fakerDE as faker } from '@faker-js/faker';
|
||||
import { isAfter } from 'date-fns';
|
||||
import { TourPreStaging } from '../staging.interface';
|
||||
import {
|
||||
parseBoolean,
|
||||
|
|
@ -9,6 +9,7 @@ import {
|
|||
parseInteger,
|
||||
parseIsoDateTime,
|
||||
pick,
|
||||
subTimeZone,
|
||||
transformProperties,
|
||||
} from '../transformer.functions';
|
||||
|
||||
|
|
@ -30,7 +31,15 @@ export class TourTransformer {
|
|||
...transformProperties(parseFloat)(
|
||||
pick(['besetztKm', 'gesamtPreis'])(tourSource),
|
||||
),
|
||||
...transformProperties(parseIsoDateTime)(pick(['date_iso'])(tourSource)),
|
||||
//! DispoLive changed date_iso from beeing UTC to local time, which in our case is CET
|
||||
...(isAfter(
|
||||
new Date(tourSource.date_iso),
|
||||
new Date('2024-10-28T00:00:00.000Z'),
|
||||
)
|
||||
? transformProperties(subTimeZone)(pick(['date_iso'])(tourSource))
|
||||
: transformProperties(parseIsoDateTime)(
|
||||
pick(['date_iso'])(tourSource),
|
||||
)),
|
||||
...(tourSource.abrDate
|
||||
? transformProperties(parseDateTime('yyyy-MM-dd'))(
|
||||
pick(['abrDate'])(tourSource),
|
||||
|
|
|
|||
Loading…
Reference in New Issue