17 lines
405 B
TypeScript
17 lines
405 B
TypeScript
|
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;
|
||
|
}
|