Record Class NaftahDate
- Record Components:
date- the parsed date componentcalendar- the optional calendar specificationtemporal- the resolved temporal
- All Implemented Interfaces:
DateSupport,NaftahTemporal,NaftahTemporalPoint
- A
NaftahDate.Datecomponent (day, month, year) - An optional
NaftahDate.Calendarcomponent - A resolved
Temporalrepresentation
This record is typically produced after parsing Naftah date expressions
and resolving them against a specific Chronology.
It supports both Gregorian and non-Gregorian calendars (e.g. Hijri) and preserves the original Naftah month and calendar names.
- Author:
- Chakib Daii
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents an Naftah calendar specification.static final recordRepresents the date part of a Naftah date expression. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final NaftahDate.CalendarThe field for thecalendarrecord component.private final NaftahDate.DateThe field for thedaterecord component.private final TemporalThe field for thetemporalrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionNaftahDate(NaftahDate.Date date, NaftahDate.Calendar calendar, Temporal temporal) Creates an instance of aNaftahDaterecord class. -
Method Summary
Modifier and TypeMethodDescriptioncalendar()Returns the value of thecalendarrecord component.(package private) NaftahDatecompute(NaftahTemporalAmount arabicTemporalAmount, Function<TemporalAmount, Temporal> computeFunction) Computes a newNaftahDateby applying the given temporal computation.date()Returns the value of thedaterecord component.final booleanIndicates whether some other object is "equal to" this one.intReturns the day-of-month component of thisNaftahDate.Returns the day of the week as a string for thisNaftahDate.intReturns the day-of-year for thisNaftahDateaccording to its chronology.getMonth()Returns the name of the month for thisNaftahDate.intReturns the numeric month value (1–12) of thisNaftahDate.intgetYear()Returns the year component of thisNaftahDate.final inthashCode()Returns a hash code value for this object.booleanChecks if the year of thisNaftahDateis a leap year in its chronology.intReturns the length of the month in days for thisNaftahDate.intReturns the length of the year in days for thisNaftahDate.minus(NaftahTemporalAmount naftahTemporalAmount) Returns a newNaftahDateobtained by subtracting the given Naftah temporal amount from this date.minusDays(long daysToSubtract) Returns a newNaftahDatewith the specified number of days subtracted.minusMonths(long monthsToSubtract) Returns a newNaftahDatewith the specified number of months subtracted.minusWeeks(long weeksToSubtract) Returns a newNaftahDatewith the specified number of weeks subtracted.minusYears(long yearsToSubtract) Returns a newNaftahDatewith the specified number of years subtracted.static NaftahDatenow()Obtains the current date using the default chronology and the system default time zone.static NaftahDatenow(Chronology chronology) Obtains the current date using the specified chronology and the system default time zone.static NaftahDatenow(Chronology chronology, NaftahTime.ZoneOrOffset zoneOrOffset) Obtains the current date using the specified chronology and zone or offset.static NaftahDatenow(NaftahDate.Calendar calendar) Obtains the current date using the specified calendar and the system default time zone.static NaftahDatenow(NaftahDate.Calendar calendar, NaftahTime.ZoneOrOffset zoneOrOffset) Obtains the current date using the specified calendar and zone or offset.static NaftahDatenow(NaftahTime.ZoneOrOffset zoneOrOffset) Obtains the current date using the default chronology and the specified zone or offset.static NaftahDateof(int day, int month, int year) Creates a newNaftahDateinstance using numeric day, month, and year values.static NaftahDateCreates a newNaftahDateinstance using a day, Naftah month name, and year.static NaftahDateof(Chronology chronology, int day, int month, int year) Creates a newNaftahDateinstance using a specific chronology, numeric day, month, and year.static NaftahDateof(Chronology chronology, int day, String month, int year) Creates a newNaftahDateinstance using a specific chronology, day, month name, and year.static NaftahDateof(NaftahDate.Calendar calendar, int day, int month, int year) Creates a newNaftahDateinstance using a calendar and numeric day, month, and year.static NaftahDateof(NaftahDate.Calendar calendar, int day, String month, int year) Creates a newNaftahDateinstance using a calendar, day, month name, and year.static NaftahDateof(NaftahDate.Calendar calendar, Temporal temporal) Creates a newNaftahDateinstance from aTemporalobject and a calendar.static NaftahDateof(NaftahDate.Date date, NaftahDate.Calendar calendar) Creates a newNaftahDateinstance from its parsed components and resolves the underlyingTemporalrepresentation automatically.static NaftahDateof(NaftahDate.Date date, NaftahDate.Calendar calendar, Temporal temporal) Creates a newNaftahDateinstance from its parsed components.plus(NaftahTemporalAmount naftahTemporalAmount) Returns a newNaftahDateobtained by adding the given Naftah temporal amount to this date.plusDays(long daysToAdd) Returns a newNaftahDatewith the specified number of days added.plusMonths(long monthsToAdd) Returns a newNaftahDatewith the specified number of months added.plusWeeks(long weeksToAdd) Returns a newNaftahDatewith the specified number of weeks added.plusYears(long yearsToAdd) Returns a newNaftahDatewith the specified number of years added.temporal()Returns the value of thetemporalrecord component.Returns this date interpreted in its calendar chronology.longConverts thisNaftahDateto the number of days since the epoch (1970-01-01) in the ISO calendar system.toString()Returns a string representation of thisNaftahDatein the format: "date calendar".Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.daiitech.naftah.builtin.time.NaftahTemporalPoint
greaterThan, greaterThanEquals, isEquals, lessThan, lessThanEquals, notEquals
-
Field Details
-
Constructor Details
-
Method Details
-
now
Obtains the current date using the default chronology and the system default time zone.This method is equivalent to invoking:
now(ChronologyUtils.DEFAULT_CHRONOLOGY, null).- Returns:
- the current
NaftahDate
-
now
Obtains the current date using the specified chronology and the system default time zone.The supplied chronology determines how the current day, month, and year are interpreted.
- Parameters:
chronology- the chronology to use (notnull)- Returns:
- the current
NaftahDate - Throws:
NullPointerException- ifchronologyisnull
-
now
Obtains the current date using the specified calendar and the system default time zone.- Parameters:
calendar- the calendar to use (notnull)- Returns:
- the current
NaftahDate - Throws:
NullPointerException- ifcalendarisnull
-
now
Obtains the current date using the default chronology and the specified zone or offset.This method is useful when resolving the current date relative to a specific time zone or fixed offset.
- Parameters:
zoneOrOffset- the zone or offset to use, ornullto use the system default- Returns:
- the current
NaftahDate
-
now
Obtains the current date using the specified chronology and zone or offset.- Parameters:
chronology- the chronology to use (notnull)zoneOrOffset- the zone or offset to use, ornullto use the system default- Returns:
- the current
NaftahDate - Throws:
NullPointerException- ifchronologyisnull
-
now
Obtains the current date using the specified calendar and zone or offset.The returned
NaftahDaterepresents the current calendar date as resolved by the provided calendar and zone or offset.- Parameters:
calendar- the calendar to use (notnull)zoneOrOffset- the zone or offset to use, ornullto use the system default- Returns:
- the current
NaftahDate - Throws:
NullPointerException- ifcalendarisnull
-
of
Creates a newNaftahDateinstance from its parsed components.This factory method should be used when the
Date, theNaftahDate.Calendar, and the underlyingTemporalrepresentation are already known. No additional parsing or chronology resolution is performed.- Parameters:
date- the parsed date component (day, month, year) according to the calendarcalendar- the calendar associated with this date (e.g., Gregorian or Hijri)temporal- the resolved temporal representation backing this date- Returns:
- a new
NaftahDateinstance combining all components
-
of
Creates a newNaftahDateinstance from its parsed components and resolves the underlyingTemporalrepresentation automatically.This factory method should be used when the
Dateand the associatedNaftahDate.Calendarare already known, but the backingTemporalhas not yet been created. The temporal representation is derived using the calendar’s chronology.- Parameters:
date- the parsed date component (day, month, year) according to the calendarcalendar- the calendar associated with this date (e.g., Gregorian or Hijri)- Returns:
- a new
NaftahDateinstance combining all components
-
of
Creates a newNaftahDateinstance from aTemporalobject and a calendar.This method extracts the day, month, and year fields from the given temporal object and constructs an
NaftahDateusing the provided calendar's chronology.The temporal must support the following fields:
- Parameters:
calendar- the calendar that determines the chronology of the datetemporal- the temporal object containing date information- Returns:
- a new
NaftahDateinstance derived from the temporal - Throws:
IllegalArgumentException- if the temporal does not support day, month, or year fields
-
of
Creates a newNaftahDateinstance using a day, Naftah month name, and year.This method uses the default chronology defined in
ChronologyUtils.DEFAULT_CHRONOLOGY.- Parameters:
day- the day of the monthmonth- the month name (e.g., "رمضان", "يناير")year- the year value- Returns:
- a new
NaftahDateinstance with the specified components
-
of
Creates a newNaftahDateinstance using a specific chronology, day, month name, and year.The chronology is used to resolve the month name to its numeric value and to determine leap years.
- Parameters:
chronology- the chronology to use (e.g., ISO or Hijri)day- the day of the monthmonth- the month nameyear- the year value- Returns:
- a new
NaftahDateinstance with the specified components
-
of
Creates a newNaftahDateinstance using a calendar, day, month name, and year.The month name is resolved to a numeric month using the provided calendar's chronology.
- Parameters:
calendar- the calendar to useday- the day of the monthmonth- the month nameyear- the year value- Returns:
- a new
NaftahDateinstance with the specified components
-
of
Creates a newNaftahDateinstance using numeric day, month, and year values.This method uses the default chronology defined in
ChronologyUtils.DEFAULT_CHRONOLOGY.- Parameters:
day- the day of the monthmonth- the numeric month value (1–12)year- the year value- Returns:
- a new
NaftahDateinstance with the specified components
-
of
Creates a newNaftahDateinstance using a specific chronology, numeric day, month, and year.The chronology is used for leap year calculations and month name resolution.
- Parameters:
chronology- the chronology to use (e.g., ISO or Hijri)day- the day of the monthmonth- the numeric month value (1–12)year- the year value- Returns:
- a new
NaftahDateinstance with the specified components
-
of
Creates a newNaftahDateinstance using a calendar and numeric day, month, and year.The calendar provides the chronology to resolve leap years and month names.
- Parameters:
calendar- the calendar to useday- the day of the monthmonth- the numeric month value (1–12)year- the year value- Returns:
- a new
NaftahDateinstance with the specified components
-
toChronoDate
Returns this date interpreted in its calendar chronology.The returned
ChronoLocalDateis derived from the underlying ISO temporal and the associatedChronology.This method must be used whenever calendar-specific fields (year, month, day) are required.
- Returns:
- a
ChronoLocalDatein the calendar's chronology
-
toEpochDay
public long toEpochDay()Converts thisNaftahDateto the number of days since the epoch (1970-01-01) in the ISO calendar system.- Specified by:
toEpochDayin interfaceDateSupport- Returns:
- the epoch day count
-
getYear
public int getYear()Returns the year component of thisNaftahDate.- Specified by:
getYearin interfaceDateSupport- Returns:
- the year value
-
getMonthValue
public int getMonthValue()Returns the numeric month value (1–12) of thisNaftahDate.- Specified by:
getMonthValuein interfaceDateSupport- Returns:
- the month value
-
getMonth
Returns the name of the month for thisNaftahDate.- Specified by:
getMonthin interfaceDateSupport- Returns:
- the month name
-
getDayOfMonth
public int getDayOfMonth()Returns the day-of-month component of thisNaftahDate.- Specified by:
getDayOfMonthin interfaceDateSupport- Returns:
- the day of the month
-
getDayOfYear
public int getDayOfYear()Returns the day-of-year for thisNaftahDateaccording to its chronology.- Specified by:
getDayOfYearin interfaceDateSupport- Returns:
- the day of the year (1–365 or 1–366 for leap years)
-
getDayOfWeek
Returns the day of the week as a string for thisNaftahDate.The calculation is based on the epoch day of the underlying
ChronoLocalDate.- Specified by:
getDayOfWeekin interfaceDateSupport- Returns:
- the name of the day of the week
-
isLeapYear
public boolean isLeapYear()Checks if the year of thisNaftahDateis a leap year in its chronology.- Specified by:
isLeapYearin interfaceDateSupport- Returns:
trueif the year is a leap year,falseotherwise
-
lengthOfMonth
public int lengthOfMonth()Returns the length of the month in days for thisNaftahDate.The length is determined according to the chronology of the calendar.
- Specified by:
lengthOfMonthin interfaceDateSupport- Returns:
- the number of days in the month
-
lengthOfYear
public int lengthOfYear()Returns the length of the year in days for thisNaftahDate.The number of days depends on the chronology of the date:
- For Gregorian years (ISO chronology), leap years return 366 days, and non-leap years return 365 days.
- For Hijri years, leap years return 355 days, and non-leap years return 354 days.
- Specified by:
lengthOfYearin interfaceDateSupport- Returns:
- the number of days in the year according to its chronology
-
plus
Returns a newNaftahDateobtained by adding the given Naftah temporal amount to this date.- Specified by:
plusin interfaceNaftahTemporalPoint- Parameters:
naftahTemporalAmount- the temporal amount to add- Returns:
- a new
NaftahDateinstance
-
plusYears
Returns a newNaftahDatewith the specified number of years added.- Specified by:
plusYearsin interfaceDateSupport- Parameters:
yearsToAdd- the number of years to add, may be negative- Returns:
- a new
NaftahDateinstance
-
plusMonths
Returns a newNaftahDatewith the specified number of months added.- Specified by:
plusMonthsin interfaceDateSupport- Parameters:
monthsToAdd- the number of months to add, may be negative- Returns:
- a new
NaftahDateinstance
-
plusWeeks
Returns a newNaftahDatewith the specified number of weeks added.- Specified by:
plusWeeksin interfaceDateSupport- Parameters:
weeksToAdd- the number of weeks to add, may be negative- Returns:
- a new
NaftahDateinstance
-
plusDays
Returns a newNaftahDatewith the specified number of days added.- Specified by:
plusDaysin interfaceDateSupport- Parameters:
daysToAdd- the number of days to add, may be negative- Returns:
- a new
NaftahDateinstance
-
minus
Returns a newNaftahDateobtained by subtracting the given Naftah temporal amount from this date.- Specified by:
minusin interfaceNaftahTemporalPoint- Parameters:
naftahTemporalAmount- the temporal amount to subtract- Returns:
- a new
NaftahDateinstance
-
minusYears
Returns a newNaftahDatewith the specified number of years subtracted.- Specified by:
minusYearsin interfaceDateSupport- Parameters:
yearsToSubtract- the number of years to subtract, may be negative- Returns:
- a new
NaftahDateinstance
-
minusMonths
Returns a newNaftahDatewith the specified number of months subtracted.- Specified by:
minusMonthsin interfaceDateSupport- Parameters:
monthsToSubtract- the number of months to subtract, may be negative- Returns:
- a new
NaftahDateinstance
-
minusWeeks
Returns a newNaftahDatewith the specified number of weeks subtracted.- Specified by:
minusWeeksin interfaceDateSupport- Parameters:
weeksToSubtract- the number of weeks to subtract, may be negative- Returns:
- a new
NaftahDateinstance
-
minusDays
Returns a newNaftahDatewith the specified number of days subtracted.- Specified by:
minusDaysin interfaceDateSupport- Parameters:
daysToSubtract- the number of days to subtract, may be negative- Returns:
- a new
NaftahDateinstance
-
compute
NaftahDate compute(NaftahTemporalAmount arabicTemporalAmount, Function<TemporalAmount, Temporal> computeFunction) Computes a newNaftahDateby applying the given temporal computation.Date-based arithmetic supports:
NaftahPeriodNaftahDurationof at least 24 hoursNaftahPeriodWithDuration
Durations shorter than 24 hours are not permitted for date-only values.
- Parameters:
arabicTemporalAmount- the temporal amount to applycomputeFunction- the temporal computation function- Returns:
- a new
NaftahDateinstance - Throws:
IllegalArgumentException- if the operation is not supported
-
toString
Returns a string representation of thisNaftahDatein the format: "date calendar".If a
NaftahDate.Calendarcomponent is present, it is appended after the date. Otherwise, only the date is returned. -
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. All components in this record class are compared withObjects::equals(Object,Object). -
date
Returns the value of thedaterecord component.- Returns:
- the value of the
daterecord component
-
calendar
Returns the value of thecalendarrecord component.- Returns:
- the value of the
calendarrecord component
-
temporal
Returns the value of thetemporalrecord component.- Specified by:
temporalin interfaceNaftahTemporalPoint- Returns:
- the value of the
temporalrecord component
-