org.hackystat.utilities.tstamp
Class Tstamp

java.lang.Object
  extended by org.hackystat.utilities.tstamp.Tstamp

public final class Tstamp
extends java.lang.Object

Utility class that facilitates Timestamp representation and processing. There are too many classes already named "Timestamp", thus the abbreviated name.

Author:
Philip Johnson

Method Summary
static int daysBetween(javax.xml.datatype.XMLGregorianCalendar day1, javax.xml.datatype.XMLGregorianCalendar day2)
          Returns the number of days between time1 and time2.
static long diff(javax.xml.datatype.XMLGregorianCalendar time1, javax.xml.datatype.XMLGregorianCalendar time2)
          Returns differences between time1 and time2 in milliseconds.
static boolean equal(javax.xml.datatype.XMLGregorianCalendar time1, javax.xml.datatype.XMLGregorianCalendar time2)
          Returns true if time1 equals time2.
static javax.xml.datatype.XMLGregorianCalendar getDefaultProjectEndTime()
          Returns the end time for the Default project, which is five years after today.
static javax.xml.datatype.XMLGregorianCalendar getDefaultProjectStartTime()
          Returns the start time for the Default project, which is 2000-01-01.
static boolean greaterThan(java.lang.String timeString1, java.lang.String timeString2)
          Returns true if timeString1 > timeString2.
static boolean greaterThan(javax.xml.datatype.XMLGregorianCalendar time1, javax.xml.datatype.XMLGregorianCalendar time2)
          Returns true if time1 > time2.
static boolean inBetween(javax.xml.datatype.XMLGregorianCalendar start, javax.xml.datatype.XMLGregorianCalendar tstamp, javax.xml.datatype.XMLGregorianCalendar end)
          Returns true if tstamp is equal to or between start and end.
static javax.xml.datatype.XMLGregorianCalendar incrementDays(javax.xml.datatype.XMLGregorianCalendar tstamp, int days)
          Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of days.
static javax.xml.datatype.XMLGregorianCalendar incrementHours(javax.xml.datatype.XMLGregorianCalendar tstamp, int hours)
          Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of hours.
static javax.xml.datatype.XMLGregorianCalendar incrementMilliseconds(javax.xml.datatype.XMLGregorianCalendar tstamp, long milliseconds)
          Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of milliseconds.
static javax.xml.datatype.XMLGregorianCalendar incrementMinutes(javax.xml.datatype.XMLGregorianCalendar tstamp, int minutes)
          Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of minutes.
static javax.xml.datatype.XMLGregorianCalendar incrementSeconds(javax.xml.datatype.XMLGregorianCalendar tstamp, int seconds)
          Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of seconds.
static boolean isBogusStartTime(javax.xml.datatype.XMLGregorianCalendar startTime)
          In the early days of Hackystat, default project start times were 1000-01-01.
static boolean isTimestamp(java.lang.String lexicalRepresentation)
          Returns true if the passed string can be parsed into an XMLGregorianCalendar object.
static boolean isTodayOrLater(javax.xml.datatype.XMLGregorianCalendar timestamp)
          Returns true if the passed timestamp indicates some time today or some time in the future.
static boolean isYesterdayOrLater(javax.xml.datatype.XMLGregorianCalendar timestamp)
          Returns true if the passed timestamp indicates some time yesterday or some time in the future.
static boolean lessThan(javax.xml.datatype.XMLGregorianCalendar time1, javax.xml.datatype.XMLGregorianCalendar time2)
          Returns true if time1 < time2.
static javax.xml.datatype.XMLGregorianCalendar makeTimestamp()
          Returns an XMLGregorianCalendar corresponding to the current time.
static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(Day day)
          Converts the specified Day into a javax.xml.datatype.XMLGregorianCalendar.
static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(long timeInMillis)
          Converts the specified time in milliseconds into a javax.xml.datatype.XMLGregorianCalendar.
static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(java.lang.String rep)
          Returns an XMLGregorianCalendar, given its string representation.
static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(java.sql.Timestamp tstamp)
          Converts a javax.sql.Timestamp into a javax.xml.datatype.XMLGregorianCalendar.
static java.sql.Timestamp makeTimestamp(javax.xml.datatype.XMLGregorianCalendar calendar)
          Returns a new java.sql.Timestamp created from a javax.xml.datatype.XMLGregorianCalendar.
