Package org.daiitech.naftah.utils.time
Class MonthUtils
java.lang.Object
org.daiitech.naftah.utils.time.MonthUtils
Utility class for converting month names to numeric month values.
This class supports both Gregorian and Hijri calendars.
Methods include:
getGregorianMonth(String)– maps Gregorian month names to *Month.getHijriMonth(String)– maps Hijri month names to integer month values (1–12).monthNameToNumber(String, java.time.chrono.Chronology)– converts a month name to its numeric * value based on the given chronology.
Throws IllegalArgumentException for unknown month names.
- Author:
- Chakib Daii
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MonthgetGregorianMonth(String monthName) Converts a Gregorian month name to aMonthenum.static StringgetGregorianMonthName(int month) Returns the name of a Gregorian month given its numeric value.static intgetHijriMonth(String monthName) Converts an Hijri month name to its corresponding numeric value (1–12).static StringgetHijriMonthName(int month) Returns the Hijri month name corresponding to the given numeric value.static intgetMonthLength(int month, int year, Chronology chronology) Returns the number of days in a given month for the specified chronology and year.static intmonthNameToNumber(String monthName, Chronology chronology) Converts a month name to its numeric value according to the given chronology.static StringmonthNumberToName(int month, Chronology chronology) Converts a numeric month value to its month name according to the given chronology.
-
Constructor Details
-
MonthUtils
private MonthUtils()Private constructor to prevent instantiation. Always throws aNaftahBugErrorwhen called.
-
-
Method Details
-
getGregorianMonth
Converts a Gregorian month name to aMonthenum.- Parameters:
monthName- the month name- Returns:
- the corresponding
Monthenum - Throws:
IllegalArgumentException- if the month name is not recognized
-
getGregorianMonthName
Returns the name of a Gregorian month given its numeric value.The returned name corresponds to the commonly used variant (e.g., "جانفي", "فيفري", "أفريل").
- Parameters:
month- the Gregorian month number (1–12)- Returns:
- the month name
- Throws:
IllegalArgumentException- if the month number is not in the range 1–12
-
getHijriMonth
Converts an Hijri month name to its corresponding numeric value (1–12).- Parameters:
monthName- the Hijri month name- Returns:
- the month number (1 for Muharram, 12 for Dhu al-Hijjah)
- Throws:
IllegalArgumentException- if the month name is not recognized
-
getHijriMonthName
Returns the Hijri month name corresponding to the given numeric value.The mapping follows the standard Hijri calendar ordering (1 = Muharram, 12 = Dhu al-Hijjah).
- Parameters:
month- the Hijri month number (1–12)- Returns:
- the Hijri month name
- Throws:
IllegalArgumentException- if the month number is not in the range 1–12
-
monthNameToNumber
Converts a month name to its numeric value according to the given chronology.If the chronology is
HijrahChronology, uses Hijri months; otherwise uses Gregorian months.- Parameters:
monthName- the month namechronology- the chronology to determine the calendar type- Returns:
- the numeric month value
- Throws:
IllegalArgumentException- if the month name is not recognized
-
monthNumberToName
Converts a numeric month value to its month name according to the given chronology.If the chronology is
HijrahChronology, the returned name is a Hijri month name. Otherwise, a Gregorian month name is returned.- Parameters:
month- the month number (1–12)chronology- the chronology used to determine the calendar system- Returns:
- the month name corresponding to the given month number
- Throws:
IllegalArgumentException- if the month number is invalid or unsupported
-
getMonthLength
Returns the number of days in a given month for the specified chronology and year.- Parameters:
month- the month number (1–12)year- the yearchronology- the chronology (Gregorian or Hijri)- Returns:
- the number of days in the month
- Throws:
IllegalArgumentException- if month is not in 1–12
-