The date to convert (Date object or ISO string)
IANA timezone identifier (e.g., "America/New_York", "Europe/London", "Asia/Tokyo")
Luxon DateTime object in the specified timezone
This function is crucial for accurate OOH calculations as it ensures that "end of work day" (17:30) is evaluated in the schedule's local timezone, not in UTC or the server's timezone.
// Convert UTC time to London time
const utcDate = new Date('2024-08-01T16:30:00Z');
const londonTime = convertTimezone(utcDate, 'Europe/London');
console.log(londonTime.toString()); // Shows as 17:30 in British Summer Time
// Convert ISO string to New York time
const nyTime = convertTimezone('2024-08-01T16:30:00Z', 'America/New_York');
console.log(nyTime.toString()); // Shows as 12:30 in Eastern Daylight Time
Converts a date to a specific timezone and returns a Luxon DateTime.
Takes either a JavaScript Date object or an ISO string and converts it to the specified timezone. The returned DateTime object preserves the same moment in time but represents it in the target timezone.