Class DateComponents
- All Implemented Interfaces:
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:
- up to 0000-12-31 : proleptic julian calendar
- from 0001-01-01 to 1582-10-04: julian calendar
- from 1582-10-15: gregorian calendar
Instances of this class are guaranteed to be immutable.
- Author:
- Luc Maisonobe
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateComponentsReference epoch for BeiDou weeks: 2006-01-01.static final DateComponentsReference epoch for CCSDS Time Code Format (CCSDS 301.0-B-4): 1958-01-01.static final DateComponentsReference epoch for 1950 dates: 1950-01-01.static final DateComponentsReference epoch for Galileo System Time: 1999-08-22.static final DateComponentsReference epoch for GLONASS four-year interval number: 1996-01-01.static final DateComponentsReference epoch for GPS weeks: 1980-01-06.static final DateComponentsJ2000.0 Reference epoch: 2000-01-01.static final DateComponentsJava Reference epoch: 1970-01-01.static final doubleOffset between julian day epoch and modified julian day epoch.static final DateComponentsReference epoch for julian dates: -4712-01-01.static final DateComponentsMaximum supported date.static final DateComponentsMaximum supported date.static final DateComponentsReference epoch for modified julian dates: 1858-11-17.static final DateComponentsReference epoch for NavIC weeks: 1999-08-22.static final DateComponentsReference epoch for QZSS weeks: 1980-01-06. -
Constructor Summary
ConstructorsConstructorDescriptionDateComponents(int offset) Build a date from its offset with respect to aJ2000_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.DateComponents(DateComponents epoch, int offset) Build a date from its offset with respect to a reference epoch. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(DateComponents other) static DateComponentscreateFromWeekComponents(int wYear, int week, int dayOfWeek) Build a date from week components.booleanintGet the calendar week number.intgetDay()Get the day.intGet the day of week.intGet the day number in year.intGet the day number with respect to J2000 epoch.intgetMJD()Get the modified julian day.intgetMonth()Get the month.Get the month as an enumerate.intgetYear()Get the year number.inthashCode()static DateComponentsParse a string in ISO-8601 format to build a date.toString()Get a string representation (ISO-8601) of the date.
-
Field Details
-
JULIAN_EPOCH
Reference epoch for julian dates: -4712-01-01.Both
java.util.DateandDateComponentsclasses 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 theconvcalutility). -
MODIFIED_JULIAN_EPOCH
Reference epoch for modified julian dates: 1858-11-17. -
FIFTIES_EPOCH
Reference epoch for 1950 dates: 1950-01-01. -
CCSDS_EPOCH
Reference epoch for CCSDS Time Code Format (CCSDS 301.0-B-4): 1958-01-01. -
GALILEO_EPOCH
Reference epoch for Galileo System Time: 1999-08-22. -
GPS_EPOCH
Reference epoch for GPS weeks: 1980-01-06. -
QZSS_EPOCH
Reference epoch for QZSS weeks: 1980-01-06. -
NAVIC_EPOCH
Reference epoch for NavIC weeks: 1999-08-22. -
BEIDOU_EPOCH
Reference epoch for BeiDou weeks: 2006-01-01. -
GLONASS_EPOCH
Reference epoch for GLONASS four-year interval number: 1996-01-01. -
J2000_EPOCH
J2000.0 Reference epoch: 2000-01-01. -
JAVA_EPOCH
Java Reference epoch: 1970-01-01. -
MAX_EPOCH
Maximum supported date.This is date 5881610-07-11 which corresponds to
Integer.MAX_VALUEdays afterJ2000_EPOCH.- Since:
- 9.0
-
MIN_EPOCH
Maximum supported date.This is date -5877490-03-03, which corresponds to
Integer.MIN_VALUEdays beforeJ2000_EPOCH.- Since:
- 9.0
-
JD_TO_MJD
public static final double JD_TO_MJDOffset between julian day epoch and modified julian day epoch.- See Also:
-
-
Constructor Details
-
DateComponents
Build a date from its components.- Parameters:
year- year number (may be 0 or negative for BC years)month- month number from 1 to 12day- day number from 1 to 31- Throws:
IllegalArgumentException- if inconsistent arguments are given (parameters out of range, february 29 for non-leap years, dates during the gregorian leap in 1582 ...)
-
DateComponents
Build a date from its components.- Parameters:
year- year number (may be 0 or negative for BC years)month- month enumerateday- day number from 1 to 31- Throws:
IllegalArgumentException- if inconsistent arguments are given (parameters out of range, february 29 for non-leap years, dates during the gregorian leap in 1582 ...)
-
DateComponents
Build a date from a year and day number.- Parameters:
year- year number (may be 0 or negative for BC years)dayNumber- day number in the year from 1 to 366- Throws:
IllegalArgumentException- if dayNumber is out of range with respect to year
-
DateComponents
public DateComponents(int offset) Build a date from its offset with respect to aJ2000_EPOCH.- Parameters:
offset- offset with respect to aJ2000_EPOCH- See Also:
-
DateComponents
Build a date from its offset with respect to a reference epoch.This constructor is mainly useful to build a date from a modified julian day (using
MODIFIED_JULIAN_EPOCH) or a GPS week number (usingGPS_EPOCH).- Parameters:
epoch- reference epochoffset- offset with respect to a reference epoch- See Also:
-
-
Method Details
-
createFromWeekComponents
public static DateComponents createFromWeekComponents(int wYear, int week, int dayOfWeek) throws IllegalArgumentException Build a date from week components.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).
- Parameters:
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)- Returns:
- a builded date
- Throws:
IllegalArgumentException- if inconsistent arguments are given (parameters out of range, week 53 on a 52 weeks year ...)
-
parseDate
Parse a string in ISO-8601 format to build a date.The supported formats are:
- basic format calendar date: YYYYMMDD
- extended format calendar date: YYYY-MM-DD
- basic format ordinal date: YYYYDDD
- extended format ordinal date: YYYY-DDD
- basic format week date: YYYYWwwD
- extended format week date: YYYY-Www-D
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.
- Parameters:
string- string to parse- Returns:
- a parsed date
- Throws:
IllegalArgumentException- if string cannot be parsed
-
getYear
public int getYear()Get the year number.- Returns:
- year number (may be 0 or negative for BC years)
-
getMonth
public int getMonth()Get the month.- Returns:
- month number from 1 to 12
-
getMonthEnum
Get the month as an enumerate.- Returns:
- month as an enumerate
-
getDay
public int getDay()Get the day.- Returns:
- day number from 1 to 31
-
getJ2000Day
public int getJ2000Day()Get the day number with respect to J2000 epoch.- Returns:
- day number with respect to J2000 epoch
-
getMJD
public int getMJD()Get the modified julian day.- Returns:
- modified julian day
-
getCalendarWeek
public int getCalendarWeek()Get the calendar week number.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).
- Returns:
- calendar week number
-
getDayOfWeek
public int getDayOfWeek()Get the day of week.Day of week is a number between 1 (Monday) and 7 (Sunday).
- Returns:
- day of week
-
getDayOfYear
public int getDayOfYear()Get the day number in year.Day number in year is between 1 (January 1st) and either 365 or 366 inclusive depending on year.
- Returns:
- day number in year
-
toString
Get a string representation (ISO-8601) of the date. -
compareTo
- Specified by:
compareToin interfaceComparable<DateComponents>
-
equals
-
hashCode
public int hashCode()
-