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 month
monthValue - 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

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The field for the day record component.
    private final String
    The field for the month record component.
    private final int
    The field for the monthValue record component.
    private final int
    The field for the year record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Date(int day, String month, int monthValue, int year)
    Creates an instance of a Date record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    day()
    Returns the value of the day record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the month record component.
    int
    Returns the value of the monthValue record component.
    of(int day, int monthValue, Chronology chronology, int year)
    Creates a Date instance using a numeric month value.
    of(int day, String month, Chronology chronology, int year)
    Creates a Date instance by resolving a month name into its numeric value using the provided chronology.
    Returns a string representation of this NaftahDate.Date.
    int
    Returns the value of the year record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • day

      private final int day
      The field for the day record component.
    • month

      private final String month
      The field for the month record component.
    • monthValue

      private final int monthValue
      The field for the monthValue record component.
    • year

      private final int year
      The field for the year record component.
  • Constructor Details

    • Date

      public Date(int day, String month, int monthValue, int year)
      Creates an instance of a Date record class.
      Parameters:
      day - the value for the day record component
      month - the value for the month record component
      monthValue - the value for the monthValue record component
      year - the value for the year record component
  • Method Details

    • of

      public static NaftahDate.Date of(int day, String month, Chronology chronology, int year)
      Creates a Date instance 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 month
      month - the month name (e.g. "رمضان", "يناير")
      chronology - the chronology used to resolve the month value
      year - the year value
      Returns:
      a new Date instance
      Throws:
      IllegalArgumentException - if the month name cannot be resolved for the given chronology
    • of

      public static NaftahDate.Date of(int day, int monthValue, Chronology chronology, int year)
      Creates a Date instance 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 month
      monthValue - the numeric month value (1–12)
      chronology - the chronology used to resolve the month name
      year - the year value
      Returns:
      a new Date instance
      Throws:
      IllegalArgumentException - if the month value cannot be resolved for the given chronology
    • toString

      public String toString()
      Returns a string representation of this NaftahDate.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.

      Specified by:
      toString in class Record
      Returns:
      a formatted string representing this date
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • day

      public int day()
      Returns the value of the day record component.
      Returns:
      the value of the day record component
    • month

      public String month()
      Returns the value of the month record component.
      Returns:
      the value of the month record component
    • monthValue

      public int monthValue()
      Returns the value of the monthValue record component.
      Returns:
      the value of the monthValue record component
    • year

      public int year()
      Returns the value of the year record component.
      Returns:
      the value of the year record component