public class DateComponents extends Object implements Serializable, Comparable<DateComponents>
This class uses the astronomical convention for calendars,
which is also the convention used by java.util.Date
:
a year zero is present between years -1 and +1, and 10 days are
missing in 1582. The calendar used around these special dates are:
Instances of this class are guaranteed to be immutable.
TimeComponents
,
DateTimeComponents
,
Serialized FormModifier and Type | Field and Description |
---|---|
static DateComponents |
BEIDOU_EPOCH
Reference epoch for BeiDou weeks: 2006-01-01.
|
static DateComponents |
CCSDS_EPOCH
Reference epoch for CCSDS Time Code Format (CCSDS 301.0-B-4): 1958-01-01.
|
static DateComponents |
FIFTIES_EPOCH
Reference epoch for 1950 dates: 1950-01-01.
|
static DateComponents |
GALILEO_EPOCH
Reference epoch for Galileo System Time: 1999-08-22.
|
static DateComponents |
GLONASS_EPOCH
Reference epoch for GLONASS four-year interval number: 1996-01-01.
|
static DateComponents |
GPS_EPOCH
Reference epoch for GPS weeks: 1980-01-06.
|
static DateComponents |
IRNSS_EPOCH
Reference epoch for IRNSS weeks: 1999-08-22.
|
static DateComponents |
J2000_EPOCH
J2000.0 Reference epoch: 2000-01-01.
|
static DateComponents |
JAVA_EPOCH
Java Reference epoch: 1970-01-01.
|
static DateComponents |
JULIAN_EPOCH
Reference epoch for julian dates: -4712-01-01.
|
static DateComponents |
MAX_EPOCH
Maximum supported date.
|
static DateComponents |
MIN_EPOCH
Maximum supported date.
|
static DateComponents |
MODIFIED_JULIAN_EPOCH
Reference epoch for modified julian dates: 1858-11-17.
|
static DateComponents |
QZSS_EPOCH
Reference epoch for QZSS weeks: 1980-01-06.
|
Constructor and Description |
---|
DateComponents(DateComponents epoch,
int offset)
Build a date from its offset with respect to a reference epoch.
|
DateComponents(int offset)
Build a date from its offset with respect to a
J2000_EPOCH . |
DateComponents(int year,
int dayNumber)
Build a date from a year and day number.
|
DateComponents(int year,
int month,
int day)
Build a date from its components.
|
DateComponents(int year,
Month month,
int day)
Build a date from its components.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(DateComponents other) |
static DateComponents |
createFromWeekComponents(int wYear,
int week,
int dayOfWeek)
Build a date from week components.
|
boolean |
equals(Object other) |
int |
getCalendarWeek()
Get the calendar week number.
|
int |
getDay()
Get the day.
|
int |
getDayOfWeek()
Get the day of week.
|
int |
getDayOfYear()
Get the day number in year.
|
int |
getJ2000Day()
Get the day number with respect to J2000 epoch.
|
int |
getMJD()
Get the modified julian day.
|
int |
getMonth()
Get the month.
|
Month |
getMonthEnum()
Get the month as an enumerate.
|
int |
getYear()
Get the year number.
|
int |
hashCode() |
static DateComponents |
parseDate(String string)
Parse a string in ISO-8601 format to build a date.
|
String |
toString()
Get a string representation (ISO-8601) of the date.
|
public static final DateComponents JULIAN_EPOCH
Both java.util.Date
and DateComponents
classes
follow the astronomical conventions and consider a year 0 between
years -1 and +1, hence this reference date lies in year -4712 and not
in year -4713 as can be seen in other documents or programs that obey
a different convention (for example the convcal
utility).
public static final DateComponents MODIFIED_JULIAN_EPOCH
public static final DateComponents FIFTIES_EPOCH
public static final DateComponents CCSDS_EPOCH
public static final DateComponents GALILEO_EPOCH
public static final DateComponents GPS_EPOCH
public static final DateComponents QZSS_EPOCH
public static final DateComponents IRNSS_EPOCH
public static final DateComponents BEIDOU_EPOCH
public static final DateComponents GLONASS_EPOCH
public static final DateComponents J2000_EPOCH
public static final DateComponents JAVA_EPOCH
public static final DateComponents MAX_EPOCH
This is date 5881610-07-11 which corresponds to Integer.MAX_VALUE
days after J2000_EPOCH
.
public static final DateComponents MIN_EPOCH
This is date -5877490-03-03, which corresponds to Integer.MIN_VALUE
days before J2000_EPOCH
.
public DateComponents(int year, int month, int day) throws IllegalArgumentException
year
- year number (may be 0 or negative for BC years)month
- month number from 1 to 12day
- day number from 1 to 31IllegalArgumentException
- if inconsistent arguments
are given (parameters out of range, february 29 for non-leap years,
dates during the gregorian leap in 1582 ...)public DateComponents(int year, Month month, int day) throws IllegalArgumentException
year
- year number (may be 0 or negative for BC years)month
- month enumerateday
- day number from 1 to 31IllegalArgumentException
- if inconsistent arguments
are given (parameters out of range, february 29 for non-leap years,
dates during the gregorian leap in 1582 ...)public DateComponents(int year, int dayNumber) throws IllegalArgumentException
year
- year number (may be 0 or negative for BC years)dayNumber
- day number in the year from 1 to 366IllegalArgumentException
- if dayNumber is out of range
with respect to yearpublic DateComponents(int offset)
J2000_EPOCH
.offset
- offset with respect to a J2000_EPOCH
getJ2000Day()
public DateComponents(DateComponents epoch, int offset)
This constructor is mainly useful to build a date from a modified
julian day (using MODIFIED_JULIAN_EPOCH
) or a GPS week number
(using GPS_EPOCH
).
epoch
- reference epochoffset
- offset with respect to a reference epochDateComponents(int)
,
getMJD()
public static DateComponents createFromWeekComponents(int wYear, int week, int dayOfWeek) throws IllegalArgumentException
The calendar week number is a number between 1 and 52 or 53 depending on the year. Week 1 is defined by ISO as the one that includes the first Thursday of a year. Week 1 may therefore start the previous year and week 52 or 53 may end in the next year. As an example calendar date 1995-01-01 corresponds to week date 1994-W52-7 (i.e. Sunday in the last week of 1994 is in fact the first day of year 1995). This date would beAnother example is calendar date 1996-12-31 which corresponds to week date 1997-W01-2 (i.e. Tuesday in the first week of 1997 is in fact the last day of year 1996).
wYear
- year associated to week numberingweek
- week number in year, from 1 to 52 or 53dayOfWeek
- day of week, from 1 (Monday) to 7 (Sunday)IllegalArgumentException
- if inconsistent arguments
are given (parameters out of range, week 53 on a 52 weeks year ...)public static DateComponents parseDate(String string)
The supported formats are:
As shown by the list above, only the complete representations defined in section 4.1 of ISO-8601 standard are supported, neither expended representations nor representations with reduced accuracy are supported.
Parsing a single integer as a julian day is not supported as it may be ambiguous with either the basic format calendar date or the basic format ordinal date depending on the number of digits.
string
- string to parseIllegalArgumentException
- if string cannot be parsedpublic int getYear()
public int getMonth()
public Month getMonthEnum()
public int getDay()
public int getJ2000Day()
public int getMJD()
public int getCalendarWeek()
The calendar week number is a number between 1 and 52 or 53 depending on the year. Week 1 is defined by ISO as the one that includes the first Thursday of a year. Week 1 may therefore start the previous year and week 52 or 53 may end in the next year. As an example calendar date 1995-01-01 corresponds to week date 1994-W52-7 (i.e. Sunday in the last week of 1994 is in fact the first day of year 1995). Another example is calendar date 1996-12-31 which corresponds to week date 1997-W01-2 (i.e. Tuesday in the first week of 1997 is in fact the last day of year 1996).
public int getDayOfWeek()
Day of week is a number between 1 (Monday) and 7 (Sunday).
public int getDayOfYear()
Day number in year is between 1 (January 1st) and either 365 or 366 inclusive depending on year.
public String toString()
public int compareTo(DateComponents other)
compareTo
in interface Comparable<DateComponents>
Copyright © 2002-2020 CS GROUP. All rights reserved.