static java.util.List<javax.xml.datatype.XMLGregorianCalendar> sort(java.util.Collection<javax.xml.datatype.XMLGregorianCalendar> tstamps)
          Returns a newly created sorted list of tstamps from the passed collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isTimestamp

public static boolean isTimestamp(java.lang.String lexicalRepresentation)
Returns true if the passed string can be parsed into an XMLGregorianCalendar object.

Parameters:
lexicalRepresentation - The string representation.
Returns:
True if the string is a legal XMLGregorianCalendar.

makeTimestamp

public static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(java.lang.String rep)
                                                             throws java.lang.Exception
Returns an XMLGregorianCalendar, given its string representation. Missing hours, minutes, second, millisecond, and timezone fields are given defaults.

Parameters:
rep - The string representation.
Returns:
The timestamp.
Throws:
java.lang.Exception - If the string cannot be parsed into a timestamp.

makeTimestamp

public static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(java.sql.Timestamp tstamp)
Converts a javax.sql.Timestamp into a javax.xml.datatype.XMLGregorianCalendar.

Parameters:
tstamp - The javax.sql.Timestamp
Returns:
A new instance of a javax.xml.datatype.XmlGregorianCalendar

makeTimestamp

public static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(long timeInMillis)
Converts the specified time in milliseconds into a javax.xml.datatype.XMLGregorianCalendar.

Parameters:
timeInMillis - the specified time in milliseconds to convert.
Returns:
A new instance of a javax.xml.datatype.XmlGregorianCalendar

makeTimestamp

public static javax.xml.datatype.XMLGregorianCalendar makeTimestamp(Day day)
Converts the specified Day into a javax.xml.datatype.XMLGregorianCalendar.

Parameters:
day - The day to be converted.
Returns:
A new instance of a javax.xml.datatype.XmlGregorianCalendar.

incrementDays

public static javax.xml.datatype.XMLGregorianCalendar incrementDays(javax.xml.datatype.XMLGregorianCalendar tstamp,
                                                                    int days)
Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of days.

Parameters:
tstamp - The base date and time.
days - The number of days to increment. This can be a negative number.
Returns:
A new XMLGregorianCalendar instance representing the inc'd time.

incrementHours

public static javax.xml.datatype.XMLGregorianCalendar incrementHours(javax.xml.datatype.XMLGregorianCalendar tstamp,
                                                                     int hours)
Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of hours.

Parameters:
tstamp - The base date and time.
hours - The number of hours to increment. This can be a negative number.
Returns:
A new XMLGregorianCalendar instance representing the inc'd time.

incrementMinutes

public static javax.xml.datatype.XMLGregorianCalendar incrementMinutes(javax.xml.datatype.XMLGregorianCalendar tstamp,
                                                                       int minutes)
Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of minutes.

Parameters:
tstamp - The base date and time.
minutes - The number of minutes to increment. This can be a negative number.
Returns:
A new XMLGregorianCalendar instance representing the inc'd time.

incrementSeconds

public static javax.xml.datatype.XMLGregorianCalendar incrementSeconds(javax.xml.datatype.XMLGregorianCalendar tstamp,
                                                                       int seconds)
Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of seconds.

Parameters:
tstamp - The base date and time.
seconds - The number of seconds to increment. This can be a negative number.
Returns:
A new XMLGregorianCalendar instance representing the inc'd time.

incrementMilliseconds

public static javax.xml.datatype.XMLGregorianCalendar incrementMilliseconds(javax.xml.datatype.XMLGregorianCalendar tstamp,
                                                                            long milliseconds)
Returns a new XMLGregorianCalendar corresponding to the passed tstamp incremented by the number of milliseconds.

Parameters:
tstamp - The base date and time.
milliseconds - The number of milliseconds to increment. This can be a negative number.
Returns:
A new XMLGregorianCalendar instance representing the inc'd time.

makeTimestamp

public static java.sql.Timestamp makeTimestamp(javax.xml.datatype.XMLGregorianCalendar calendar)
Returns a new java.sql.Timestamp created from a javax.xml.datatype.XMLGregorianCalendar.

Parameters:
calendar - The XML timestamp.
Returns:
The SQL timestamp.

makeTimestamp

public static javax.xml.datatype.XMLGregorianCalendar makeTimestamp()
Returns an XMLGregorianCalendar corresponding to the current time.

