Package org.daiitech.naftah.utils.time
Class ZoneUtils
java.lang.Object
org.daiitech.naftah.utils.time.ZoneUtils
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final ResourceBundleResource bundle containing names of time zones mapped to Java Zone IDs.Reverse map from Java Zone IDs to canonical time zone names.Map of time zone names to Java Zone IDs. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringjavaZoneIdToName(String javaZoneId) Converts a Java Zone ID to its canonical name.static ZoneOffsetparseZoneOffset(String offsetStr) Parses a string offset (e.g., "+03:00") into aZoneOffset.static StringzoneNameToJavaZoneId(String zoneName) Converts a time zone name to its corresponding Java Zone ID.
-
Field Details
-
BUNDLE
Resource bundle containing names of time zones mapped to Java Zone IDs. -
ZONE_MAP
Map of time zone names to Java Zone IDs.This map is initialized from the
BUNDLEand is unmodifiable. -
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 aNaftahBugErrorwhen called.
-
-
Method Details
-
parseZoneOffset
Parses a string offset (e.g., "+03:00") into aZoneOffset.- Parameters:
offsetStr- the string representation of the offset- Returns:
- the corresponding
ZoneOffset - Throws:
IllegalArgumentException- if the offset string is invalid
-
zoneNameToJavaZoneId
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
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
-