Class GregorianMath
Contains some calendrical tools for the rules of gregorian calendar.
- Author:
- Meno Hochschild
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkDate(int year, int month, int dayOfMonth)
Checks the range limits of date values according to the rules of gregorian calendar.static int
getDayOfWeek(int year, int month, int dayOfMonth)
Returns the day of week for given gregorian date.static int
getLengthOfMonth(int year, int month)
Determines the maximum length of month in days dependent on given year (leap years!)static boolean
isLeapYear(int year)
Queries if given year is a gregorian leap year.static boolean
isValid(int year, int month, int dayOfMonth)
Queries if given values form a well defined gregorian date.static int
readDayOfMonth(long packedDate)
Returns the day of month from given binary compressed date.static int
readMonth(long packedDate)
Returns the month from given binary compressed date.static int
readYear(long packedDate)
Returns the year from given binary compressed date.static long
toMJD(int year, int month, int dayOfMonth)
Calculates the modified Julian date.static long
toMJD(GregorianDate date)
Calculates the modified Julian date.static long
toPackedDate(long mjd)
Calculates the gregorian Date based on given modified julian date in binary compressed format.
-
Field Details
-
MIN_YEAR
public static final int MIN_YEARMinimum of supported year range (-999999999).- See Also:
- Constant Field Values
-
MAX_YEAR
public static final int MAX_YEARMaximum of supported year range (999999999).- See Also:
- Constant Field Values
-
-
Method Details
-
isLeapYear
public static boolean isLeapYear(int year)Queries if given year is a gregorian leap year.
- Parameters:
year
- number of proleptic year- Returns:
true
if it is a leap year elsefalse
-
getLengthOfMonth
public static int getLengthOfMonth(int year, int month)Determines the maximum length of month in days dependent on given year (leap years!) and month.
- Parameters:
year
- proleptic iso yearmonth
- gregorian month (1-12)- Returns:
- length of month in days
- Throws:
IllegalArgumentException
- if month is out of range (1-12)
-
isValid
public static boolean isValid(int year, int month, int dayOfMonth)Queries if given values form a well defined gregorian date.
This method only checks the range limits, not if the date is historically correct.
- Parameters:
year
- proleptic iso year [(-999999999) - 999999999]month
- gregorian month (1-12)dayOfMonth
- day of month (1-31)- Returns:
true
if valid elsefalse
- See Also:
checkDate(int, int, int)
-
checkDate
public static void checkDate(int year, int month, int dayOfMonth)Checks the range limits of date values according to the rules of gregorian calendar.
- Parameters:
year
- proleptic iso year [(-999999999) - 999999999]month
- gregorian month (1-12)dayOfMonth
- day of month (1-31)- Throws:
IllegalArgumentException
- if any argument is out of range- See Also:
isValid(int, int, int)
-
getDayOfWeek
public static int getDayOfWeek(int year, int month, int dayOfMonth)Returns the day of week for given gregorian date.
This method is based on ISO-8601 and assumes that Monday is the first day of week.
- Parameters:
year
- proleptic iso yearmonth
- gregorian month (1-12)dayOfMonth
- day of month (1-31)- Returns:
- day of week (monday = 1, ..., sunday = 7)
- Throws:
IllegalArgumentException
- if the month or the day are out of range
-
readYear
public static int readYear(long packedDate)Returns the year from given binary compressed date.
- Parameters:
packedDate
- packed date in binary format- Returns:
- proleptic iso year
- See Also:
toPackedDate(long)
-
readMonth
public static int readMonth(long packedDate)Returns the month from given binary compressed date.
- Parameters:
packedDate
- packed date in binary format- Returns:
- gregorian month (1-12)
- See Also:
toPackedDate(long)
-
readDayOfMonth
public static int readDayOfMonth(long packedDate)Returns the day of month from given binary compressed date.
- Parameters:
packedDate
- packed date in binary format- Returns:
- day of month (1-31)
- See Also:
toPackedDate(long)
-
toPackedDate
public static long toPackedDate(long mjd)Calculates the gregorian Date based on given modified julian date in binary compressed format.
Applications can extract the single date components from the result of this method by mean of
readYear()
,readMonth()
andreadDayOfMonth()
.- Parameters:
mjd
- days since [1858-11-17] (modified Julian date)- Returns:
- packed date in binary format
- Throws:
IllegalArgumentException
- if the calculated year is not in range [(-999999999)-999999999)]- See Also:
readYear(long)
,readMonth(long)
,readDayOfMonth(long)
-
toMJD
Calculates the modified Julian date.
- Parameters:
date
- gregorian date- Returns:
- days since [1858-11-17] (modified Julian date)
- Throws:
IllegalArgumentException
- if the argument is out of range- See Also:
toMJD(int, int, int)
-
toMJD
public static long toMJD(int year, int month, int dayOfMonth)Calculates the modified Julian date.
- Parameters:
year
- proleptic iso year [(-999999999) - 999999999]month
- gregorian month (1-12)dayOfMonth
- day of month in range (1-31)- Returns:
- days since [1858-11-17] (modified Julian date)
- Throws:
IllegalArgumentException
- if any argument is out of range
-