DateHelper.cs - MitchOSully/Visualising-the-DFN-Dataset GitHub Wiki

Summary

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.

List of Functions

Public Global Variables

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)

Public Global Variables

double JD2000

The JD of the start of the program (1/1/2000).
TO DO: change to startJD.

double JD2020

The JD of the end of the program (31/12/2020).
TO DO: change to endJD.

void start()

Initialises JD2000 and JD2020.

Params

None

Returns

None

Calls

Called By

string getDateErrorMessage(string[] dateElements)

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.

Params

Name Type Description
dateElements string array A string array of length 3, storing the day, month and year of the Gregorian date.

Returns

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.

Calls

Called By

double dateToJD(int[] dateElements)

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).

Params

Name Type Description
dateElements int array The Gregorian date. Has the form {<day>, <month>, <year>}.

Returns

Name Type Description
JD double The JD corresponding to the imported Gregorian date.

Calls

None

Called By

int[] JDToDate(double JD)

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).

Params

Name Type Description
JD double The Julian Day.

Returns

Name Type Description
dateElements int array The Gregorian date corresponding to the imported JD. Has the form {<day>, <month>, <year>}.

Calls

None

Called By

string JDToDateString(double JD)

Uses JDToDate to convert the imported JD into a Gregorian date. Then constructs a string that the Gregorian date can be read in.

Params

Name Type Description
JD double The Julian Day.

Returns

Name Type Description
dateString string The date string. Has the format <day>/<month>/<year>. <day> and <month> occupy two digits.

Calls

Called By

bool daysValid(int day, int month, int year)

Confirms that day is within the proper boundaries of its month and year.

Params

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.

Returns

Name Type Description
N/A bool True if day is within its range, set by month and year. False if not.

Calls

Called By

int calcDaysInMonth(int month, int year)

Determines the number of days in month, considering the the possibility that year may be a leap year.

Params

Name Type Description
month int The month. Takes values between 1 and 12.
year int The year. For checking leap year.

Returns

Name Type Description
daysInMonth int The number of days in month.

Calls

Called By

bool isALeapYear(int year)

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.).

Params

Name Type Description
year int The year that we are checking.

Returns

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.

Calls

None

Called By

⚠️ **GitHub.com Fallback** ⚠️