fix utc conversion for schedule
This commit is contained in:
parent
1f9a9896e9
commit
e312a6c712
|
@ -25,22 +25,22 @@ export class Ad {
|
|||
monTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
tueTime: string;
|
||||
tueTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
wedTime: string;
|
||||
wedTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
thuTime: string;
|
||||
thuTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
friTime: string;
|
||||
friTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
satTime: string;
|
||||
satTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
sunTime: string;
|
||||
sunTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
monMargin: number;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import { DateTime, TimeZone } from 'timezonecomplete';
|
||||
|
||||
export class TimeConverter {
|
||||
static toUtcDatetime = (
|
||||
date: string,
|
||||
time: string,
|
||||
ianaTimezone: string,
|
||||
): Date =>
|
||||
date && time
|
||||
? new Date(
|
||||
new DateTime(`${date}T${time}:00`, TimeZone.zone(ianaTimezone, false))
|
||||
.convert(TimeZone.zone('UTC'))
|
||||
.toIsoString(),
|
||||
)
|
||||
: undefined;
|
||||
}
|
|
@ -5,7 +5,7 @@ import { Ad } from '../domain/entities/ad';
|
|||
import { AdPresenter } from '../adapters/primaries/ad.presenter';
|
||||
import { CreateAdRequest } from '../domain/dtos/create-ad.request';
|
||||
import { Coordinates } from '../../geography/domain/entities/coordinates';
|
||||
import moment from 'moment-timezone';
|
||||
import { TimeConverter } from '../domain/entities/time-converter';
|
||||
|
||||
@Injectable()
|
||||
export class AdProfile extends AutomapperProfile {
|
||||
|
@ -53,18 +53,76 @@ export class AdProfile extends AutomapperProfile {
|
|||
(dest) => dest.updatedAt,
|
||||
mapFrom((source) => new Date(source.updatedAt)),
|
||||
),
|
||||
// forMember(
|
||||
// (dest) => dest.monTime,
|
||||
// mapFrom((source) =>
|
||||
// source.monTime
|
||||
// ? new Date(
|
||||
// moment
|
||||
// .tz(`${source.fromDate} ${source.monTime}`, source.timezone)
|
||||
// .format(),
|
||||
// )
|
||||
// : undefined,
|
||||
// ),
|
||||
// ),
|
||||
forMember(
|
||||
(dest) => dest.monTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.monTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
forMember(
|
||||
(dest) => dest.tueTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.tueTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
forMember(
|
||||
(dest) => dest.wedTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.wedTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
forMember(
|
||||
(dest) => dest.thuTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.thuTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
forMember(
|
||||
(dest) => dest.friTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.friTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
forMember(
|
||||
(dest) => dest.satTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.satTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
forMember(
|
||||
(dest) => dest.sunTime,
|
||||
mapFrom((source) =>
|
||||
TimeConverter.toUtcDatetime(
|
||||
source.fromDate,
|
||||
source.sunTime,
|
||||
source.timezone,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue