ewe.sys
Class Time

java.lang.Object
  extended byewe.data.DataObject
      extended byewe.sys.Time
All Implemented Interfaces:
Comparable, Copyable, DataUnit, Stringable, Textable, Value
Direct Known Subclasses:
Date, DayOfYear, TimeMask, TimeOfDay, TimeStamp

public class Time
extends DataObject
implements Value, Textable

Time identifies a date and time, storing information to millisecond precision only. A Time object is displayed as a string in a manner specified by the "format" string. If this value is null it will be formatted as by the "defaultFormat" string.

The format string uses the convention as the java.util.SimpleDateFormat with some specifiers left out. What is included are:

 Symbol   Meaning                 Presentation        Example
 ------   -------                 ------------        -------
 y        year                    (Number)            1996
 M        month in year           (Text & Number)     July & 07
 d        day in month            (Number)            10
 h        hour in am/pm (1~12)    (Number)            12
 H        hour in day (0~23)      (Number)            0
 m        minute in hour          (Number)            30
 s        second in minute        (Number)            55
 S        millisecond             (Number)            978
 E        day in week             (Text)              Tuesday
 a        am/pm marker            (Text)              PM
 '        escape for text
 

Time also implements Textable and getText()/setText() encodes the object in a numeric form that is independant of the format used for toString()/fromString().


Field Summary
 String _fields
           
 int day
          The day in the range of 1 to the last day in the month.
static int DAY
           
 int dayOfWeek
          The day of the week in the range 1 to 7, with 1 being Monday and 7 being Sunday
static String defaultFormat
          The default format to use if one is not specified.
protected static long epoch
           
 String format
          The date format to use for I/O with this Time object.
 int hour
          The hour in the range of 0 to 23.
static int HOUR
           
 int millis
          Milliseconds in the range of 0 to 999.
 int minute
          The minute in the range of 0 to 59.
static int MINUTE
           
 int month
          The month in the range of 1 to 12.
static int MONTH
           
 int second
          The second in the range of 0 to 59.
static int SECOND
           
 int year
          The year as its full set of digits (year 2010 is 2010).
static int YEAR
           
 
Constructor Summary
Time()
          Constructs a time object set to the current date and time.
Time(int day, int month, int year)
           
 
Method Summary
 boolean after(Time other)
           
 boolean before(Time other)
           
static int compareEncodedTimes(long one, long two, boolean ignoreDate, boolean ignoreTime)
          Compare two encoded times.
 int compareTo(Object other)
          Compare this object with another.
static long convertSystemTime(long time, boolean toSystem)
           
static DateChange dateDifference(Time later, Time earlier, DateChange destination)
           
 DateChange difference(Time earlier, DateChange destination)
           
 boolean equals(Object other)
          Returns if this object is considered equal to the other object.
 String format(String dateFormat)
           
 void fromString(String source)
           
 void fromString(String source, Locale locale)
           
static boolean fromString(String source, Time t, String format, Locale locale)
           
 String getDefaultFormat()
           
 long getEncodedTime()
          This converts to a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in a platform independent manner.
 String getFormat()
           
 String getText()
           
 long getTime()
          This converts the time into a 64-bit time value and represents the number of milliseconds since Jan 1, 1970.
 int hashCode()
          Returns a hashCode for the object.
static int indexOfDayInWeek(int dayOfWeek, Locale locale)
          This returns the index of the day in the week.
static boolean isLeapYear(int year)
           
 boolean isValid()
           
static int numberOfDays(int month, int year)
          Find the number of days in a month.
 void parse(String dateValue)
           
 void parse(String dateValue, String dateFormat)
           
 Time roundTo(int roundTo)
          Rounds this time down.
 Time setEncodedTime(long from)
          This converts from a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in a platform independent manner.
 Time setFormat(String format)
           
 void setText(String text)
           
 Time setTime(long source)
          This converts a 64-bit absolute time value as provided by getTime() (which represents the number of milliseconds since Jan 1, 1970).
 Time setToCurrentTime()
          Set the time to be the current time.
 String toString()
          Return a String representation of this object.
 String toString(Locale locale)
           
static String toString(Time t, String format, Locale locale)
           
 Time update()
          Update values like dayOfWeek from the year, month, day and time values.
 
Methods inherited from class ewe.data.DataObject
_getSetField, appendAllFields, copied, copyFrom, getCopy, getDeclaredField, getDeclaredFieldValue, getDeclaredFieldValue, getFieldList, getFieldList, getMyFieldList, getNew
 
Methods inherited from class java.lang.Object
clone, finalize, getClass
 

Field Detail

year

public int year
The year as its full set of digits (year 2010 is 2010).


month

public int month
The month in the range of 1 to 12.


day

public int day
The day in the range of 1 to the last day in the month.


hour

public int hour
The hour in the range of 0 to 23.


minute

public int minute
The minute in the range of 0 to 59.


second

public int second
The second in the range of 0 to 59.


millis

public int millis
Milliseconds in the range of 0 to 999.


dayOfWeek

public int dayOfWeek
The day of the week in the range 1 to 7, with 1 being Monday and 7 being Sunday


format

public String format
The date format to use for I/O with this Time object.


defaultFormat

public static String defaultFormat
The default format to use if one is not specified.


_fields

public String _fields

epoch

protected static long epoch

SECOND

public static final int SECOND
See Also:
Constant Field Values

