Record Class NaftahTime

java.lang.Object
java.lang.Record
org.daiitech.naftah.builtin.time.NaftahTime
Record Components:
time - the time component
zoneOrOffset - the optional time zone or offset component
temporal - the resolved Temporal representation
All Implemented Interfaces:
NaftahTemporal, NaftahTemporalPoint, TimeSupport

public record NaftahTime(NaftahTime.Time time, NaftahTime.ZoneOrOffset zoneOrOffset, Temporal temporal) extends Record implements NaftahTemporalPoint, TimeSupport
Represents an Arabic time expression, optionally including a time zone or offset, and a resolved Temporal representation.

Implemented as a record with the components:

This record implements NaftahTemporalPoint and is typically produced after parsing Arabic time expressions.

Author:
Chakib Daii
  • Field Details

  • Constructor Details

  • Method Details

    • now

      public static NaftahTime now()
      Obtains the current time using the system default time zone.

      This method is equivalent to invoking now(null).

      Returns:
      the current ArabicTime
    • now

      public static NaftahTime now(NaftahTime.ZoneOrOffset zoneOrOffset)
      Obtains the current time using the specified zone or offset.

      If zoneOrOffset is null, the system default time zone is used.

      Parameters:
      zoneOrOffset - the zone or offset to use, or null to use the system default
      Returns:
      the current ArabicTime
    • of

      public static NaftahTime of(int hour, int minute)
      Creates an ArabicTime instance from hour and minute.

      Seconds and nanoseconds default to 0.

      Parameters:
      hour - the hour-of-day (0–23)
      minute - the minute-of-hour (0–59)
      Returns:
      a new ArabicTime instance
    • of

      public static NaftahTime of(int hour, int minute, NaftahTime.ZoneOrOffset zoneOrOffset)
      Creates an ArabicTime instance from hour and minute, optionally associated with a time zone or offset.

      The second and nanosecond fields are set to 0.

      Parameters:
      hour - the hour-of-day (0–23)
      minute - the minute-of-hour (0–59)
      zoneOrOffset - the optional time zone or offset, may be null
      Returns:
      a new ArabicTime instance, not null
    • of

      public static NaftahTime of(int hour, int minute, int second)
      Creates an ArabicTime instance from hour, minute, and second.

      Nano-of-second defaults to 0.

      Parameters:
      hour - the hour-of-day (0–23)
      minute - the minute-of-hour (0–59)
      second - the second-of-minute (0–59)
      Returns:
      a new ArabicTime instance
    • of

      public static NaftahTime of(int hour, int minute, int second, NaftahTime.ZoneOrOffset zoneOrOffset)
      Creates an ArabicTime instance from hour, minute, and second, optionally associated with a time zone or offset.

      The nanosecond field is set to 0.

      Parameters:
      hour - the hour-of-day (0–23)
      minute - the minute-of-hour (0–59)
      second - the second-of-minute (0–59)
      zoneOrOffset - the optional time zone or offset, may be null
      Returns:
      a new ArabicTime instance, not null
    • of

      public static NaftahTime of(int hour, int minute, int second, int nanoOfSecond)
      Creates an ArabicTime instance from hour, minute, second, and nanosecond.
      Parameters:
      hour - the hour-of-day (0–23)
      minute - the minute-of-hour (0–59)
      second - the second-of-minute (0–59)
      nanoOfSecond - the nanosecond-of-second (0–999,999,999)
      Returns:
      a new ArabicTime instance
    • of

      public static NaftahTime of(int hour, int minute, int second, int nanoOfSecond, NaftahTime.ZoneOrOffset zoneOrOffset)
      Creates an ArabicTime instance from hour, minute, second, and nanosecond, optionally associated with a time zone or offset.
      Parameters:
      hour - the hour-of-day (0–23)
      minute - the minute-of-hour (0–59)
      second - the second-of-minute (0–59)
      nanoOfSecond - the nanosecond-of-second (0–999,999,999)
      zoneOrOffset - the optional time zone or offset, may be null
      Returns:
      a new ArabicTime instance, not null
    • ofSecondOfDay

      public static NaftahTime ofSecondOfDay(long secondOfDay)
      Creates an ArabicTime instance from the total number of seconds since midnight.
      Parameters:
      secondOfDay - the second-of-day (0–86,399)
      Returns:
      a new ArabicTime instance
    • ofSecondOfDay

      public static NaftahTime ofSecondOfDay(long secondOfDay, NaftahTime.ZoneOrOffset zoneOrOffset)
      Creates an ArabicTime instance from the total number of seconds since midnight, optionally associated with a time zone or offset.
      Parameters:
      secondOfDay - the second-of-day (0–86,399)
      zoneOrOffset - the optional time zone or offset, may be null
      Returns:
      a new ArabicTime instance, not null
    • ofNanoOfDay

      public static NaftahTime ofNanoOfDay(long nanoOfDay)
      Creates an ArabicTime instance from the total number of nanoseconds since midnight.
      Parameters:
      nanoOfDay - the nano-of-day (0–86,399,999,999,999)
      Returns:
      a new ArabicTime instance
    • ofNanoOfDay

      public static NaftahTime ofNanoOfDay(long nanoOfDay, NaftahTime.ZoneOrOffset zoneOrOffset)
      Creates an ArabicTime instance from the total number of nanoseconds since midnight, optionally associated with a time zone or offset.
      Parameters:
      nanoOfDay - the nano-of-day (0–86,399,999,999,999)
      zoneOrOffset - the optional time zone or offset, may be null
      Returns:
      a new ArabicTime instance, not null
    • of

      public static NaftahTime of(NaftahTime.Time time, NaftahTime.ZoneOrOffset zoneOrOffset, Temporal temporal)
      Creates a new ArabicTime instance using explicit components.

      This factory method is typically used when the parsed time, optional zone/offset, and the resolved Temporal representation are already available.

      Parameters:
      time - the logical time component (hour, minute, second, nano, AM/PM)
      zoneOrOffset - the optional time zone or offset information, may be null
      temporal - the resolved Temporal representation backing this time
      Returns:
      a new ArabicTime instance
    • of

      public static NaftahTime of(NaftahTime.Time time, NaftahTime.ZoneOrOffset zoneOrOffset)
      Creates a new ArabicTime instance using explicit components and resolves the backing Temporal automatically.
      Parameters:
      time - the logical time component, not null
      zoneOrOffset - the optional time zone or offset, may be null
      Returns:
      a new ArabicTime instance, not null
    • of

      public static NaftahTime of(NaftahTime.ZoneOrOffset zoneOrOffset, Temporal temporal)
      Creates a new ArabicTime instance by extracting time fields directly from a Temporal object.

      The following fields are resolved if supported by the temporal:

      Unsupported fields default to 0.

      The resulting NaftahTime.Time instance is created using a 24-hour clock representation, with no AM/PM marker.

      Parameters:
      zoneOrOffset - the optional time zone or offset information, may be null
      temporal - the temporal object from which time fields are extracted
      Returns:
      a new ArabicTime instance
      Throws:
      IllegalArgumentException - if the temporal cannot represent a valid time
    • getHour

      public int getHour()
      Gets the hour-of-day field.
      Specified by:
      getHour in interface TimeSupport
      Returns:
      the hour-of-day, from 0 to 23
    • getMinute

      public int getMinute()
      Gets the minute-of-hour field.
      Specified by:
      getMinute in interface TimeSupport
      Returns:
      the minute-of-hour, from 0 to 59
    • getSecond

      public int getSecond()
      Gets the second-of-minute field.
      Specified by:
      getSecond in interface TimeSupport
      Returns:
      the second-of-minute, from 0 to 59
    • getNano

      public int getNano()
      Gets the nano-of-second field.
      Specified by:
      getNano in interface TimeSupport
      Returns:
      the nano-of-second, from 0 to 999,999,999
    • plus

      public NaftahTime plus(NaftahTemporalAmount naftahTemporalAmount)
      Returns a new ArabicTime obtained by adding the given Arabic temporal amount to this time.
      Specified by:
      plus in interface NaftahTemporalPoint
      Parameters:
      naftahTemporalAmount - the temporal amount to add
      Returns:
      a new ArabicTime instance
    • plusHours

      public NaftahTime plusHours(long hoursToAdd)
      Returns a new ArabicTime with the specified number of hours added.

      If hoursToAdd is zero, this instance is returned unchanged.

      Specified by:
      plusHours in interface TimeSupport
      Parameters:
      hoursToAdd - the number of hours to add, may be negative
      Returns:
      a new ArabicTime instance with the hours added
    • plusMinutes

      public NaftahTime plusMinutes(long minutesToAdd)
      Returns a new ArabicTime with the specified number of minutes added.

      If minutesToAdd is zero, this instance is returned unchanged.

      Specified by:
      plusMinutes in interface TimeSupport
      Parameters:
      minutesToAdd - the number of minutes to add, may be negative
      Returns:
      a new ArabicTime instance with the minutes added
    • plusSeconds

      public NaftahTime plusSeconds(long secondsToAdd)
      Returns a new ArabicTime with the specified number of seconds added.

      If secondsToAdd is zero, this instance is returned unchanged.

      Specified by:
      plusSeconds in interface TimeSupport
      Parameters:
      secondsToAdd - the number of seconds to add, may be negative
      Returns:
      a new ArabicTime instance with the seconds added
    • plusNanos

      public NaftahTime plusNanos(long nanosToAdd)
      Returns a new ArabicTime with the specified number of nanoseconds added.

      If nanosToAdd is zero, this instance is returned unchanged.

      Specified by:
      plusNanos in interface TimeSupport
      Parameters:
      nanosToAdd - the number of nanoseconds to add, may be negative
      Returns:
      a new ArabicTime instance with the nanoseconds added
    • minus

      public NaftahTime minus(NaftahTemporalAmount naftahTemporalAmount)
      Returns a new ArabicTime obtained by subtracting the given Arabic temporal amount from this time.
      Specified by:
      minus in interface NaftahTemporalPoint
      Parameters:
      naftahTemporalAmount - the temporal amount to subtract
      Returns:
      a new ArabicTime instance
    • minusHours

      public NaftahTime minusHours(long hoursToSubtract)
      Returns a new ArabicTime with the specified number of hours subtracted.

      If hoursToSubtract is zero, this instance is returned unchanged.

      Specified by:
      minusHours in interface TimeSupport
      Parameters:
      hoursToSubtract - the number of hours to subtract, may be negative
      Returns:
      a new ArabicTime instance with the hours subtracted
    • minusMinutes

      public NaftahTime minusMinutes(long minutesToSubtract)
      Returns a new ArabicTime with the specified number of minutes subtracted.

      If minutesToSubtract is zero, this instance is returned unchanged.

      Specified by:
      minusMinutes in interface TimeSupport
      Parameters:
      minutesToSubtract - the number of minutes to subtract, may be negative
      Returns:
      a new ArabicTime instance with the minutes subtracted
    • minusSeconds

      public NaftahTime minusSeconds(long secondsToSubtract)
      Returns a new ArabicTime with the specified number of seconds subtracted.

      If secondsToSubtract is zero, this instance is returned unchanged.

      Specified by:
      minusSeconds in interface TimeSupport
      Parameters:
      secondsToSubtract - the number of seconds to subtract, may be negative
      Returns:
      a new ArabicTime instance with the seconds subtracted
    • minusNanos

      public NaftahTime minusNanos(long nanosToSubtract)
      Returns a new ArabicTime with the specified number of nanoseconds subtracted.

      If nanosToSubtract is zero, this instance is returned unchanged.

      Specified by:
      minusNanos in interface TimeSupport
      Parameters:
      nanosToSubtract - the number of nanoseconds to subtract, may be negative
      Returns:
      a new ArabicTime instance with the nanoseconds subtracted
    • compute

      NaftahTime compute(NaftahTemporalAmount arabicTemporalAmount, Function<TemporalAmount,Temporal> computeFunction)
      Computes a new ArabicTime by applying the given temporal computation.

      Only duration-based arithmetic is supported for time-only values. Period-based operations are not permitted.

      Parameters:
      arabicTemporalAmount - the temporal amount to apply
      computeFunction - the temporal computation function
      Returns:
      a new ArabicTime instance
      Throws:
      IllegalArgumentException - if the operation is not supported
    • toString

      public String toString()
      Returns a string representation of this ArabicTime in the format: "time zoneOrOffset".

      If a NaftahTime.ZoneOrOffset is present, it is appended after the time. Otherwise, only the time component is returned.

      Specified by:
      toString in class Record
      Returns:
      a formatted string representing the time and optional zone or offset
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • time

      public NaftahTime.Time time()
      Returns the value of the time record component.
      Returns:
      the value of the time record component
    • zoneOrOffset

      public NaftahTime.ZoneOrOffset zoneOrOffset()
      Returns the value of the zoneOrOffset record component.
      Returns:
      the value of the zoneOrOffset record component
    • temporal

      public Temporal temporal()
      Returns the value of the temporal record component.
      Specified by:
      temporal in interface NaftahTemporalPoint
      Returns:
      the value of the temporal record component