Package org.daiitech.naftah.builtin.time
Record Class NaftahDate.Date
java.lang.Object
java.lang.Record
org.daiitech.naftah.builtin.time.NaftahDate.Date
- Record Components:
day- the day of month (starting from 1)month- the name of the monthmonthValue- the numeric month value (1–12)year- the year value
- Enclosing class:
- NaftahDate
public static record NaftahDate.Date(int day, String month, int monthValue, int year)
extends Record
Represents the date part of a Naftah date expression.
Stores both the original Naftah month name and its numeric value
as resolved using a specific Chronology.
Validation ensures the day, month, and month name are logically correct.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe field for thedayrecord component.private final StringThe field for themonthrecord component.private final intThe field for themonthValuerecord component.private final intThe field for theyearrecord component. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintday()Returns the value of thedayrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.month()Returns the value of themonthrecord component.intReturns the value of themonthValuerecord component.static NaftahDate.Dateof(int day, int monthValue, Chronology chronology, int year) Creates aDateinstance using a numeric month value.static NaftahDate.Dateof(int day, String month, Chronology chronology, int year) Creates aDateinstance by resolving a month name into its numeric value using the provided chronology.toString()Returns a string representation of thisNaftahDate.Date.intyear()Returns the value of theyearrecord component.
-
Field Details
-
day
private final int dayThe field for thedayrecord component. -
month
The field for themonthrecord component. -
monthValue
private final int monthValueThe field for themonthValuerecord component. -
year
private final int yearThe field for theyearrecord component.
-
-
Constructor Details
-
Date
Creates an instance of aDaterecord class.- Parameters:
day- the value for thedayrecord componentmonth- the value for themonthrecord componentmonthValue- the value for themonthValuerecord componentyear- the value for theyearrecord component
-
-
Method Details
-
of
Creates aDateinstance by resolving a month name into its numeric value using the provided chronology.The month name is interpreted according to the given chronology: Hijri chronologies resolve Hijri month names, while non-Hijri chronologies resolve Gregorian month names.
- Parameters:
day- the day of the monthmonth- the month name (e.g. "رمضان", "يناير")chronology- the chronology used to resolve the month valueyear- the year value- Returns:
- a new
Dateinstance - Throws:
IllegalArgumentException- if the month name cannot be resolved for the given chronology
-
of
Creates aDateinstance using a numeric month value.The numeric month is converted back to its name according to the provided chronology. This ensures that the month name remains consistent with the calendar system.
- Parameters:
day- the day of the monthmonthValue- the numeric month value (1–12)chronology- the chronology used to resolve the month nameyear- the year value- Returns:
- a new
Dateinstance - Throws:
IllegalArgumentException- if the month value cannot be resolved for the given chronology
-
toString
Returns a string representation of thisNaftahDate.Date.The format is:
day month year
Numeric values are rendered using the configured number formatter, and the month name is preserved exactly as stored.
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
day
public int day()Returns the value of thedayrecord component.- Returns:
- the value of the
dayrecord component
-
month
Returns the value of themonthrecord component.- Returns:
- the value of the
monthrecord component
-
monthValue
public int monthValue()Returns the value of themonthValuerecord component.- Returns:
- the value of the
monthValuerecord component
-
year
public int year()Returns the value of theyearrecord component.- Returns:
- the value of the
yearrecord component
-