Package org.daiitech.naftah.utils.time
Class ChronologyUtils
java.lang.Object
org.daiitech.naftah.utils.time.ChronologyUtils
Utility class for working with Java
Chronology instances
and their corresponding calendar names.
Provides methods to:
- Map calendar names to Java
Chronologyinstances - Retrieve the canonical calendar name for a given
Chronology
Supports both ISO (Gregorian) and Hijrah (Islamic) chronologies by default.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<String,Chronology> A map from calendar names to their correspondingChronologyinstances.private static final Map<Chronology,String> A reverse map fromChronologyinstances to a canonical calendar name.static final ChronologyThe default chronology used when no specific calendar is provided.static final ChronologyThe Hijrah chronology representing the Islamic (Hijri) calendar. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic ChronologygetChronologyByName(String chronologyName) Returns theChronologyinstance corresponding to the given calendar name.static StringgetChronologyName(Chronology chronology) Returns the canonical calendar name corresponding to the givenChronologyinstance.
-
Field Details
-
DEFAULT_CHRONOLOGY
The default chronology used when no specific calendar is provided. Typically represents the ISO (Gregorian) calendar. -
HIJRAH_CHRONOLOGY
The Hijrah chronology representing the Islamic (Hijri) calendar. -
CALENDAR_MAP
A map from calendar names to their correspondingChronologyinstances.Supports multiple aliases for ISO and Hijrah calendars.
-
CHRONOLOGY_NAME_MAP
A reverse map fromChronologyinstances to a canonical calendar name.If multiple names map to the same chronology, only the first encountered name is stored as the canonical name.
-
-
Constructor Details
-
ChronologyUtils
private ChronologyUtils()Private constructor to prevent instantiation. Always throws aNaftahBugErrorwhen called.
-
-
Method Details
-
getChronologyByName
Returns theChronologyinstance corresponding to the given calendar name.- Parameters:
chronologyName- the name of the calendar- Returns:
- the corresponding
Chronologyinstance - Throws:
IllegalArgumentException- if the calendar name is unknown
-
getChronologyName
Returns the canonical calendar name corresponding to the givenChronologyinstance.- Parameters:
chronology- the chronology instance- Returns:
- the canonical calendar name
- Throws:
IllegalArgumentException- if the chronology is not supported
-