to.etc.util
Class DateUtil

java.lang.Object
  extended by to.etc.util.DateUtil

public class DateUtil
extends java.lang.Object

Static date/time utiility class.

Author:
Frits Jalvingh Created on Feb 28, 2007

Field Summary
static java.util.Date FUTURE
          A fixed date way into the future.
 
Method Summary
static java.util.Date addDays(java.util.Date in, int days)
           
static boolean between(java.util.Date start, java.util.Date end, java.util.Date v)
           
static java.util.Date calculateDurationEndInSec(java.util.Date start, int durationInSeconds)
           
static void clearTime(java.util.Calendar cal)
          Clears the entire time portion of a Calendar.
static java.util.Date dateFor(int year, int month, int day)
           
static java.util.Date dateFor(int year, int month, int day, int hour, int minute, int sec, int mils)
           
static java.util.Date dateFromDateTime(java.util.Date coredate, java.lang.String timestring)
          Decraps the separate date / time found in the VP database into a normal date containing the time.
static long decodeTime(java.lang.String timestring)
          Decodes a time string, encoded as hh:mm:ss.mmmm where ss.mmmm are optional.
static java.util.Date dumbEndOfDayDate(java.util.Date dt)
          INTERNAL DAO USE ONLY -- This returns a date/ which ends at 23:59 of the day passed.
static java.lang.String encodeTimeInMS(long millis, int nfields, boolean shortest)
          Quick conversion of time to a string for presentation pps.
static java.lang.String extractTimeString(java.util.Date dt, int size)
          Extracts the dumb time field from a date.
static java.util.Date incrementDate(java.util.Date dt, int field, int amount)
          Returns date incremented for specified value.
static void main(java.lang.String[] args)
           
static boolean overlaps(java.util.Date s1, java.util.Date e1, java.util.Date s2, java.util.Date e2)
           
static void setDate(java.util.Calendar cal, int year, int month, int day)
           
static java.util.Date setDateOnly(java.util.Date finisheddate, java.util.Date dt)
          Updates the date part of a date only, leaving the time part unaltered.
static void setTime(java.util.Calendar cal, int h, int m, int s, int ms)
           
static java.util.Date tomorrow(java.util.Date dt)
          Calculates the date for 0:00 the day after (tomorrow).
static java.util.Date truncateDate(java.util.Date dt)
           
static void truncateDate(java.util.Date dest, java.util.Date dt)
           
static java.util.Date yearStartDate(int year)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FUTURE

public static final java.util.Date FUTURE
A fixed date way into the future.

Method Detail

dateFromDateTime

public static java.util.Date dateFromDateTime(java.util.Date coredate,
                                              java.lang.String timestring)
Decraps the separate date / time found in the VP database into a normal date containing the time. This needs to be as speedy as possible.

Parameters:
coredate -
timestring -
Returns:

encodeTimeInMS

public static java.lang.String encodeTimeInMS(long millis,
                                              int nfields,
                                              boolean shortest)
Quick conversion of time to a string for presentation pps.

Parameters:
millis - Time in millis.
nfields - The number of fields to show: 1 = hours only, 2= hh:mm, 3=h:mm:ss. Warning: the fields that are not shown do not "round up" the shown fields! So if you use nfields=1 for 18:45 the hour shown would be 18, not 19!
shortest - When set this truncates the time display when components are zero. So for 18:00:0) this would render '18'; for 18:21:00 this would render 18:21.
Returns:

decodeTime

public static long decodeTime(java.lang.String timestring)
Decodes a time string, encoded as hh:mm:ss.mmmm where ss.mmmm are optional. If the field is invalid this returns -1, else it returns the #of ms representing the time.

Parameters:
time -
Returns:

extractTimeString

public static java.lang.String extractTimeString(java.util.Date dt,
                                                 int size)
Extracts the dumb time field from a date.

Parameters:
dt -
Returns:

truncateDate

public static java.util.Date truncateDate(java.util.Date dt)

incrementDate

public static java.util.Date incrementDate(java.util.Date dt,
                                           int field,
                                           int amount)
Returns date incremented for specified value.

Parameters:
dt -
field - see Calendar.add(int, int)
amount - see Calendar.add(int, int)
Returns:
In case of dt is null returns null

truncateDate

public static void truncateDate(java.util.Date dest,
                                java.util.Date dt)

tomorrow

public static java.util.Date tomorrow(java.util.Date dt)
Calculates the date for 0:00 the day after (tomorrow). Works like the EndOfDay but returns one minute later.

Parameters:
ts -
Returns:

dumbEndOfDayDate

public static java.util.Date dumbEndOfDayDate(java.util.Date dt)
INTERNAL DAO USE ONLY -- This returns a date/ which ends at 23:59 of the day passed. It is used within DAO's only to allow Hibernate to query split date/time fields.

Parameters:
dt -
Returns:

clearTime

public static void clearTime(java.util.Calendar cal)
Clears the entire time portion of a Calendar.

Parameters:
cal -

yearStartDate

public static java.util.Date yearStartDate(int year)

calculateDurationEndInSec

public static java.util.Date calculateDurationEndInSec(java.util.Date start,
                                                       int durationInSeconds)

dateFor

public static java.util.Date dateFor(int year,
                                     int month,
                                     int day)

setDate

public static void setDate(java.util.Calendar cal,
                           int year,
                           int month,
                           int day)

dateFor

public static java.util.Date dateFor(int year,
                                     int month,
                                     int day,
                                     int hour,
                                     int minute,
                                     int sec,
                                     int mils)

setTime

public static void setTime(java.util.Calendar cal,
                           int h,
                           int m,
                           int s,
                           int ms)

addDays

public static java.util.Date addDays(java.util.Date in,
                                     int days)

between

public static boolean between(java.util.Date start,
                              java.util.Date end,
                              java.util.Date v)

overlaps

public static boolean overlaps(java.util.Date s1,
                               java.util.Date e1,
                               java.util.Date s2,
                               java.util.Date e2)

main

public static void main(java.lang.String[] args)

setDateOnly

public static java.util.Date setDateOnly(java.util.Date finisheddate,
                                         java.util.Date dt)
Updates the date part of a date only, leaving the time part unaltered.

Parameters:
finisheddate -
dt -
Returns: