prefuse.util
Class TimeLib

java.lang.Object
  extended by prefuse.util.TimeLib

public class TimeLib
extends java.lang.Object

Library routines for dealing with times and time spans. All time values are given as long values, indicating the number of milliseconds since the epoch (January 1, 1970). This is the same time format returned by the System.currentTimeMillis() method.

Author:
jeffrey heer

Field Summary
static int CENTURY
          Represents a century, 100 years
static int DECADE
          Represents a decade, 10 years
static int MILLENIUM
          Represents a millenium, 1000 years.
 
Method Summary
static java.util.Calendar clearTo(java.util.Calendar c, int field)
          Clear the given calendar, setting to zero all time values less than or equal to that of the given field.
static int get(java.util.Calendar c, int field)
          Get the value of the given time field for a Calendar.
static long getClearedTime(long t, java.util.Calendar c, int field)
          Get the timestamp resulting from clearing (setting to zero) all time values less than or equal to that of the given field.
static long getDate(java.util.Calendar c, int year, int month, int day)
          Get the timestamp for the given year, month, and, day.
static java.util.Date getDate(java.lang.Class type, long d)
          Get a new Date instance of the specified subclass and given long value.
static long getTime(java.util.Calendar c, int hour, int minute, int second)
          Get a timestamp for the given hour, minute, and second.
static int getUnitsBetween(long t0, long t1, int field)
          Get the number of time units between the two given timestamps.
static void increment(java.util.Calendar c, int field, int val)
          Increment a calendar by a given number of time units.
static boolean isMultiYear(int field)
          Indicates if a field value indicates a timespan greater than one year.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MILLENIUM

public static final int MILLENIUM
Represents a millenium, 1000 years.

See Also:
Constant Field Values

CENTURY

public static final int CENTURY
Represents a century, 100 years

See Also:
Constant Field Values

DECADE

public static final int DECADE
Represents a decade, 10 years

See Also:
Constant Field Values
Method Detail

getUnitsBetween

public static int getUnitsBetween(long t0,
                                  long t1,
                                  int field)
Get the number of time units between the two given timestamps.

Parameters:
t0 - the first timestamp (as a long)
t1 - the second timestamp (as a long)
field - the time unit to use, one of the Calendar fields, or one of the extended fields provided by this class (MILLENIUM, CENTURY, or DECADE).
Returns:
the number of time units between the two timestamps

increment

public static void increment(java.util.Calendar c,
                             int field,
                             int val)
Increment a calendar by a given number of time units.

Parameters:
c - the calendar to increment
field - the time unit to increment, one of the Calendar fields, or one of the extended fields provided by this class (MILLENIUM, CENTURY, or DECADE).
val - the number of time units to increment by

get

public static int get(java.util.Calendar c,
                      int field)
Get the value of the given time field for a Calendar. Just like the Calendar.get(int) method, but include support for the extended fields provided by this class (MILLENIUM, CENTURY, or DECADE).

Parameters:
c - the Calendar
field - the time field
Returns:
the value of the time field for the given calendar

getDate

public static long getDate(java.util.Calendar c,
                           int year,
                           int month,
                           int day)
Get the timestamp for the given year, month, and, day.

Parameters:
c - a Calendar to use to help compute the result. The state of the Calendar will be overwritten.
year - the year to look up
month - the month to look up (months start at 0==January)
day - the day to look up
Returns:
the timestamp for the given date

getTime

public static long getTime(java.util.Calendar c,
                           int hour,
                           int minute,
                           int second)
Get a timestamp for the given hour, minute, and second. The date will be assumed to be January 1, 1970.

Parameters:
c - a Calendar to use to help compute the result. The state of the Calendar will be overwritten.
hour - the hour, on a 24 hour clock
minute - the minute value
second - the seconds value
Returns:
the timestamp for the given date

getDate

public static java.util.Date getDate(java.lang.Class type,
                                     long d)
Get a new Date instance of the specified subclass and given long value.

Parameters:
type - the concrete subclass of the Date instance, must be an instance of subclass of java.util.Date
d - the date/time value as a long
Returns:
the new Date instance, or null if the class type is not valid

getClearedTime

public static long getClearedTime(long t,
                                  java.util.Calendar c,
                                  int field)
Get the timestamp resulting from clearing (setting to zero) all time values less than or equal to that of the given field. For example, clearing to Calendar.HOUR will floor the time to nearest hour which occurred before or at the given time (e.g., 1:32 --> 1:30).

Parameters:
t - the reference time
c - a Calendar instance used to help compute the value, the state of the Calendar will be overwritten.
field - the time field to clear to, one of the Calendar fields, or one of the extended fields provided by this class (MILLENIUM, CENTURY, or DECADE).
Returns:
the cleared time

clearTo

public static java.util.Calendar clearTo(java.util.Calendar c,
                                         int field)
Clear the given calendar, setting to zero all time values less than or equal to that of the given field. For example, clearing to Calendar.HOUR will floor the time to nearest hour which occurred before or at the given time (e.g., 1:32 --> 1:30).

Parameters:
c - the Calendar to clear
field - the time field to clear to, one of the Calendar fields, or one of the extended fields provided by this class (MILLENIUM, CENTURY, or DECADE).
Returns:
the original Calendar reference, now set to the cleared time

isMultiYear

public static boolean isMultiYear(int field)
Indicates if a field value indicates a timespan greater than one year. These multi-year spans are the extended fields introduced by this class (MILLENIUM, CENTURY, and DECADE).

Parameters:
field - the time field
Returns:
true if the field is multi-year, false otherwise


Copyright © 2007 Regents of the University of California