File size: 436 Bytes
cf86710 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import { TZDate } from "@date-fns/tz";
/**
* Convert a {@link Date} or {@link TZDate} instance to the given time zone.
* Reuses the same instance when it is already a {@link TZDate} using the target
* time zone to avoid extra allocations.
*/
export function toTimeZone(date: Date, timeZone: string): TZDate {
if (date instanceof TZDate && date.timeZone === timeZone) {
return date;
}
return new TZDate(date, timeZone);
}
|