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

20 lines
522 B
TypeScript
Raw Normal View History

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