public final class GregorianDate extends Object implements Comparable<GregorianDate>, IEquatable<GregorianDate>, ImmutableValueType
GregorianDate
does not include a TimeStandard
as JulianDate
does. However, without explicitly specifying a TimeStandard
for the date, the GregorianDate
is assumed to be represented in CoordinatedUniversalTime
(get
). GregorianDate
is
also capable of representing leap seconds, which are represented as the second measured from 60 to 61. In this case,
the GregorianDate
is assumed to be the CoordinatedUniversalTime
(get
) represented
in InternationalAtomicTime
(get
) which can represent leap seconds exactly.Modifier and Type | Field and Description |
---|---|
static GregorianDate |
MaxValue
Represents the largest possible value of
GregorianDate . |
static GregorianDate |
MinValue
Represents the smallest possible value of
GregorianDate . |
Constructor and Description |
---|
GregorianDate()
Initializes a new instance.
|
GregorianDate(int year,
double daysOfYear)
Initializes a
GregorianDate from the provided values. |
GregorianDate(int year,
int month,
int day)
Initializes a
GregorianDate from the provided values. |
GregorianDate(int year,
int dayOfYear,
int hour,
int minute,
double second)
Initializes a
GregorianDate from the provided values. |
GregorianDate(int year,
int month,
int day,
int hour,
int minute,
double second)
Initializes a
GregorianDate from the provided values. |
GregorianDate(JulianDate julianDate)
Initializes a
GregorianDate from the provided
JulianDate . |
GregorianDate(JulianDate julianDate,
TimeStandard timeStandard)
Initializes a
GregorianDate from the provided
JulianDate . |
GregorianDate(ZonedDateTime dateTime)
Initializes a
GregorianDate from the provided
ZonedDateTime . |
Modifier and Type | Method and Description |
---|---|
GregorianDate |
addDays(double days)
Adds the specified number of days to this date and returns the new date.
|
GregorianDate |
addHours(double hours)
Adds the specified number of hours to this date and returns the new date.
|
GregorianDate |
addMinutes(double minutes)
Adds the specified number of minutes to this date and returns the new date.
|
GregorianDate |
addSeconds(double seconds)
Adds the specified number of seconds to this date and returns the new date.
|
int |
compareTo(GregorianDate other)
Compares this instance with another instance of the same type.
|
static boolean |
equals(GregorianDate left,
GregorianDate right)
Returns
true if the two instances are exactly equal. |
boolean |
equals(Object obj)
Indicates whether another object is exactly equal to this instance.
|
boolean |
equalsType(GregorianDate other)
Indicates whether another instance of this type is exactly equal to this instance.
|
int |
getDay()
Gets the day of the month (in the range 1 through the number of days in the
month).
|
DayOfWeek |
getDayOfWeek()
Gets the day of the week represented by this instance.
|
int |
getDayOfYear()
Gets the day of the year represented by this instance.
|
int |
getHour()
Gets the hour (in the range 0 through 23).
|
double |
getJulianSecondsOfDay()
Gets the corresponding seconds past noon for this instance.
|
int |
getMinute()
Gets the minute (in the range 0 through 59).
|
int |
getMonth()
Gets the month of the year (in the range 1 through 12).
|
static GregorianDate |
getNow()
Gets the
GregorianDate that represents the current date and time. |
double |
getSecond()
Gets the second, including fractional seconds (in the range 0.0 up to, but not
including, 61.0).
|
double |
getSecondsOfDay()
Gets the corresponding seconds past midnight for this instance.
|
int |
getYear()
Gets the year.
|
static boolean |
greaterThan(GregorianDate left,
GregorianDate right)
Returns
true if left is greater than right . |
static boolean |
greaterThanOrEqual(GregorianDate left,
GregorianDate right)
Returns
true if left is greater than or equal to right . |
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
static boolean |
isValid(int year,
int month,
int day,
int hour,
int minute,
double second)
Indicates whether the date values provided are a valid representation of a date
and time.
|
static boolean |
lessThan(GregorianDate left,
GregorianDate right)
Returns
true if left is less than right . |
static boolean |
lessThanOrEqual(GregorianDate left,
GregorianDate right)
Returns
true if left is less than or equal to right . |
static boolean |
notEquals(GregorianDate left,
GregorianDate right)
Returns
true if the two instances are not exactly equal. |
static GregorianDate |
parse(String s)
Converts the specified string representation of a date and time to its
GregorianDate equivalent. |
static GregorianDate |
parse(String s,
Locale provider)
Converts the specified string representation of a date and time to its
GregorianDate equivalent using the specified culture-specific
format information. |
static GregorianDate |
parseExact(String s,
String[] format,
Locale provider)
Converts the specified string representation of a date and time to its
GregorianDate equivalent using the specified format and
culture-specific format information. |
static GregorianDate |
parseExact(String s,
String format,
Locale provider)
Converts the specified string representation of a date and time to its
GregorianDate equivalent using the specified format and
culture-specific format information. |
GregorianDate |
roundSeconds(int digits)
Rounds this instance to the specified number of decimal digits in the seconds, rolling over to minutes, hours, days,
etc.
|
GregorianDate |
roundSeconds(int digits,
TimeStandard timeStandard)
Rounds this instance to the specified number of decimal digits in the seconds, rolling over to minutes, hours, days,
etc.
|
GregorianDate |
subtractDays(double days)
Subtracts the specified number of days from this date and returns the new date.
|
GregorianDate |
subtractHours(double hours)
Subtracts the specified number of hours from this date and returns the new date.
|
GregorianDate |
subtractMinutes(double minutes)
Subtracts the specified number of minutes from this date and returns the new date.
|
GregorianDate |
subtractSeconds(double seconds)
Subtracts the specified number of seconds from this date and returns the new date.
|
ZonedDateTime |
toDateTime()
Convert this
GregorianDate to a ZonedDateTime . |
String |
toIso8601String()
Converts the value of this instance to its equivalent ISO8601 extended string representation,
with fractional seconds represented to 15 digits.
|
String |
toIso8601String(Iso8601Format format)
Converts the value of this instance to its equivalent ISO8601 string representation,
with fractional seconds represented to 15 digits.
|
String |
toIso8601String(Iso8601Format format,
int digitsOfFractionalSeconds)
Converts the value of this instance to its equivalent ISO8601 string representation,
with fractional seconds represented to the specified number of digits.
|
JulianDate |
toJulianDate()
Convert this
GregorianDate to a JulianDate . |
JulianDate |
toJulianDate(TimeStandard timeStandard)
Convert this
GregorianDate to a JulianDate . |
String |
toLongDateString()
Converts the value of this instance to its equivalent long date string representation.
|
String |
toLongTimeString()
Converts the value of this instance to its equivalent long time string representation.
|
String |
toShortDateString()
Converts the value of this instance to its equivalent short date string representation.
|
String |
toShortTimeString()
Converts the value of this instance to its equivalent short time string representation.
|
String |
toString()
Converts the value of this instance to its equivalent string representation.
|
String |
toString(Locale provider)
Converts the value of this instance to its equivalent string
representation using the specified culture-specific format information.
|
String |
toString(String format)
Converts the value of this instance to its equivalent string
representation using the specified format.
|
String |
toString(String format,
Locale provider)
Converts the value of this instance to its equivalent string
representation using the specified format and culture-specific format information.
|
static boolean |
tryParse(String s,
GregorianDate[] result)
Converts the specified string representation of a date and time to its
GregorianDate equivalent. |
static boolean |
tryParse(String s,
Locale provider,
GregorianDate[] result)
Converts the specified string representation of a date and time to its
GregorianDate equivalent using the specified culture-specific
format information. |
@Nonnull public static final GregorianDate MaxValue
GregorianDate
.
Corresponds to DateTimeHelper.maxValue()
.@Nonnull public static final GregorianDate MinValue
GregorianDate
.
Corresponds to DateTimeHelper.minValue()
.public GregorianDate()
public GregorianDate(int year, int month, int day, int hour, int minute, double second)
GregorianDate
from the provided values.year
- The year.month
- The month of the year (in the range 1 through 12)day
- The day of the month (in the range 1 through the number of
days in month
)hour
- The hour (in the range 0 through 23).minute
- The minute (in the range 0 through 59).second
- The second, including fractional seconds (in the range 0.0
up to, but not including, 61.0). A second between 60.0 and 61.0 (a leap
second) is only valid if the overall time is during one of the official leap
seconds.ArgumentException
- Thrown when one of the provided parameters is outside its acceptable range.public GregorianDate(int year, int month, int day)
GregorianDate
from the provided values. The
remaining values are assumed to be zero.year
- The year.month
- The month of the year (in the range 1 through 12)day
- The day of the month (in the range 1 through the number of
days in month
)ArgumentException
- Thrown when one of the provided parameters is outside its acceptable range.public GregorianDate(int year, int dayOfYear, int hour, int minute, double second)
GregorianDate
from the provided values.year
- The year.dayOfYear
- The day of year
(in the range 1 through the number of days in the given year).hour
- The hour (in the range 0 through 23).minute
- The minute (in the range 0 through 59).second
- The second, including fractional seconds (in the range 0.0
up to, but not including, 61.0). A second between 60.0 and 61.0 (a leap
second) is only valid if the overall time is during one of the official leap
seconds.ArgumentException
- Thrown when one of the provided parameters is outside its acceptable range.public GregorianDate(int year, double daysOfYear)
GregorianDate
from the provided values. The
fractional portion of the daysOfYear
will be converted into
hours, minutes, and seconds.year
- The year.daysOfYear
- The day of year plus the fractional portion of the day
(in the range 1 through the number of days in the given year).public GregorianDate(@Nonnull JulianDate julianDate)
GregorianDate
from the provided
JulianDate
. The new GregorianDate
will be in the
CoordinatedUniversalTime
(get
) (UTC) time standard.julianDate
- The JulianDate
.public GregorianDate(@Nonnull JulianDate julianDate, TimeStandard timeStandard)
GregorianDate
from the provided
JulianDate
. The new GregorianDate
will be in the
provided TimeStandard
.julianDate
- The JulianDate
.timeStandard
- The TimeStandard
to represent the new GregorianDate
in.public GregorianDate(@Nonnull ZonedDateTime dateTime)
GregorianDate
from the provided
ZonedDateTime
. If the provided ZonedDateTime
is in local
time, it is converted to UTC.dateTime
- The ZonedDateTime
.public final int getYear()
public final int getMonth()
public final int getDay()
public final int getHour()
public final int getMinute()
public final double getSecond()
public final double getSecondsOfDay()
public final double getJulianSecondsOfDay()
@Nonnull public final DayOfWeek getDayOfWeek()
DayOfWeek
(get
) value that indicates the day
of the week. This property value ranges from zero, indicating Sunday, to six,
indicating Saturday.public final int getDayOfYear()
@Nonnull public static GregorianDate getNow()
GregorianDate
that represents the current date and time.public static boolean isValid(int year, int month, int day, int hour, int minute, double second)
year
- The year.month
- The month of the year (in the range 1 through 12)day
- The day of the month (in the range 1 through the number of
days in month
)hour
- The hour (in the range 0 through 23).minute
- The minute (in the range 0 through 59).second
- The second, including fractional seconds (in the range 0.0
up to, but not including, 61.0). A second between 60.0 and 61.0 (a leap
second) is only valid if the overall time is during one of the official leap
seconds.@Nonnull public final JulianDate toJulianDate()
GregorianDate
to a JulianDate
. The
time standard will be CoordinatedUniversalTime
(get
)
(UTC), unless this GregorianDate
represents the instant of a
leap second, in which case the JulianDate
will be in
InternationalAtomicTime
(get
) (TAI).JulianDate
representing this date.@Nonnull public final JulianDate toJulianDate(TimeStandard timeStandard)
GregorianDate
to a JulianDate
. The
GregorianDate
is assumed to specify a time in the
specified TimeStandard
.timeStandard
- The time standard in which this GregorianDate
is expressed. The returned
JulianDate
will be expressed in this time standard as well, if possible.JulianDate
representing this date.@Nonnull public final ZonedDateTime toDateTime()
ZonedDateTime
representing this date.@Nonnull public final GregorianDate roundSeconds(int digits)
CoordinatedUniversalTime
(get
)
(UTC) time standard so the Second
(get
) will be allowed to go above 60 during a leap second.digits
- The number of digits after the decimal point to include in the seconds.@Nonnull public final GregorianDate roundSeconds(int digits, TimeStandard timeStandard)
timeStandard
is CoordinatedUniversalTime
(get
),
(UTC), the seconds will be allowed to go above 60 during a leap second. For any other time standard, the
Second
(get
) will be below 60.digits
- The number of digits after the decimal point to include in the seconds.timeStandard
- The time standard in which this GregorianDate
is expressed.public final int compareTo(@Nonnull GregorianDate other)
compareTo
in interface Comparable<GregorianDate>
other
- An object to compare with this instance.Value | Meaning |
---|---|
Less than zero |
This instance is less than other .
|
Zero |
This instance is equal to other .
|
Greater than zero |
This instance is greater than other .
|
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean equals(Object obj)
equals
in class Object
obj
- The object to compare to this instance.true
if obj
is an instance of this type and represents the same value as this instance; otherwise false
.Object.hashCode()
,
HashMap
public final boolean equalsType(@Nonnull GregorianDate other)
equalsType
in interface IEquatable<GregorianDate>
other
- The instance to compare to this instance.true
if other
represents the same value as this instance; otherwise false
.public String toString()
@Nonnull public final String toString(@Nullable String format)
format
- A format string.format
.NumberFormatException
- Thrown if the length of format
is 1,
and it is not one of the format specifier characters defined for DateTimeFormatInfo
,
or if format
does not contain a valid custom format pattern.@Nonnull public final String toString(@Nullable Locale provider)
provider
- An Locale
that supplies culture-specific formatting information.provider
.@Nonnull public final String toString(@Nullable String format, @Nullable Locale provider)
format
- A format string.provider
- An Locale
that supplies culture-specific formatting information.format
and provider
.NumberFormatException
- Thrown if the length of format
is 1,
and it is not one of the format specifier characters defined for DateTimeFormatInfo
,
or if format
does not contain a valid custom format pattern.@Nonnull public final String toIso8601String()
@Nonnull public final String toIso8601String(@Nonnull Iso8601Format format)
format
- The type of ISO8601 string to create.@Nonnull public final String toIso8601String(@Nonnull Iso8601Format format, int digitsOfFractionalSeconds)
format
- The type of ISO8601 string to create.digitsOfFractionalSeconds
- The number of digits after the decimal point in the 'seconds' portion of the time.@Nonnull public final String toLongDateString()
@Nonnull public final String toLongTimeString()
@Nonnull public final String toShortDateString()
@Nonnull public final String toShortTimeString()
public static boolean equals(@Nonnull GregorianDate left, @Nonnull GregorianDate right)
true
if the two instances are exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
represents the same value as right
; otherwise false
.public static boolean notEquals(@Nonnull GregorianDate left, @Nonnull GregorianDate right)
true
if the two instances are not exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
does not represent the same value as right
; otherwise false
.public static boolean lessThan(@Nonnull GregorianDate left, @Nonnull GregorianDate right)
true
if left
is less than right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is less than right
; otherwise false
.public static boolean greaterThan(@Nonnull GregorianDate left, @Nonnull GregorianDate right)
true
if left
is greater than right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is greater than right
; otherwise false
.public static boolean lessThanOrEqual(@Nonnull GregorianDate left, @Nonnull GregorianDate right)
true
if left
is less than or equal to right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is less than or equal to right
; otherwise false
.public static boolean greaterThanOrEqual(@Nonnull GregorianDate left, @Nonnull GregorianDate right)
true
if left
is greater than or equal to right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is greater than or equal to right
; otherwise false
.@Nonnull public static GregorianDate parse(@Nonnull String s)
Converts the specified string representation of a date and time to its
GregorianDate
equivalent.
Note: GregorianDate
is always assumed to be in UTC. You cannot
parse strings containing time zone information. However, this will handle
three common ISO8601 formats:
s
- A string containing a date and time to convert.GregorianDate
equivalent to the date and time contained in s.ArgumentNullException
- Thrown if s
is null
.NumberFormatException
- Thrown if s
does not contain a valid string representation of a date and time.@Nonnull public static GregorianDate parse(@Nonnull String s, @Nullable Locale provider)
Converts the specified string representation of a date and time to its
GregorianDate
equivalent using the specified culture-specific
format information.
Note: GregorianDate
is always assumed to be in UTC. You cannot
parse strings containing time zone information. However, this will handle
three common ISO8601 formats:
s
- A string containing a date and time to convert.provider
- An Locale
that supplies culture-specific format information about s
.GregorianDate
equivalent to the date and time contained in
s
as specified by provider
.ArgumentNullException
- Thrown if s
is null
.NumberFormatException
- Thrown if s
does not contain a valid string representation of a date and time.@Nonnull public static GregorianDate parseExact(@Nonnull String s, @Nonnull String format, @Nullable Locale provider)
Converts the specified string representation of a date and time to its
GregorianDate
equivalent using the specified format and
culture-specific format information. The format of the string representation
must match the specified format exactly.
Note: GregorianDate
is always assumed to be in UTC. You cannot
parse strings containing time zone information.
s
- A string containing a date and time to convert.format
- The expected format of s
.provider
- An Locale
that supplies culture-specific format information about s
.GregorianDate
equivalent to the date and time contained in
s
as specified by format
and
provider
.ArgumentNullException
- Thrown if s
or format
is null
.NumberFormatException
- Thrown if s
or format
is an empty string,
or if s
does not contain a date and time that corresponds to the
pattern specified in format
.@Nonnull public static GregorianDate parseExact(@Nonnull String s, @Nonnull String[] format, @Nullable Locale provider)
Converts the specified string representation of a date and time to its
GregorianDate
equivalent using the specified format and
culture-specific format information. The format of the string representation
must match the specified format exactly.
Note: GregorianDate
is always assumed to be in UTC. You cannot
parse strings containing time zone information.
s
- A list of strings containing a date and time to convert.format
- The expected format of s
.provider
- An Locale
that supplies
culture-specific format information about s
.GregorianDate
equivalent to the date and time contained in
s
as specified by format
and
provider
.ArgumentNullException
- Thrown if s
or format
is null
.NumberFormatException
- Thrown if s
or format
is an empty string,
or if s
does not contain a date and time that corresponds to the
pattern specified in format
.public static boolean tryParse(String s, @Nonnull GregorianDate[] result)
Converts the specified string representation of a date and time to its
GregorianDate
equivalent.
Note: GregorianDate
is always assumed to be in UTC. You cannot
parse strings containing time zone information. However, this method handles
three common ISO8601 formats:
s
- A string containing a date and time to convert.result
- On input, an array with one element. On return, the array is populated with
the GregorianDate
value equivalent to the date and time contained in s
,
if the conversion succeeded, or GregorianDate.MinValue
if the conversion failed. The conversion
fails if the s
parameter is null
, or does not contain a
valid string representation of a date and time.true
if s
was parsed successfully; otherwise false
.public static boolean tryParse(String s, Locale provider, @Nonnull GregorianDate[] result)
Converts the specified string representation of a date and time to its
GregorianDate
equivalent using the specified culture-specific
format information.
Note: GregorianDate
is always assumed to be in UTC. You cannot
parse strings containing time zone information. However, this method handles
three common ISO8601 formats:
s
- A string containing a date and time to convert.provider
- An Locale
that supplies culture-specific format information about s
.result
- On input, an array with one element. On return, the array is populated with
the GregorianDate
value equivalent to the date and time contained in s
,
if the conversion succeeded, or GregorianDate.MinValue
if the conversion failed. The conversion
fails if the s
parameter is null
, or does not contain a
valid string representation of a date and time.true
if s
was parsed successfully; otherwise false
.@Nonnull public final GregorianDate addSeconds(double seconds)
seconds
- The number of seconds.@Nonnull public final GregorianDate subtractSeconds(double seconds)
seconds
- The number of seconds.@Nonnull public final GregorianDate addMinutes(double minutes)
minutes
- The number of minutes.@Nonnull public final GregorianDate subtractMinutes(double minutes)
minutes
- The number of minutes.@Nonnull public final GregorianDate addHours(double hours)
hours
- The number of hours.@Nonnull public final GregorianDate subtractHours(double hours)
hours
- The number of hours.@Nonnull public final GregorianDate addDays(double days)
days
- The number of days.@Nonnull public final GregorianDate subtractDays(double days)
days
- The number of days.