matcher/src/modules/ad/domain/entities/time-converter.ts

20 lines
424 B
TypeScript
Raw Normal View History

2023-05-02 09:56:07 +00:00
import { DateTime, TimeZone } from 'timezonecomplete';
export class TimeConverter {
static toUtcDatetime = (
date: string,
time: string,
2023-05-02 15:26:04 +00:00
timezone: string,
): Date => {
try {
return new Date(
new DateTime(`${date}T${time}:00`, TimeZone.zone(timezone, false))
.convert(TimeZone.zone('UTC'))
.toIsoString(),
);
} catch (e) {
return undefined;
}
};
2023-05-02 09:56:07 +00:00
}