Package com.mckoi.util
Class TimeFrame
- java.lang.Object
-
- com.mckoi.util.TimeFrame
-
public class TimeFrame extends java.lang.Object
An immutable object that represents a frame of time down to the accuracy of a millisecond.This object wraps around a BigDecimal that represents the number of milliseconds it takes to pass through the period.
- Author:
- Tobias Downer
-
-
Constructor Summary
Constructors Constructor Description TimeFrame(java.math.BigDecimal period)
Constructs the TimeFrame for the given time.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Date
addToDate(java.util.Date date)
Returns a Date that is the addition of this period of time to the given date.boolean
equals(java.lang.Object ob)
Returns true if the TimeFrame is equal to another.java.lang.String
format(int format_type)
Returns a string that represents this time frame formatted as a string.java.lang.String
format(int format_type, boolean shorthand)
Returns a string that represents this time frame formatted as a string.java.math.BigDecimal
getPeriod()
Returns the number of milliseconds for the period of this time frame.boolean
isNoTime()
Returns true if this time frame represents no time.static TimeFrame
parse(java.lang.String str)
Parses the given String and returns a TimeFrame object that represents the date.java.lang.String
toString()
For Debugging.
-
-
-
Method Detail
-
getPeriod
public java.math.BigDecimal getPeriod()
Returns the number of milliseconds for the period of this time frame.
-
isNoTime
public boolean isNoTime()
Returns true if this time frame represents no time.
-
addToDate
public java.util.Date addToDate(java.util.Date date)
Returns a Date that is the addition of this period of time to the given date.
-
format
public java.lang.String format(int format_type)
Returns a string that represents this time frame formatted as a string. The period is formatted as short hand.- Parameters:
format_type
- either WEEKS, HOURS, MINUTES
-
format
public java.lang.String format(int format_type, boolean shorthand)
Returns a string that represents this time frame formatted as a string.- Parameters:
format_type
- either WEEKS, HOURS, MINUTESshorthand
- if false then timeframe is formatted in long hand. 'ms' -> 'milliseconds'
-
parse
public static TimeFrame parse(java.lang.String str) throws java.text.ParseException
Parses the given String and returns a TimeFrame object that represents the date. This excepts strings such as:"3 wks 12 days", "5.4 days", "9d", "12 minutes", "24 mins", etc.
See 'GeneralParser' for more details.
- Throws:
java.text.ParseException
-
equals
public boolean equals(java.lang.Object ob)
Returns true if the TimeFrame is equal to another.- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
For Debugging.- Overrides:
toString
in classjava.lang.Object
-
-