Class TimeFrame

java.lang.Object
com.mckoi.util.TimeFrame

public class TimeFrame extends 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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    Formatting enum.
    static int
    Formatting enum.
    static int
    Formatting enum.
    static int
    Formatting enum.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs the TimeFrame for the given time.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a Date that is the addition of this period of time to the given date.
    boolean
    Returns true if the TimeFrame is equal to another.
    format(int format_type)
    Returns a string that represents this time frame formatted as a string.
    format(int format_type, boolean shorthand)
    Returns a string that represents this time frame formatted as a string.
    Returns the number of milliseconds for the period of this time frame.
    boolean
    Returns true if this time frame represents no time.
    static TimeFrame
    Parses the given String and returns a TimeFrame object that represents the date.
    For Debugging.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • WEEKS

      public static int WEEKS
      Formatting enum.
    • DAYS

      public static int DAYS
      Formatting enum.
    • HOURS

      public static int HOURS
      Formatting enum.
    • MINUTES

      public static int MINUTES
      Formatting enum.
  • Constructor Details

    • TimeFrame

      public TimeFrame(BigDecimal period)
      Constructs the TimeFrame for the given time.
  • Method Details

    • getPeriod

      public 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 Date addToDate(Date date)
      Returns a Date that is the addition of this period of time to the given date.
    • format

      public 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 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, MINUTES
      shorthand - if false then timeframe is formatted in long hand. 'ms' -> 'milliseconds'
    • parse

      public static TimeFrame parse(String str) throws 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:
      ParseException
    • equals

      public boolean equals(Object ob)
      Returns true if the TimeFrame is equal to another.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      For Debugging.
      Overrides:
      toString in class Object