Date

org.abh80.nf.core.time.Date
See theDate companion object
class Date extends Comparable[Date], Serializable

A robust date implementation that handles dates in different calendar systems.

This class provides functionality to work with dates across three calendar systems:

  • Gregorian calendar (current standard calendar system)
  • Julian calendar (historical calendar used before Gregorian)
  • Proleptic Julian calendar (extension of Julian calendar for dates before year 1)

The implementation uses J2000 day number as internal representation, which counts days from January 1, 2000 (known as the J2000 epoch in astronomy).

The class automatically handles calendar transitions:

  • Before year 1: Proleptic Julian calendar
  • Years 1-1582: Julian calendar
  • After October 4, 1582: Gregorian calendar

Attributes

Note

This class is immutable and thread-safe

it's recommended to initialize this class from the Date companion object

Companion
object
Graph
Supertypes
trait Serializable
trait Comparable[Date]
class Object
trait Matchable
class Any

Members list

Value members

Constructors

def this(year: Int, month: Int, day: Int)

Constructs a Date from year, month, and day components.

Constructs a Date from year, month, and day components.

Value parameters

day

The day of month

month

The month (1-12)

year

The year (can be negative for BCE dates)

Attributes

Throws
IllegalArgumentException

if the date components form an invalid date

def this(j2000DayOffset: Int)

Constructs a Date from J2000 day offset.

Constructs a Date from J2000 day offset.

Value parameters

j2000DayOffset

Number of days since January 1, 2000

Attributes

def this(instant: Instant)

Constructs a Date from java Instant

Constructs a Date from java Instant

Attributes

Concrete methods

override def compareTo(o: Date): Int

Attributes

Definition Classes
Comparable
override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Any
def getDay: Int

Returns the day of month (1-31).

Returns the day of month (1-31).

Attributes

Returns

Day of month

def getDayOfWeek: Int

Returns the ISO day of week.

Returns the ISO day of week.

In ISO standard:

  • Monday = 1
  • Tuesday = 2 ...
  • Sunday = 7

Attributes

Returns

Day of week (1-7)

def getDayOfYear: Int

Returns the day of year (1-366).

Returns the day of year (1-366).

January 1st is day 1, December 31st is day 365/366.

Attributes

Returns

Day of year

def getJ2000Day: Int

Returns the J2000 day number for this date.

Returns the J2000 day number for this date.

The J2000 day number is the number of days since January 1, 2000. Negative values indicate dates before J2000.

Attributes

Returns

J2000 day number

def getJulianDay: Int

Returns the Julian Day Number for this date.

Returns the Julian Day Number for this date.

The Julian Day Number is a continuous count of days since the beginning of the Julian Period, used primarily in astronomy.

Attributes

Returns

Julian Day Number

def getMJD: Int

Get the modified julian day

Get the modified julian day

Attributes

def getMonth: Int

Returns the month number (1-12).

Returns the month number (1-12).

Attributes

Returns

Month as integer where 1=January, 12=December

Returns the month as an enumerated type.

Returns the month as an enumerated type.

Attributes

Returns

Month enum value

def getWeek: Int

Returns the ISO week number for the date.

Returns the ISO week number for the date.

The ISO week numbering system defines:

  • Week 1 is the week containing January 4th
  • Weeks start on Monday
  • Week can belong to different year than the date

Attributes

Returns

Week number (1-53)

def getYear: Int

Returns the year component.

Returns the year component.

Attributes

Returns

Year (negative values indicate BCE)

override def hashCode(): Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Any
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def toString(f: (Int, Int, Int) => StringDateFormat): String

Converts the date to a string representation using the specified format.

Converts the date to a string representation using the specified format.

Value parameters

f

The format function that defines the output format

Attributes

Returns

Formatted date string