Returns:
The timestamp.

getDefaultProjectStartTime

public static javax.xml.datatype.XMLGregorianCalendar getDefaultProjectStartTime()
Returns the start time for the Default project, which is 2000-01-01.

Returns:
A timestamp representing 2000-01-01.

getDefaultProjectEndTime

public static javax.xml.datatype.XMLGregorianCalendar getDefaultProjectEndTime()
Returns the end time for the Default project, which is five years after today. Note that this is updated every time the server starts up.

Returns:
The timestamp for the Default project end time.

isBogusStartTime

public static boolean isBogusStartTime(javax.xml.datatype.XMLGregorianCalendar startTime)
In the early days of Hackystat, default project start times were 1000-01-01. This was stupid. The following hack exists to correct projects containing this old value. This code and its callers can be removed when the disease is eradicated.

Parameters:
startTime - The startTime in question.
Returns:
True if it's before 1950.

inBetween

public static boolean inBetween(javax.xml.datatype.XMLGregorianCalendar start,
                                javax.xml.datatype.XMLGregorianCalendar tstamp,
                                javax.xml.datatype.XMLGregorianCalendar end)
Returns true if tstamp is equal to or between start and end.

Parameters:
start - The start time.
tstamp - The timestamp to test.
end - The end time.
Returns:
True if tstamp is between start and end.

greaterThan

public static boolean greaterThan(javax.xml.datatype.XMLGregorianCalendar time1,
                                  javax.xml.datatype.XMLGregorianCalendar time2)
Returns true if time1 > time2.

Parameters:
time1 - The first time.
time2 - The second time.
Returns:
True if time1 > time2

daysBetween

public static int daysBetween(javax.xml.datatype.XMLGregorianCalendar day1,
                              javax.xml.datatype.XMLGregorianCalendar day2)
Returns the number of days between time1 and time2. Returns a negative number if day1 is after day2. Takes into account daylight savings time issues.

Parameters:
day1 - The first day.
day2 - The second day.
Returns:
The number of days between the two days.

greaterThan

public static boolean greaterThan(java.lang.String timeString1,
                                  java.lang.String timeString2)
Returns true if timeString1 > timeString2. Throws an unchecked IllegalArgument exception if the strings can't be converted to timestamps.

Parameters:
timeString1 - The first time.
timeString2 - The second time.
Returns:
True if time1 > time2

lessThan

public static boolean lessThan(javax.xml.datatype.XMLGregorianCalendar time1,
                               javax.xml.datatype.XMLGregorianCalendar time2)
Returns true if time1 < time2.

Parameters:
time1 - The first time.
time2 - The second time.
Returns:
True if time1 < time2

equal

public static boolean equal(javax.xml.datatype.XMLGregorianCalendar time1,
                            javax.xml.datatype.XMLGregorianCalendar time2)
Returns true if time1 equals time2.

Parameters:
time1 - The first time.
time2 - The second time.
Returns:
True if time1 equals time2

diff

public static long diff(javax.xml.datatype.XMLGregorianCalendar time1,
                        javax.xml.datatype.XMLGregorianCalendar time2)
Returns differences between time1 and time2 in milliseconds.

Parameters:
time1 - Start.
time2 - End.
Returns:
Difference between two times in milliseconds.

isTodayOrLater

public static boolean isTodayOrLater(javax.xml.datatype.XMLGregorianCalendar timestamp)
Returns true if the passed timestamp indicates some time today or some time in the future.

Parameters:
timestamp - The timestamp of interest.
Returns:
True if it's today or some day in the future.

isYesterdayOrLater

public static boolean isYesterdayOrLater(javax.xml.datatype.XMLGregorianCalendar timestamp)
Returns true if the passed timestamp indicates some time yesterday or some time in the future. This is useful for the Commit/Churn DPDs, where the sensor typically sends data not from the current day, but from the day before.

Parameters:
timestamp - The timestamp of interest.
Returns:
True if it's today or some day in the future.

sort

public static java.util.List<javax.xml.datatype.XMLGregorianCalendar> sort(java.util.Collection<javax.xml.datatype.XMLGregorianCalendar> tstamps)
Returns a newly created sorted list of tstamps from the passed collection.

Parameters:
tstamps - The timestamps to be sorted.
Returns:
A new list of tstamps, now in sorted order.