Package com.mdfromhtml.core
Class MDfromHTMLDuration
- java.lang.Object
-
- com.mdfromhtml.core.MDfromHTMLDuration
-
- All Implemented Interfaces:
Serializable,Comparable<MDfromHTMLDuration>
public class MDfromHTMLDuration extends Object implements Serializable, Comparable<MDfromHTMLDuration>
Utility class for durations in time.- Author:
- wnm3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Stringm_strClassNamestatic MDfromHTMLDurationUNDEFINED_MDfromHTMLDurationAn undefined version of this object.
-
Constructor Summary
Constructors Constructor Description MDfromHTMLDuration()Construct an undefinedMDfromHTMLDuration.MDfromHTMLDuration(String strName)Construct a well formedMDfromHTMLDurationMDfromHTMLDuration(String strName, MDfromHTMLDate dateStart, MDfromHTMLDate dateEnd)Construct a well formedMDfromHTMLDuration
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(MDfromHTMLDuration o1)longelapsedDays()Calculate the number of elapsed days between the start and end of this duration.static longelapsedDays(Date dateStart, Date dateEnd)Calculate the number of elapsed days between the start and end of this duration.longelapsedHours()Calculate the number of elapsed hours between the start and end of this duration.static longelapsedHours(Date dateStart, Date dateEnd)Calculate the number of elapsed hours between the start and end of this duration.longelapsedMinutes()Calculate the number of elapsed minutes between the start and end of this duration.static longelapsedMinutes(Date dateStart, Date dateEnd)Calculate the number of elapsed minutes between the start and end of this duration.longelapsedSeconds()Calculate the number of elapsed seconds between the start and end of this duration.static longelapsedSeconds(Date dateStart, Date dateEnd)Calculate the number of elapsed seconds between the start and end of this duration.longelapsedTime()Calculate the number of elapsed milliseconds between the start and end of this duration.static longelapsedTime(Date dateStart, Date dateEnd)Calculate the number of elapsed milliseconds between the start and end of this duration.booleanequals(MDfromHTMLDuration o1)StringformattedElapsedTime()static StringformattedElapsedTime(double dElapsedSeconds)static StringformattedElapsedTime(long lElapsedMS)static StringformattedElapsedTime(Date dateStart, Date dateEnd)MDfromHTMLDategetEndDate()StringgetName()MDfromHTMLDategetStartDate()booleanisUndefined()Determine if thisMDfromHTMLDuration is undefined (e.g., if its name equals UNDEFINED_String).static voidmain(String[] args)static MDfromHTMLDurationnewInstanceFromListString(String listString)Create anMDfromHTMLDuration from the passed list string.voidsetDuration(MDfromHTMLDate dateStart, MDfromHTMLDate dateEnd)Set the start and end dates for this duration.voidsetEndDate(MDfromHTMLDate endDate)Set the end date for this duration.voidsetName(String strName)Set the name for this duration.voidsetStartDate(MDfromHTMLDate startDate)Set the start date for this duration.StringtoString()Generates a list string compatible with the Utils listStringToArrayList method describing this duration.StringtoString(String strTimeZone)Generates a list string compatible with the Utils listStringToArrayList method describing this duration using the specified timezone for dates.static MDfromHTMLDurationundefinedForNull(MDfromHTMLDuration duration)Converts the inputMDfromHTMLDuration to an undefinedMDfromHTMLDuration if the input MDfromHTMLDuration is null.
-
-
-
Field Detail
-
m_strClassName
public static final String m_strClassName
-
UNDEFINED_MDfromHTMLDuration
public static MDfromHTMLDuration UNDEFINED_MDfromHTMLDuration
An undefined version of this object. An undefinedMDfromHTMLDuration has an undefined name.- See Also:
MDfromHTMLUtils.isUndefined(String)
-
-
Constructor Detail
-
MDfromHTMLDuration
public MDfromHTMLDuration()
Construct an undefinedMDfromHTMLDuration.
-
MDfromHTMLDuration
public MDfromHTMLDuration(String strName)
Construct a well formedMDfromHTMLDuration- Parameters:
strName- name of this duration
-
MDfromHTMLDuration
public MDfromHTMLDuration(String strName, MDfromHTMLDate dateStart, MDfromHTMLDate dateEnd)
Construct a well formedMDfromHTMLDuration- Parameters:
strName- name of this durationdateStart- start date of this durationdateEnd- end date of this duration
-
-
Method Detail
-
elapsedDays
public static long elapsedDays(Date dateStart, Date dateEnd)
Calculate the number of elapsed days between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of days since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Parameters:
dateStart- the start date of the durationdateEnd- the end date of the duration- Returns:
- the number of elapsed days between the start and end of this duration.
-
elapsedHours
public static long elapsedHours(Date dateStart, Date dateEnd)
Calculate the number of elapsed hours between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of hours since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Parameters:
dateStart- the start date of the durationdateEnd- the end date of the duration- Returns:
- the number of elapsed hours between the start and end of this duration.
-
elapsedMinutes
public static long elapsedMinutes(Date dateStart, Date dateEnd)
Calculate the number of elapsed minutes between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of minutes since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Parameters:
dateStart- the start date of the durationdateEnd- the end date of the duration- Returns:
- the number of elapsed minutes between the start and end of this duration.
-
elapsedSeconds
public static long elapsedSeconds(Date dateStart, Date dateEnd)
Calculate the number of elapsed seconds between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of seconds since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Parameters:
dateStart- the start date of the durationdateEnd- the end date of the duration- Returns:
- the number of elapsed seconds between the start and end of this duration.
-
elapsedTime
public static long elapsedTime(Date dateStart, Date dateEnd)
Calculate the number of elapsed milliseconds between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of milliseconds since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then the negative of the elapsed time from the end date to the start date is returned.- Parameters:
dateStart- the start date of the durationdateEnd- the end date of the duration- Returns:
- the number of elapsed milliseconds between the start and end of this duration.
-
formattedElapsedTime
public static String formattedElapsedTime(double dElapsedSeconds)
-
formattedElapsedTime
public static String formattedElapsedTime(long lElapsedMS)
-
main
public static void main(String[] args)
-
newInstanceFromListString
public static MDfromHTMLDuration newInstanceFromListString(String listString) throws Exception
Create anMDfromHTMLDuration from the passed list string.- Parameters:
listString- the list of String fields needed to create anMDfromHTMLDuration (name, start date, end date);- Returns:
- a newly createdMDfromHTMLDuration object filled with the content of the supplied listString. If the listString is null or empty, or does not contain at least the name field, an undefinedMDfromHTMLDuration is returned.
- Throws:
Exception- if listString is null or empty, or if the name in the list is null, empty or undefined.- See Also:
isUndefined()
-
undefinedForNull
public static MDfromHTMLDuration undefinedForNull(MDfromHTMLDuration duration)
Converts the inputMDfromHTMLDuration to an undefinedMDfromHTMLDuration if the input MDfromHTMLDuration is null.- Parameters:
duration- MDfromHTMLDuration to be tested against null and converted.- Returns:
- An undefinedMDfromHTMLDuration if the inputMDfromHTMLDuration was null, otherwise, the inputMDfromHTMLDuration is echoed back.
-
compareTo
public int compareTo(MDfromHTMLDuration o1)
- Specified by:
compareToin interfaceComparable<MDfromHTMLDuration>
-
elapsedDays
public long elapsedDays()
Calculate the number of elapsed days between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of days since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Returns:
- the number of elapsed days between the start and end of this duration.
-
elapsedHours
public long elapsedHours()
Calculate the number of elapsed hours between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of hours since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Returns:
- the number of elapsed hours between the start and end of this duration.
-
elapsedMinutes
public long elapsedMinutes()
Calculate the number of elapsed minutes between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of minutes since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Returns:
- the number of elapsed minutes between the start and end of this duration.
-
elapsedSeconds
public long elapsedSeconds()
Calculate the number of elapsed seconds between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of seconds since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Returns:
- the number of elapsed seconds between the start and end of this duration.
-
elapsedTime
public long elapsedTime()
Calculate the number of elapsed milliseconds between the start and end of this duration. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of milliseconds since the epoch (midnight 1/1/70 GMT) until the end date. If the start date is greater than the end date, then 0L is returned.- Returns:
- the number of elapsed milliseconds between the start and end of this duration.
-
equals
public boolean equals(MDfromHTMLDuration o1)
-
formattedElapsedTime
public String formattedElapsedTime()
- Returns:
- the elapsed time of this duration formatted as a String containing an optional sign (if the duration is negative) followed by the days-hours:minutes:seconds.milliseconds
-
getEndDate
public MDfromHTMLDate getEndDate()
- Returns:
- the end date of this duration. Note: this may be set to an undefinedMDfromHTMLDate. Test for this condition using isUndefined().
- See Also:
MDfromHTMLDate.UNDEFINED_MDfromHTMLDate,MDfromHTMLDate.isUndefined()
-
getName
public String getName()
- Returns:
- the name of this duration. Note: this may be set to UNDEFINED_String. Test for this condition using isUndefined().
- See Also:
MDfromHTMLConstants.UNDEFINED_String,MDfromHTMLUtils.isUndefined(String)
-
getStartDate
public MDfromHTMLDate getStartDate()
- Returns:
- the start date of this duration. Note: this may be set to an undefinedMDfromHTMLDate. Test for this condition using isUndefined().
- See Also:
MDfromHTMLDate.UNDEFINED_MDfromHTMLDate,MDfromHTMLDate.isUndefined()
-
isUndefined
public boolean isUndefined()
Determine if thisMDfromHTMLDuration is undefined (e.g., if its name equals UNDEFINED_String).- Returns:
- true if thisMDfromHTMLDuration is determined to be undefined. Otherwise, return false.
- See Also:
MDfromHTMLConstants.UNDEFINED_String
-
setDuration
public void setDuration(MDfromHTMLDate dateStart, MDfromHTMLDate dateEnd)
Set the start and end dates for this duration. If null is passed for either parameter, it is set to an undefinedMDfromHTMLDate.- Parameters:
dateStart- the start date.dateEnd- the end date.- See Also:
MDfromHTMLDate.UNDEFINED_MDfromHTMLDate,MDfromHTMLDate.isUndefined()
-
setEndDate
public void setEndDate(MDfromHTMLDate endDate)
Set the end date for this duration. If null is passed, the endDate is set to an undefinedMDfromHTMLDate.- Parameters:
endDate- the end date.
-
setName
public void setName(String strName) throws Exception
Set the name for this duration.- Parameters:
strName- the name.- Throws:
Exception- if strName is null, empty, or undefined.- See Also:
MDfromHTMLUtils.isUndefined(String)
-
setStartDate
public void setStartDate(MDfromHTMLDate startDate)
Set the start date for this duration. If null is passed, the startDate is set to an undefinedMDfromHTMLDate.- Parameters:
startDate- the start date.
-
toString
public String toString()
Generates a list string compatible with the Utils listStringToArrayList method describing this duration.- Overrides:
toStringin classObject- Returns:
- a string list comprising delimited, quoted fields containing the name, start date, and end date of this duration, as well as the elapsed time formatted as DD-HH:MM:SS.mmm where DD is the number of days, HH is the number of hours, MM is the number of minutes, SS is the number of seconds, and mmm is the number of milliseconds.
- See Also:
MDfromHTMLUtils.listStringToArrayList(String)
-
toString
public String toString(String strTimeZone)
Generates a list string compatible with the Utils listStringToArrayList method describing this duration using the specified timezone for dates.- Parameters:
strTimeZone- the ID for a TimeZone as a String containing a sign followed by the two digit hour and two digit minute offset from Greenwich Mean Time. For example, for Eastern Standard Time, submit "-0500". For Europe/Paris submit "+0100".- Returns:
- a string list comprising delimited, quoted fields containing the name, start date, and end date of this duration, as well as the elapsed time formatted as DD-HH:MM:SS.mmm where DD is the number of days, HH is the number of hours, MM is the number of minutes, SS is the number of seconds, and mmm is the number of milliseconds.
- See Also:
MDfromHTMLUtils.listStringToArrayList(String)
-
-