public class ASTTime
extends java.lang.Object
The code allows for the possibility that h is negative as well as situations where the time is negative but the integer hours is 0 (e.g., -0:13:14.45). Time objects maintain the time in both HMS and decimal format so that either format can be readily obtained directly from the object.
Different programming languages have time-related routines, but they are not used here because (a) we need to allow time to be negative and (b) implementing the time-related routines needed makes it easier to translate to a different programming language.
Copyright (c) 2018
Constructor and Description |
---|
ASTTime()
Creates and initializes a new time object.
|
ASTTime(double decValue)
Creates and initializes a new time object.
|
Modifier and Type | Method and Description |
---|---|
static ASTDate |
adjustDatebyDays(ASTDate dateObj,
double days)
Adjust the date by some number of days
|
static ASTTime |
DecToHMS(double decValue)
Converts a decimal value into an ASTTime object
|
static java.lang.String |
getCurrentTime()
Define a method for returning the current time.
|
double |
getDecTime()
Gets the time as a decimal value
|
int |
getHours()
Gets the 'hours' portion of the time
|
int |
getMinutes()
Gets the 'minutes' portion of the time
|
double |
getSeconds()
Gets the 'seconds' portion of the time
|
static double |
GSTtoLST(double GST,
double dLongitude)
Convert GST to LST
|
static double |
GSTtoUT(double GST,
ASTDate dateObj)
Convert GST to UT
|
static double |
HMStoDec(boolean neg,
int h,
int m,
double s)
Convert HMS values to decimal
|
boolean |
isNegTime()
Returns whether the time is negative
|
static ASTTime |
isValidDecTime(java.lang.String inputStr)
Checks a string to see if it contains a valid decimal
format value.
|
static ASTTime |
isValidDecTime(java.lang.String inputStr,
boolean flag)
Checks a string to see if it contains a valid decimal
format value.
|
static ASTTime |
isValidHMSTime(java.lang.String inputStr)
Checks a string to see if contains a valid HMS value.
|
static ASTTime |
isValidHMSTime(java.lang.String inputStr,
boolean flag)
Checks a string to see if contains a valid HMS value.
|
static ASTTime |
isValidTime(java.lang.String inputStr)
Validate a string that may be in either HMS or decimal
format.
|
static ASTTime |
isValidTime(java.lang.String inputStr,
boolean flag)
Validate a string that may be in either HMS or decimal
format.
|
boolean |
isValidTimeObj()
Returns whether the object is a valid time
|
static double |
LCTtoUT(double LCT,
boolean DST,
ASTLatLon.TimeZoneType timeZone,
double lon,
ASTInt dateAdjustObj)
Convert LCT to UT
|
static double |
LSTtoGST(double LST,
double dLongitude)
Convert LST to GST
|
void |
setDecTime(double decValue)
Set the time object's value
|
static java.lang.String |
timeToStr(ASTTime timeObj,
boolean formatFlag)
Convert time to an HMS or decimal string format depending upon the formatFlag,
which can be HMSFORMAT or DECFORMAT.
|
static java.lang.String |
timeToStr(boolean neg,
int h,
int m,
double s,
boolean formatFlag)
Convert time to an HMS or decimal string format depending upon the formatFlag,
which can be HMSFORMAT or DECFORMAT.
|
static java.lang.String |
timeToStr(double decTime,
boolean formatFlag)
Convert time to an HMS or decimal string format depending upon the formatFlag,
which can be HMSFORMAT or DECFORMAT.
|
static double |
UTtoGST(double UT,
ASTDate dateObj)
Convert UT to GST
|
static double |
UTtoLCT(double UT,
boolean DST,
ASTLatLon.TimeZoneType timeZone,
double lon,
ASTInt dateAdjustObj)
Convert UT to LCT
|
public ASTTime()
Since much of the usage of this class involves validating that a string has a valid time, assume a new object is invalid until it is proven otherwise.
This method is overloaded to allow an initial value to be specified
public ASTTime(double decValue)
Since much of the usage of this class involves validating that a string has a valid time, assume a new object is invalid until it is proven otherwise.
This method is overloaded to allow an initial value to be specified
decValue
- initial value for the time objectpublic boolean isValidTimeObj()
public boolean isNegTime()
public double getDecTime()
public int getHours()
public int getMinutes()
public double getSeconds()
public void setDecTime(double decValue)
decValue
- decimal value to which object is to be setpublic static java.lang.String getCurrentTime()
public static ASTTime isValidDecTime(java.lang.String inputStr)
This method is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to validatepublic static ASTTime isValidDecTime(java.lang.String inputStr, boolean flag)
This method is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to validateflag
- whether to display error messagespublic static ASTTime isValidHMSTime(java.lang.String inputStr)
The custom code here is needed because we want to allow for the possibility that h could be negative, and to allow both minutes and seconds to be optional. Also note that to handle a situation where the time is negative but h is 0 (e.g., -0:13:15.45), the bNeg field is required.
This method is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to validatepublic static ASTTime isValidHMSTime(java.lang.String inputStr, boolean flag)
The custom code here is needed because we want to allow for the possibility that h could be negative, and to allow both minutes and seconds to be optional. Also note that to handle a situation where the time is negative but h is 0 (e.g., -0:13:15.45), the bNeg field is required.
This method is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to validateflag
- whether to display error messagespublic static ASTTime isValidTime(java.lang.String inputStr)
This method is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to be validatedpublic static ASTTime isValidTime(java.lang.String inputStr, boolean flag)
This method is overloaded to allow flag to be an optional parameter. The default is to display error messages.
inputStr
- string to be validatedflag
- whether to display error messagespublic static java.lang.String timeToStr(double decTime, boolean formatFlag)
decTime
- decimal value to convertformatFlag
- what format to returnpublic static java.lang.String timeToStr(ASTTime timeObj, boolean formatFlag)
timeObj
- time object to be convertedformatFlag
- what format to returnpublic static java.lang.String timeToStr(boolean neg, int h, int m, double s, boolean formatFlag)
neg
- true if the time is negativeh
- integer hoursm
- integer minutess
- decimal secondsformatFlag
- what format to returnpublic static ASTTime DecToHMS(double decValue)
decValue
- decimal value to be convertedpublic static double HMStoDec(boolean neg, int h, int m, double s)
neg
- true if the time is negativeh
- integer hours (always non-negative)m
- integer minutess
- decimal secondspublic static ASTDate adjustDatebyDays(ASTDate dateObj, double days)
dateObj
- original datedays
- number of days by which to adjust the datepublic static double GSTtoLST(double GST, double dLongitude)
GST
- GST time to convertdLongitude
- observer's longitudepublic static double GSTtoUT(double GST, ASTDate dateObj)
GST
- GST time to convertdateObj
- date for which UT is desiredpublic static double LCTtoUT(double LCT, boolean DST, ASTLatLon.TimeZoneType timeZone, double lon, ASTInt dateAdjustObj)
LCT
- time to convertDST
- true if on daylight saving timetimeZone
- observer's time zonelon
- observer's longitudedateAdjustObj
- amount by which to adjust datepublic static double LSTtoGST(double LST, double dLongitude)
LST
- LST time to convertdLongitude
- observer's longitudepublic static double UTtoGST(double UT, ASTDate dateObj)
UT
- UT time to convertdateObj
- date as an objectpublic static double UTtoLCT(double UT, boolean DST, ASTLatLon.TimeZoneType timeZone, double lon, ASTInt dateAdjustObj)
UT
- time to convertDST
- true if on daylight saving timetimeZone
- observer's time zonelon
- observer's longitudedateAdjustObj
- amount by which to adjust date