Class ZoneUtils

java.lang.Object
org.daiitech.naftah.utils.time.ZoneUtils

public final class ZoneUtils extends Object
Utility class for handling time zones with support for names.

Provides methods to convert between time zone names and Java Zone IDs, as well as parsing string offsets into ZoneOffset.

Author:
Chakib Daii
  • Field Details

    • BUNDLE

      private static final ResourceBundle BUNDLE
      Resource bundle containing names of time zones mapped to Java Zone IDs.
    • ZONE_MAP

      private static final Map<String,String> ZONE_MAP
      Map of time zone names to Java Zone IDs.

      This map is initialized from the BUNDLE and is unmodifiable.

    • JAVA_ZONE_TO_MAP

      private static final Map<String,String> JAVA_ZONE_TO_MAP
      Reverse map from Java Zone IDs to canonical time zone names.

      Only the first name encountered for a given Java Zone ID is retained. This map is unmodifiable.

  • Constructor Details

    • ZoneUtils

      private ZoneUtils()
      Private constructor to prevent instantiation. Always throws a NaftahBugError when called.
  • Method Details

    • parseZoneOffset

      public static ZoneOffset parseZoneOffset(String offsetStr)
      Parses a string offset (e.g., "+03:00") into a ZoneOffset.
      Parameters:
      offsetStr - the string representation of the offset
      Returns:
      the corresponding ZoneOffset
      Throws:
      IllegalArgumentException - if the offset string is invalid
    • zoneNameToJavaZoneId

      public static String zoneNameToJavaZoneId(String zoneName)
      Converts a time zone name to its corresponding Java Zone ID.
      Parameters:
      zoneName - the name of the time zone
      Returns:
      the Java Zone ID (e.g., "Asia/Riyadh")
      Throws:
      IllegalArgumentException - if the name is unknown
    • javaZoneIdToName

      public static String javaZoneIdToName(String javaZoneId)
      Converts a Java Zone ID to its canonical name.
      Parameters:
      javaZoneId - the Java Zone ID
      Returns:
      the corresponding name of the time zone
      Throws:
      IllegalArgumentException - if the Java Zone ID is unknown