CalOohPay API Documentation - v2.1.0
    Preparing search index...

    Function convertTimezone

    • 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.

      Parameters

      • date: string | Date

        The date to convert (Date object or ISO string)

      • timeZoneId: string

        IANA timezone identifier (e.g., "America/New_York", "Europe/London", "Asia/Tokyo")

      Returns DateTime

      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.

      • Input can be Date or ISO string (both are converted properly)
      • Output is always a Luxon DateTime for consistent timezone operations
      • Preserves the exact moment in time (UTC timestamp unchanged)
      • Only the representation timezone changes
      // 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