public class TimeComponents extends Object implements Serializable, Comparable<TimeComponents>
Instances of this class are guaranteed to be immutable.
DateComponents
,
DateTimeComponents
,
Serialized FormModifier and Type | Field and Description |
---|---|
static TimeComponents |
H00
Constant for commonly used hour 00:00:00.
|
static TimeComponents |
H12
Constant for commonly used hour 12:00:00.
|
Constructor and Description |
---|
TimeComponents(double secondInDay)
Build a time from the second number within the day.
|
TimeComponents(int secondInDayA,
double secondInDayB)
Build a time from the second number within the day.
|
TimeComponents(int hour,
int minute,
double second)
Build a time from its clock elements.
|
TimeComponents(int hour,
int minute,
double second,
int minutesFromUTC)
Build a time from its clock elements.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(TimeComponents other) |
boolean |
equals(Object other) |
String |
formatUtcOffset()
Get the UTC offset as a string in ISO8601 format.
|
static TimeComponents |
fromSeconds(int secondInDayA,
double secondInDayB,
double leap,
int minuteDuration)
Build a time from the second number within the day.
|
int |
getHour()
Get the hour number.
|
int |
getMinute()
Get the minute number.
|
int |
getMinutesFromUTC()
Get the offset between the specified date and UTC.
|
double |
getSecond()
Get the seconds number.
|
double |
getSecondsInLocalDay()
Get the second number within the local day, without applying the
offset from UTC . |
double |
getSecondsInUTCDay()
Get the second number within the UTC day, applying the
offset from UTC . |
int |
hashCode() |
static TimeComponents |
parseTime(String string)
Parse a string in ISO-8601 format to build a time.
|
String |
toString()
Get a string representation of the time including the offset from UTC.
|
String |
toStringWithoutUtcOffset()
Get a string representation of the time without the offset from UTC.
|
public static final TimeComponents H00
public static final TimeComponents H12
public TimeComponents(int hour, int minute, double second) throws IllegalArgumentException
Note that seconds between 60.0 (inclusive) and 61.0 (exclusive) are allowed
in this method, since they do occur during leap seconds introduction
in the UTC
time scale.
hour
- hour number from 0 to 23minute
- minute number from 0 to 59second
- second number from 0.0 to 61.0 (excluded)IllegalArgumentException
- if inconsistent arguments
are given (parameters out of range)public TimeComponents(int hour, int minute, double second, int minutesFromUTC) throws IllegalArgumentException
Note that seconds between 60.0 (inclusive) and 61.0 (exclusive) are allowed
in this method, since they do occur during leap seconds introduction
in the UTC
time scale.
hour
- hour number from 0 to 23minute
- minute number from 0 to 59second
- second number from 0.0 to 61.0 (excluded)minutesFromUTC
- offset between the specified date and UTC, as an
integral number of minutes, as per ISO-8601 standardIllegalArgumentException
- if inconsistent arguments
are given (parameters out of range)public TimeComponents(double secondInDay) throws OrekitIllegalArgumentException
If the secondInDay
is less than 60.0
then getSecond()
will be less than 60.0
, otherwise it will be less than 61.0
. This constructor
may produce an invalid value of getSecond()
during a negative leap second,
through there has never been one. For more control over the number of seconds in
the final minute use fromSeconds(int, double, double, int)
.
This constructor is always in UTC (i.e. will return
0
).
secondInDay
- second number from 0.0 to Constants.JULIAN_DAY
+
1
(excluded)OrekitIllegalArgumentException
- if seconds number is out of rangefromSeconds(int, double, double, int)
,
TimeComponents(int, double)
public TimeComponents(int secondInDayA, double secondInDayB) throws OrekitIllegalArgumentException
The second number is defined here as the sum
secondInDayA + secondInDayB
from 0.0 to Constants.JULIAN_DAY
+ 1
(excluded). The two parameters are used for increased accuracy.
If the sum is less than 60.0
then getSecond()
will be less
than 60.0
, otherwise it will be less than 61.0
. This constructor
may produce an invalid value of getSecond()
during a negative leap second,
through there has never been one. For more control over the number of seconds in
the final minute use fromSeconds(int, double, double, int)
.
This constructor is always in UTC (i.e. getMinutesFromUTC()
will
return 0).
secondInDayA
- first part of the second numbersecondInDayB
- last part of the second numberOrekitIllegalArgumentException
- if seconds number is out of rangefromSeconds(int, double, double, int)
public static TimeComponents fromSeconds(int secondInDayA, double secondInDayB, double leap, int minuteDuration)
The seconds past midnight is the sum secondInDayA + secondInDayB +
leap
. The two parameters are used for increased accuracy. Only the first part of
the sum (secondInDayA + secondInDayB
) is used to compute the hours and
minutes. The third parameter (leap
) is added directly to the second value
(getSecond()
) to implement leap seconds. These three quantities must
satisfy the following constraints. This first guarantees the hour and minute are
valid, the second guarantees the second is valid.
0 <= secondInDayA + secondInDayB < 86400
0 <= (secondInDayA + secondInDayB) % 60 + leap <= minuteDuration
0 <= leap <= minuteDuration - 60 if minuteDuration >= 60
0 >= leap >= minuteDuration - 60 if minuteDuration < 60
If the seconds of minute (getSecond()
) computed from secondInDayA + secondInDayB + leap
is greater than or equal to 60 + leap
then the second of minute will be set to FastMath.nextDown(60 + leap)
. This
prevents rounding to an invalid seconds of minute number when the input values have
greater precision than a double
.
This constructor is always in UTC (i.e. will return
0
).
If secondsInDayB
or leap
is NaN then the hour and minute will
be determined from secondInDayA
and the second of minute will be NaN.
secondInDayA
- first part of the second number.secondInDayB
- last part of the second number.leap
- magnitude of the leap second if this point in time is during
a leap second, otherwise 0.0
. This value is not used
to compute hours and minutes, but it is added to the computed
second of minute.minuteDuration
- number of seconds in the current minute, normally 60
.OrekitIllegalArgumentException
- if the inequalities above do not hold.public static TimeComponents parseTime(String string)
The supported formats are:
As shown by the list above, only the complete representations defined in section 4.2 of ISO-8601 standard are supported, neither expended representations nor representations with reduced accuracy are supported.
string
- string to parseIllegalArgumentException
- if string cannot be parsedpublic int getHour()
public int getMinute()
public double getSecond()
public int getMinutesFromUTC()
The offset is always an integral number of minutes, as per ISO-8601 standard.
public double getSecondsInLocalDay()
offset from UTC
.getSecondsInUTCDay()
public double getSecondsInUTCDay()
offset from UTC
.-getMinutesFromUTC()
to Constants.JULIAN_DAY + getMinutesFromUTC()
getSecondsInLocalDay()
public String toStringWithoutUtcOffset()
formatUtcOffset()
,
toString()
public String formatUtcOffset()
+00:00
.toStringWithoutUtcOffset()
,
toString()
public String toString()
toString
in class Object
toStringWithoutUtcOffset()
,
formatUtcOffset()
public int compareTo(TimeComponents other)
compareTo
in interface Comparable<TimeComponents>
Copyright © 2002-2022 CS GROUP. All rights reserved.