MINUTE

public static final int MINUTE
See Also:
Constant Field Values

HOUR

public static final int HOUR
See Also:
Constant Field Values

DAY

public static final int DAY
See Also:
Constant Field Values

MONTH

public static final int MONTH
See Also:
Constant Field Values

YEAR

public static final int YEAR
See Also:
Constant Field Values
Constructor Detail

Time

public Time()
Constructs a time object set to the current date and time.


Time

public Time(int day,
            int month,
            int year)
Method Detail

convertSystemTime

public static long convertSystemTime(long time,
                                     boolean toSystem)

isValid

public boolean isValid()

isLeapYear

public static boolean isLeapYear(int year)

dateDifference

public static DateChange dateDifference(Time later,
                                        Time earlier,
                                        DateChange destination)
                                 throws IllegalArgumentException
Throws:
IllegalArgumentException

difference

public DateChange difference(Time earlier,
                             DateChange destination)
                      throws IllegalArgumentException
Throws:
IllegalArgumentException

getTime

public long getTime()
This converts the time into a 64-bit time value and represents the number of milliseconds since Jan 1, 1970. Although this is the epoch used, it is bad practice to assume that this millisecond value is portable. Its purpose is to allow calculations of time past between two time values. For a fully portable 64-bit time, use getEncodedTime().


setTime

public Time setTime(long source)
This converts a 64-bit absolute time value as provided by getTime() (which represents the number of milliseconds since Jan 1, 1970). Although this is the epoch used, it is bad practice to assume that this millisecond value is portable. Its purpose is to allow calculations of time past between two time values or to move from one Time to another by adding or subtracting millisecond values from it. For a fully portable 64-bit time, use setEncodedTime().

This returns this Time value if the time is valid and null if it is not.


update

public Time update()
Update values like dayOfWeek from the year, month, day and time values. It should also check for validity. You should call isValid() after doing update.


setFormat

public Time setFormat(String format)

getFormat

public String getFormat()

getDefaultFormat

public String getDefaultFormat()

parse

public void parse(String dateValue,
                  String dateFormat)
           throws IllegalArgumentException
Throws:
IllegalArgumentException

parse

public void parse(String dateValue)
           throws IllegalArgumentException
Throws:
IllegalArgumentException

format

public String format(String dateFormat)

fromString

public void fromString(String source)
Specified by:
fromString in interface Stringable

fromString

public void fromString(String source,
                       Locale locale)

roundTo

public Time roundTo(int roundTo)
Rounds this time down.

Parameters:
roundTo - should be SECOND, MINUTE, HOUR, ...

compareTo

public int compareTo(Object other)
Description copied from interface: Comparable
Compare this object with another. It should return: less than 0 if this object is considered LESS than the "other" object; greater than 0 if this object is considered GREATER than the "other" object; 0 if this object is considered EQUAL to the "other" object. (i.e. it is an implicit subtraction).

Specified by:
compareTo in interface Comparable
Overrides:
compareTo in class DataObject

before

public boolean before(Time other)

after

public boolean after(Time other)

toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Specified by:
toString in interface Stringable
Overrides:
toString in class Object
Returns:
a String representing this object.

toString

public String toString(Locale locale)

toString

public static String toString(Time t,
                              String format,
                              Locale locale)

fromString

public static boolean fromString(String source,
                                 Time t,
                                 String format,
                                 Locale locale)

numberOfDays

public static int numberOfDays(int month,
                               int year)
Find the number of days in a month.


indexOfDayInWeek

public static int indexOfDayInWeek(int dayOfWeek,
                                   Locale locale)
This returns the index of the day in the week. The input parameter is a value of 1 = Monday to 7 = Sunday. The output value is 1 = First day of week to 7 = Last day of week.


getEncodedTime

public long getEncodedTime()
This converts to a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in a platform independent manner. This value should not be used for calculations but only for storage or transmission.


setEncodedTime

public Time setEncodedTime(long from)
This converts from a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in a platform independent manner. This value should not be used for calculations but only for storage or transmission.


compareEncodedTimes

public static int compareEncodedTimes(long one,
                                      long two,
                                      boolean ignoreDate,
                                      boolean ignoreTime)
Compare two encoded times.

Parameters:
one - An encoded time from getEncodedTime().
two - An encoded time from getEncodedTime().
ignoreDate - if this is true then the date portion will be ignored.
ignoreTime - if this is true then the time portion will be ignored.
Returns:
less than 0 if one is less than two, greater than 0 if one is greater than two, 0 if they are equal.

getText

public String getText()
Specified by:
getText in interface Textable

setText

public void setText(String text)
Specified by:
setText in interface Textable

equals

public boolean equals(Object other)
Description copied from class: Object
Returns if this object is considered equal to the other object.

Overrides:
equals in class DataObject

hashCode

public int hashCode()
Description copied from class: Object
Returns a hashCode for the object. The general contract of hashCode is:
  • An object must return the same hash code for its entire existence.
  • If two objects are considered equal by the equals() method, they should return the same hash code. Not all Objects will do this and you should only use hashCode() from Objects which declare an overrided version of hashCode(). The only Objects which provide consistent and correct hash codes under Ewe are Object, String and Class.

    Overrides:
    hashCode in class Object

  • setToCurrentTime

    public Time setToCurrentTime()
    Set the time to be the current time.

    Returns:
    this Time.