org.enblom.time
Class TimeUtils

java.lang.Object
  extended by org.enblom.time.TimeUtils

public class TimeUtils
extends Object

Utilities for dealing with Time and similar objects.

Author:
Andreas Enblom

Constructor Summary
TimeUtils()
           
 
Method Summary
static int differenceInDays(DayDate later, DayDate earlier)
          Calculates the difference in whole days between the two given date.
static int differenceInDays(Time later, Time earlier)
          Calculates the difference in whole days between the two given times.
static long differenceInMillis(TimeOfDay later, TimeOfDay earlier)
          Calculates the difference in milliseconds between the two given times of day.
static long differenceInMillis(Time later, Time earlier)
          Calculates the difference in milliseconds between the two given times.
static DayDate max(DayDate d1, DayDate d2)
          Finds the maximum of two dates.
static TimeOfDay max(TimeOfDay t1, TimeOfDay t2)
          Finds the maximum of two times.
static Time max(Time t1, Time t2)
          Finds the maximum of two times.
static DayDate min(DayDate d1, DayDate d2)
          Finds the minimum of two dates.
static TimeOfDay min(TimeOfDay t1, TimeOfDay t2)
          Finds the minimum of two times.
static Time min(Time t1, Time t2)
          Finds the minimum of two times.
static Time moveToTimeZone(Time time, TimeZone timeZone, TimeZone newTimeZone)
          Given a time with a time zone, calculate the corresponding time in another time zone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeUtils

public TimeUtils()
Method Detail

min

public static Time min(Time t1,
                       Time t2)
Finds the minimum of two times.

Parameters:
t1 - The first time.
t2 - The last time
Returns:
The minimum (i.e. earliest) of the two times.

max

public static Time max(Time t1,
                       Time t2)
Finds the maximum of two times.

Parameters:
t1 - The first time.
t2 - The last time
Returns:
The maximum (i.e. latest) of the two times.

min

public static DayDate min(DayDate d1,
                          DayDate d2)
Finds the minimum of two dates.

Parameters:
d1 - The first date.
d2 - The last date
Returns:
The minimum (i.e. earliest) of the two date.

max

public static DayDate max(DayDate d1,
                          DayDate d2)
Finds the maximum of two dates.

Parameters:
d1 - The first time.
d2 - The last time
Returns:
The maximum (i.e. latest) of the two dates.

min

public static TimeOfDay min(TimeOfDay t1,
                            TimeOfDay t2)
Finds the minimum of two times.

Parameters:
t1 - The first time.
t2 - The last time
Returns:
The minimum (i.e. earliest) of the two times.

max

public static TimeOfDay max(TimeOfDay t1,
                            TimeOfDay t2)
Finds the maximum of two times.

Parameters:
t1 - The first time.
t2 - The last time
Returns:
The maximum (i.e. latest) of the two times.

differenceInDays

public static int differenceInDays(Time later,
                                   Time earlier)
Calculates the difference in whole days between the two given times. Only the date part of the timestamp is considered, so the difference between 2011-06-04 00:01 and 2011-06-03 23:59 is one day. The sign of this difference assumes that the first argument is later than the second argument, if not, the calculated difference will be negative. Two times representing the same day will have zero difference.

Parameters:
later - The first time to compare.
earlier - The second time to compare.
Returns:
The difference in whole days between the two given times. This is positive if the first argument represents a later day than the second argument, negative if the first argument represents an earlier day than the second argument, and zero if both arguments represent the same day.

differenceInDays

public static int differenceInDays(DayDate later,
                                   DayDate earlier)
Calculates the difference in whole days between the two given date. For instance, the difference between 2011-06-04 and 2011-06-03 is one day. The sign of this difference assumes that the first argument is later than the second argument, if not, the calculated difference will be negative. Two arguments representing the same day will have zero difference.

Parameters:
later - The first time to compare.
earlier - The second time to compare.
Returns:
The difference in whole days between the two given dates. This is positive if the first argument represents a later day than the second argument, negative if the first argument represents an earlier day than the second argument, and zero if both arguments represent the same day.

differenceInMillis

public static long differenceInMillis(Time later,
                                      Time earlier)
Calculates the difference in milliseconds between the two given times. The sign of this difference assumes that the first argument is later than the second argument, if not, the calculated difference will be negative. Two arguments representing the same time will have zero difference.

Parameters:
later - The first time to compare.
earlier - The second time to compare.
Returns:
The difference in milliseconds between the two given times. This is positive if the first argument represents a later time than the second argument, negative if the first argument represents an earlier time than the second argument, and zero if both arguments represent the same time.

differenceInMillis

public static long differenceInMillis(TimeOfDay later,
                                      TimeOfDay earlier)
Calculates the difference in milliseconds between the two given times of day. The sign of this difference assumes that the first argument is later than the second argument, if not, the calculated difference will be negative. Two arguments representing the same time of day will have zero difference.

Parameters:
later - The first time to compare.
earlier - The second time to compare.
Returns:
The difference in milliseconds between the two given times of day. This is positive if the first argument represents a later time of day than the second argument, negative if the first argument represents an earlier time of day than the second argument, and zero if both arguments represent the same time of day.

moveToTimeZone

public static Time moveToTimeZone(Time time,
                                  TimeZone timeZone,
                                  TimeZone newTimeZone)
Given a time with a time zone, calculate the corresponding time in another time zone.

Parameters:
time - The time.
timeZone - The time zone.
newTimeZone - The other time zone, to which the local time is moved.
Returns:
The time in the other time zone.


Copyright © 2013. All Rights Reserved.