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
Members list
Value members
Constructors
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
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
Constructs a Date from java Instant
Constructs a Date from java Instant
Attributes
Concrete methods
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 typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
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
Returns the day of month (1-31).
Returns the day of month (1-31).
Attributes
- Returns
-
Day of month
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)
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
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
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
Get the modified julian day
Get the modified julian day
Attributes
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
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)
Returns the year component.
Returns the year component.
Attributes
- Returns
-
Year (negative values indicate BCE)
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
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
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