Class ChronologyUtils

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

public final class ChronologyUtils extends Object
Utility class for working with Java Chronology instances and their corresponding calendar names.

Provides methods to:

  • Map calendar names to Java Chronology instances
  • Retrieve the canonical calendar name for a given Chronology

Supports both ISO (Gregorian) and Hijrah (Islamic) chronologies by default.

Author:
Chakib Daii
  • Field Details

    • DEFAULT_CHRONOLOGY

      public static final Chronology DEFAULT_CHRONOLOGY
      The default chronology used when no specific calendar is provided. Typically represents the ISO (Gregorian) calendar.
    • HIJRAH_CHRONOLOGY

      public static final Chronology HIJRAH_CHRONOLOGY
      The Hijrah chronology representing the Islamic (Hijri) calendar.
    • CALENDAR_MAP

      private static final Map<String,Chronology> CALENDAR_MAP
      A map from calendar names to their corresponding Chronology instances.

      Supports multiple aliases for ISO and Hijrah calendars.

    • CHRONOLOGY_NAME_MAP

      private static final Map<Chronology,String> CHRONOLOGY_NAME_MAP
      A reverse map from Chronology instances 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 a NaftahBugError when called.
  • Method Details

    • getChronologyByName

      public static Chronology getChronologyByName(String chronologyName)
      Returns the Chronology instance corresponding to the given calendar name.
      Parameters:
      chronologyName - the name of the calendar
      Returns:
      the corresponding Chronology instance
      Throws:
      IllegalArgumentException - if the calendar name is unknown
    • getChronologyName

      public static String getChronologyName(Chronology chronology)
      Returns the canonical calendar name corresponding to the given Chronology instance.
      Parameters:
      chronology - the chronology instance
      Returns:
      the canonical calendar name
      Throws:
      IllegalArgumentException - if the chronology is not supported