DateHelper.cs - MitchOSully/Visualising-the-DFN-Dataset GitHub Wiki
A helper script that manipulates date and time, mainly converting between Julian Day (JD) and Gregorian Date. Utilised by ScreenMaster
(extensively), BodyPlotter
(a little) and MeteoroidInfo
(a little).
Must be assigned to an empty GameObject in the scene, as well as every meteoroid in the scene.
void start()
string getDateErrorMessage(string[] dateElements)
double dateToJD(int[] dateElements)
int[] JDToDate(double JD)
string JDToDateString(double JD)
bool daysValid(int day, int month, int year)
int calcDaysInMonth(int month, int year)
bool isALeapYear(int year)
The JD of the start of the program (1/1/2000).
TO DO: change to startJD
.
The JD of the end of the program (31/12/2020).
TO DO: change to endJD
.
Initialises JD2000
and JD2020
.
None
None
Conducts the validation on a Gregorian date inputted by the user and returns a message describing the error. If return string == null
, then no error occured.
Name | Type | Description |
---|---|---|
dateElements |
string array |
A string array of length 3, storing the day, month and year of the Gregorian date. |
Name | Type | Description |
---|---|---|
errorMessage |
string |
The message describing the user's error. If no error is detected, then the string is set to null and returned. |
Converts a Gregorian date (represented by an array of integers) into a JD. Calculation used is from Astronomical Algorithms, 2nd Ed. by Jean Meeus (p61).
Name | Type | Description |
---|---|---|
dateElements |
int array |
The Gregorian date. Has the form {<day>, <month>, <year>}. |
Name | Type | Description |
---|---|---|
JD |
double |
The JD corresponding to the imported Gregorian date. |
None
Converts a JD to a Gregorian date (represented by an array of integers). Calculation used is from Astronomical Algorithms, 2nd Ed. by Jean Meeus (p63).
Name | Type | Description |
---|---|---|
JD |
double |
The Julian Day. |
Name | Type | Description |
---|---|---|
dateElements |
int array |
The Gregorian date corresponding to the imported JD. Has the form {<day>, <month>, <year>}. |
None
Uses JDToDate
to convert the imported JD into a Gregorian date. Then constructs a string that the Gregorian date can be read in.
Name | Type | Description |
---|---|---|
JD |
double |
The Julian Day. |
Name | Type | Description |
---|---|---|
dateString |
string |
The date string. Has the format <day>/<month>/<year>. <day> and <month> occupy two digits. |
Confirms that day
is within the proper boundaries of its month
and year
.
Name | Type | Description |
---|---|---|
day |
int |
The day of the month. Should be between 1 and 30/31/28/29. If not, we return false. |
month |
int |
The month. Takes values between 1 and 12. We need this to determine an upper limit for day . |
year |
int |
The year. We need this to check if it's a leap year for the specific case of February. |
Name | Type | Description |
---|---|---|
N/A | bool |
True if day is within its range, set by month and year . False if not. |
Determines the number of days in month
, considering the the possibility that year
may be a leap year.
Name | Type | Description |
---|---|---|
month |
int |
The month. Takes values between 1 and 12. |
year |
int |
The year. For checking leap year. |
Name | Type | Description |
---|---|---|
daysInMonth |
int |
The number of days in month . |
Returns true if year
is a leap year and false otherwise.
The conditions of a leap year (according to Gregorian Calendar) are: must be a multiple of 4, BUT not a multiple of 100, UNLESS it's a multiple of 400 (ref.).
Name | Type | Description |
---|---|---|
year |
int |
The year that we are checking. |
Name | Type | Description |
---|---|---|
verdict |
bool |
The verdict of whether year is a leap year or not. True if it is, false if it's not. |
None