public class ASTDate
extends java.lang.Object
Methods provided include validating strings in the form mm/dd/yyyy where all fields are required and yyyy could be negative. The validate methods ensure that mm is in [1,12] and that the day is in an appropriate range for the mm including checking for leap years for Gregorian dates). Note that different languages have date-related routines, but they are not used here because (a) we need to allow dates to be negative and (b) implementing these routines rather than using a language's native date routines makes it easier to translate to a different programming language.
Copyright (c) 2018
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
DaysOfWeek
days of the week
|
Constructor and Description |
---|
ASTDate()
Constructor to create a date object.
|
Modifier and Type | Method and Description |
---|---|
static double |
dateToJD(ASTDate dateObj)
Converts a calendar date to a Julian day number.
|
static double |
dateToJD(int month,
double day,
int year)
Converts a calendar date to a Julian day number.
|
static java.lang.String |
dateToStr(ASTDate dateObj)
Convert a date to a string.
|
static java.lang.String |
dateToStr(int month,
double day,
int year)
Convert a date to a string.
|
static java.lang.String |
dateToStr(int month,
int day,
int year)
Convert a date to a string.
|
static int |
daysIntoYear(int iMonth,
int iDay,
int iYear)
Calculate how many days into a year a specific date is
|
static ASTDate |
daysIntoYear2Date(int iYear,
int N)
Calculate date when given the number of days into a year
|
static java.lang.String |
getCurrentDate()
Define a method for returning today's current date.
|
double |
getdDay()
Returns the day contained in the date object
|
int |
getiDay()
Returns the day contained in the date object
|
int |
getMonth()
Returns the month contained in the date object
|
int |
getYear()
Returns the year contained in the date object
|
static boolean |
isLeapYear(int year)
Checks to see if a year is a leap year.
|
static ASTDate |
isValidDate(java.lang.String inputStr)
Check a string to see if contains a valid Date.
|
static ASTDate |
isValidDate(java.lang.String inputStr,
boolean flag)
Check a string to see if contains a valid Date.
|
static ASTDate |
isValidDate(java.lang.String inputStr,
boolean flag,
boolean allowFrac)
Check a string to see if contains a valid Date.
|
boolean |
isValidDateObj()
Returns whether the object is a valid date
|
static ASTDate |
JDtoDate(double JD)
Convert a Julian day number to a calendar date.
|
void |
setdDay(double day)
Sets the double day in the date object
|
void |
setiDay(int day)
Sets the integer day in the date object
|
void |
setMonth(int month)
Sets the month in the date object.
|
void |
setYear(int year)
Sets the year in the date object
|
public ASTDate()
public boolean isValidDateObj()
public int getMonth()
public int getiDay()
public double getdDay()
public int getYear()
public void setMonth(int month)
month
- month for this objectpublic void setiDay(int day)
day
- day for this object (as an integer)public void setdDay(double day)
day
- day for this object (as a double)public void setYear(int year)
year
- year for this objectpublic static java.lang.String getCurrentDate()
public static ASTDate isValidDate(java.lang.String inputStr)
SimpleDateFormat
because
we want to allow for the possibility that yyyy could be negative. Note that range checking
is done to ensure that mm and dd are in the proper ranges. A check is also made to ensure
that dd = 29 only for leap years, but this only works for years in the Gregorian calendar
(i.e., years greater than 1581).inputStr
- string to be validatedpublic static ASTDate isValidDate(java.lang.String inputStr, boolean flag)
SimpleDateFormat
because
we want to allow for the possibility that yyyy could be negative. Note that range checking
is done to ensure that mm and dd are in the proper ranges. A check is also made to ensure
that dd = 29 only for leap years, but this only works for years in the Gregorian calendar
(i.e., years greater than 1581).inputStr
- string to be validatedflag
- whether to display error messagespublic static ASTDate isValidDate(java.lang.String inputStr, boolean flag, boolean allowFrac)
SimpleDateFormat
because
we want to allow for the possibility that yyyy could be negative. Note that range checking
is done to ensure that mm and dd are in the proper ranges. A check is also made to ensure
that dd = 29 only for leap years, but this only works for years in the Gregorian calendar
(i.e., years greater than 1581).inputStr
- string to be validatedflag
- whether to display error messagesallowFrac
- if true, allow fractional part of
a day to be in the input string
and allow day to be 0public static java.lang.String dateToStr(ASTDate dateObj)
dateObj
- date to be converted as an objectpublic static java.lang.String dateToStr(int month, double day, int year)
month
- month as an integerday
- day as a doubleyear
- year as an integerpublic static java.lang.String dateToStr(int month, int day, int year)
month
- month as an integerday
- day as an integeryear
- year as an integerpublic static double dateToJD(ASTDate dateObj)
dateObj
- date to be converted as an objectpublic static double dateToJD(int month, double day, int year)
month
- month to be convertedday
- day, including fractional part of
the day, to be convertedyear
- year to be convertedpublic static int daysIntoYear(int iMonth, int iDay, int iYear)
iMonth
- month for the date in questioniDay
- day for the date in questioniYear
- year for the date in questionpublic static ASTDate daysIntoYear2Date(int iYear, int N)
iYear
- year under considerationN
- number of days into iYearpublic static boolean isLeapYear(int year)
By definition, a leap year must be in the Gregorian calendar (i.e., greater than 1581). This method will return false if the year is not a leap year or if the year is less than 1582.
year
- year to checkpublic static ASTDate JDtoDate(double JD)
JD
- Julian day number to convert