@Status(stage=PRODUCTION, unitTests=COMPLETE) @Review(by="Kees Schotanus", at="2009-09-28") public final class CDate extends Object
GregorianCalendar. Dates on or after 1582/10/15
are supposed to be Gregorian and dates up to and including 1582/10/4 are
supposed to be Julian.| Modifier and Type | Field and Description |
|---|---|
static int |
CENTURY
A century is not a leap year in the Gregorian Calendar.
|
static int |
DAYS_IN_A_YEAR
Number of days in a (non leap) year.
|
static int |
FOUR_CENTURIES
Every fourth century is a leap year in the Gregorian Calendar.
|
static int |
FOUR_YEARS
Every fourth year is a leap year.
|
static int |
MAXIMUM_AGE_OF_A_PERSON
The maximum age a person could possibly reach.
|
static int |
MAXIMUM_YEAR
The last year for which this CDate will give valid results.
|
static int |
MINIMUM_YEAR
The first year for which this CDate will give valid results.
|
| Modifier and Type | Method and Description |
|---|---|
static Date |
addDays(Calendar calendar,
int numberOfDays)
Adds the supplied numberOfDays to the supplied calendar.
|
static Date |
addDays(Date date,
int numberOfDays)
Adds the supplied numberOfDays to the supplied date.
|
static GregorianCalendar |
asGregorianCalendar(Date date)
Gets a GregorianCalendar from the supplied date.
|
static void |
clearTimeInfo(Calendar calendar)
Clears time information from the supplied calendar.
|
static void |
clearTimeInfo(Date date)
Clears time information from the supplied date.
|
static GregorianCalendar |
computeEasterSunday(int year)
For the supplied (Gregorian) year, this method calculates the date of
Easter Sunday.
|
static int |
getCurrentYear()
Gets the current year.
|
static int |
getDayOfYear(int year,
int month,
int day)
Computes the ordinal day number within a year, for the supplied Gregorian
date (in the form of a year, month and day).
|
static int |
getDifferenceInDays(Calendar startCalendar,
Calendar endCalendar)
Computes the difference in days between the supplied calendars.
|
static int |
getDifferenceInDays(Date startDate,
Date endDate)
Computes the difference in days between the supplied dates.
|
static int |
getDifferenceInMonths(Calendar startCalendar,
Calendar endCalendar)
Computes the difference in whole months between the supplied calendars.
|
static int |
getDifferenceInMonths(Date startDate,
Date endDate)
Computes the difference in whole months between the supplied dates.
|
static int |
getDifferenceInYears(Calendar startCalendar,
Calendar endCalendar)
Computes the difference in whole years between the supplied calendars.
|
static int |
getDifferenceInYears(Date startDate,
Date endDate)
Computes the difference in whole years between the supplied dates.
|
static int |
getDurationInYears(Calendar startCalendar,
Calendar endCalendar)
Computes the duration in whole years between the supplied calendars.
|
static int |
getDurationInYears(Date startDate,
Date endDate)
Computes the duration in whole years between the supplied dates.
|
static int |
getMaximumDayOfMonth(int year,
int month)
Calculates the maximum ordinal day number for the supplied month.
|
static int |
getMaximumDayOfYear(int year)
Gets the maximum number of days in the supplied year.
|
static int |
getMinumumYearOfBirth()
Gets the minimum year in which a living person may be born.
|
static Date |
getTime()
Gets the current system time.
|
static Date |
getToday()
Gets the current date, without time information.
|
static boolean |
isLeapYear(int year)
Determines whether the supplied year is a leap year or not.
|
static void |
validate(int year,
int month,
int day)
Validates that the supplied date is an existing day.
|
static void |
validateMonth(int month)
Validates the supplied month.
|
static void |
validateYear(int year)
Validates the supplied year.
|
public static final int MINIMUM_YEAR
public static final int MAXIMUM_YEAR
public static final int DAYS_IN_A_YEAR
public static final int MAXIMUM_AGE_OF_A_PERSON
public static final int FOUR_YEARS
public static final int CENTURY
public static final int FOUR_CENTURIES
public static void validate(int year,
int month,
int day)
year - Year number where: MINIMUM_YEAR
<= year <= MAXIMUM_YEAR, with the exception of 0
since after 1 BC comes 1 AD.
month - Ordinal month number where:
1 <= month <= 12.day - Ordinal day number where:
1 <= day <= max day for month.IllegalArgumentException - When one of the input parameters is out
of range.public static void validateYear(int year)
MINIMUM_YEAR <= year <= MAXIMUM_YEAR with
the exception of 0 since after 1 BC comes 1 AD.year - The year to validate.IllegalArgumentException - When the supplied year is 0 or not in
range.public static void validateMonth(int month)
month - The month to validate.IllegalArgumentException - When the supplied month is not in range.public static int getDayOfYear(int year,
int month,
int day)
year - Gregorian year.
month - Ordinal month number.
1 <= month <= 12day - Ordinal day number.
1 <= day <= maximumDayForSuppliedMonthIllegalArgumentException - When one of the input parameters is out
of range.public static int getMaximumDayOfMonth(int year,
int month)
year - The year.
isLeapYear(int). A year before the Gregorian cutover is
supposed to be a year from the Julian Calendar.month - Ordinal month number where: 1 <= month <= 12.IllegalArgumentException - When the supplied month is out of range.public static int getMaximumDayOfYear(int year)
year - The year to get the maximum number of days of.IllegalArgumentException - When the supplied year is out of range.public static boolean isLeapYear(int year)
year - Year to check.public static int getDifferenceInDays(Date startDate, Date endDate)
startDate - Start date.endDate - End date.NullPointerException - When either the supplied startDate or
endDate is null.public static int getDifferenceInDays(Calendar startCalendar, Calendar endCalendar)
startCalendar - Start date.endCalendar - End date.NullPointerException - When either the supplied startCalendar or
endCalendar is null.public static int getDifferenceInMonths(Date startDate, Date endDate)
startDate - Start date.endDate - End date.NullPointerException - When either the supplied startDate or
endDate is null.public static int getDifferenceInMonths(Calendar startCalendar, Calendar endCalendar)
startCalendar - The start date.endCalendar - The end date.NullPointerException - When either the supplied startCalendar or
endCalendar is null.public static int getDifferenceInYears(Date startDate, Date endDate)
startDate - Start date.endDate - End date.NullPointerException - When either the supplied startDate or
endDate is null.public static int getDifferenceInYears(Calendar startCalendar, Calendar endCalendar)
startCalendar - Start date.endCalendar - End date.NullPointerException - When either the supplied startCalendar or
endCalendar is null.public static int getDurationInYears(Date startDate, Date endDate)
startDate - Start date.endDate - End date.NullPointerException - When either the supplied startDate or
endDate is null.public static int getDurationInYears(Calendar startCalendar, Calendar endCalendar)
startCalendar - Start date.endCalendar - End date.NullPointerException - When either the supplied startCalendar or
endCalendar is null.public static Date addDays(Date date, int numberOfDays)
date - The start date.numberOfDays - The number of days to add to the supplied date.
NullPointerException - When the supplied date is null.public static Date addDays(Calendar calendar, int numberOfDays)
calendar - The start date.numberOfDays - The number of days to add to the supplied calendar.
NullPointerException - When the supplied calendar is null.public static GregorianCalendar computeEasterSunday(int year)
year - The Gregorian year.IllegalArgumentException - When the supplied year is before 1582.public static void clearTimeInfo(Calendar calendar)
calendar - The calendar for which the time info must be cleared.NullPointerException - When the supplied calendar is null.public static void clearTimeInfo(Date date)
clearTimeInfo(Calendar)
date - The date for which the time info must be cleared.NullPointerException - When the supplied date is null.public static int getCurrentYear()
public static Date getToday()
public static Date getTime()
public static int getMinumumYearOfBirth()
MAXIMUM_AGE_OF_A_PERSON.public static GregorianCalendar asGregorianCalendar(Date date)
date - The date to convert to a GregorianCalendar.NullPointerException - When the supplied date is null.Copyright © 2008–2017. All rights reserved.