fix utc conversion for schedule
This commit is contained in:
parent
1f9a9896e9
commit
e312a6c712
|
@ -25,22 +25,22 @@ export class Ad {
|
||||||
monTime: Date;
|
monTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
tueTime: string;
|
tueTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
wedTime: string;
|
wedTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
thuTime: string;
|
thuTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
friTime: string;
|
friTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
satTime: string;
|
satTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
sunTime: string;
|
sunTime: Date;
|
||||||
|
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
monMargin: number;
|
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 { AdPresenter } from '../adapters/primaries/ad.presenter';
|
||||||
import { CreateAdRequest } from '../domain/dtos/create-ad.request';
|
import { CreateAdRequest } from '../domain/dtos/create-ad.request';
|
||||||
import { Coordinates } from '../../geography/domain/entities/coordinates';
|
import { Coordinates } from '../../geography/domain/entities/coordinates';
|
||||||
import moment from 'moment-timezone';
|
import { TimeConverter } from '../domain/entities/time-converter';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AdProfile extends AutomapperProfile {
|
export class AdProfile extends AutomapperProfile {
|
||||||
|
@ -53,18 +53,76 @@ export class AdProfile extends AutomapperProfile {
|
||||||
(dest) => dest.updatedAt,
|
(dest) => dest.updatedAt,
|
||||||
mapFrom((source) => new Date(source.updatedAt)),
|
mapFrom((source) => new Date(source.updatedAt)),
|
||||||
),
|
),
|
||||||
// forMember(
|
forMember(
|
||||||
// (dest) => dest.monTime,
|
(dest) => dest.monTime,
|
||||||
// mapFrom((source) =>
|
mapFrom((source) =>
|
||||||
// source.monTime
|
TimeConverter.toUtcDatetime(
|
||||||
// ? new Date(
|
source.fromDate,
|
||||||
// moment
|
source.monTime,
|
||||||
// .tz(`${source.fromDate} ${source.monTime}`, source.timezone)
|
source.timezone,
|
||||||
// .format(),
|
),
|
||||||
// )
|
),
|
||||||
// : undefined,
|
),
|
||||||
// ),
|
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