Package org.cip4.jdflib.util
Class JDFDuration
java.lang.Object
org.cip4.jdflib.util.JDFDuration
- All Implemented Interfaces:
Comparable<JDFDuration>
-
Constructor Summary
ConstructorsConstructorDescriptionAllocates aJDFDurationobject and initializes it with 0JDFDuration(double s) Allocates aJDFDurationobject and initializes it with 's'JDFDuration(int s, int m, int h, int d) Allocates aJDFDurationobject and initializes it with days, hours, minutes, secondsJDFDuration(long s) Allocates aJDFDurationobject and initializes it with 's'JDFDuration(String strDuration) Allocates aJDFDurationobject and initializes it with a value ofstrDuration, represented as a formatted duration string.JDFDuration(JDFDate start, JDFDate end) creates a duration from two dates; may be negative if start later endMakes a copy of theJDFDurationobject 'd' -
Method Summary
Modifier and TypeMethodDescriptionaddOffset(int seconds, int minutes, int hours, int days) add a given offset to this
note: multiple calls stackdoubleaddSeconds(double seconds) add seconds to a durationintcompareTo(JDFDuration arg0) static JDFDurationcreateDuration(String duration) does some heuristics to create a duration if duration is purely numeric, we guess daysbooleanCompares two JDFDuration objects for equality.
The result istrueif and only if the argument is notnulland is aJDFDurationobject that represents the same duration, as this object.longthe duration in secondsFormat and return the duration set by 'setDuration(int i)' or 'setDurationString(String a_aDuration)' as an ISO conforming String.
For example: 'P1Y2M3DT10H30M'longthe duration in millisecondsinthashCode()hashCode: complements equals() to fulfill the equals/hashCode contractbooleanisLess - tests if the duration of this JDFDuration is longer than the duration of the specified JDFDuration.booleanisShorter - tests if the duration of this JDFDuration is less than the duration of the specified JDFDuration.voidsetDuration(double seconds) setDuration: sets a duration forthisin seconds, including fractions.voidsetDuration(long seconds) setDuration: sets a duration forthisin seconds.booleansetDurationISO(String a_aDuration) Set a duration.toString()for debug purposes
-
Constructor Details
-
JDFDuration
public JDFDuration()Allocates aJDFDurationobject and initializes it with 0 -
JDFDuration
Makes a copy of theJDFDurationobject 'd'- Parameters:
d- the duration
-
JDFDuration
creates a duration from two dates; may be negative if start later end- Parameters:
start- the starting pointend- the end point
-
JDFDuration
public JDFDuration(double s) Allocates aJDFDurationobject and initializes it with 's'- Parameters:
s- duration in seconds s may be fractional
-
JDFDuration
public JDFDuration(long s) Allocates aJDFDurationobject and initializes it with 's'- Parameters:
s- duration in seconds s
-
JDFDuration
public JDFDuration(int s, int m, int h, int d) Allocates aJDFDurationobject and initializes it with days, hours, minutes, seconds- Parameters:
d-h-m-s-
-
JDFDuration
Allocates aJDFDurationobject and initializes it with a value ofstrDuration, represented as a formatted duration string.
Duration examples:- "P1Y2M3DT10H30M"
- "P8MT12M"
Durations with overflows, e.g. P13M (13 Months) are also handled and correctly output, in this case P1Y1M- Parameters:
strDuration- - formatted duration- Throws:
DataFormatException- if strDuration is not a valid string representation of JDFDuration
-
-
Method Details
-
createDuration
does some heuristics to create a duration if duration is purely numeric, we guess days- Parameters:
duration-- Returns:
-
addSeconds
public double addSeconds(double seconds) add seconds to a duration- Parameters:
seconds- number of seconds to add- Returns:
- the new duration in seconds
-
addOffset
add a given offset to this
note: multiple calls stack- Parameters:
seconds- seconds to add to thisminutes- minutes to add to thishours- hours to add to thisdays- days to add to this
-
toString
for debug purposes -
getDurationISO
Format and return the duration set by 'setDuration(int i)' or 'setDurationString(String a_aDuration)' as an ISO conforming String.
For example: 'P1Y2M3DT10H30M'- Returns:
- String - the duration formatted as an ISO 8601 conforming String if duration is '0' return value is 'PT00M'
-
setDurationISO
Set a duration. Durations are not bound to time or date and can be set independently- Parameters:
a_aDuration- formatted duration string 'P1Y2M3DT10H30M'- Returns:
- true - the duration was set
false - the duration was not set, because a NumberFormatException was thrown (-> parseInt())
-
setDuration
public void setDuration(long seconds) setDuration: sets a duration forthisin seconds. This duration is used in multiple classes of the JDF (e.g. Heating time).- Parameters:
seconds- the duration in seconds.
-
setDuration
public void setDuration(double seconds) setDuration: sets a duration forthisin seconds, including fractions. This duration is used in multiple classes of the JDF (e.g. Heating time).- Parameters:
seconds- the duration in seconds.
-
getDuration
public long getDuration()the duration in seconds- Returns:
- duration in seconds; '0' default
-
getDurationMillis
public long getDurationMillis()the duration in milliseconds- Returns:
- duration in seconds; '0' default
-
isLonger
isLess - tests if the duration of this JDFDuration is longer than the duration of the specified JDFDuration. Compares the integer durations, thus -PT15S is shorter than -PT5S- Parameters:
x- the JDFDuration object to compare tothis- Returns:
- boolean - true if the duration of this JDFDuration is longer than the duration of the JDFDuration 'x'.
-
isShorter
isShorter - tests if the duration of this JDFDuration is less than the duration of the specified JDFDuration. Compares the integer durations, thus -PT15S is shorter than -PT5S- Parameters:
x- the JDFDuration object to compare tothis- Returns:
- boolean - true if the duration of this JDFDuration is shorter than the duration of the JDFDuration 'x'.
-
equals
Compares two JDFDuration objects for equality.
The result istrueif and only if the argument is notnulland is aJDFDurationobject that represents the same duration, as this object. -
hashCode
public int hashCode()hashCode: complements equals() to fulfill the equals/hashCode contract -
compareTo
- Specified by:
compareToin interfaceComparable<JDFDuration>- Parameters:
arg0-- Returns:
- See Also:
-