net.sf.mpxj.utility
Class DateUtility

java.lang.Object
  extended by net.sf.mpxj.utility.DateUtility

public final class DateUtility
extends Object

Utility methods for manipulating dates.


Field Summary
static Date FIRST_DATE
          First date supported by Microsoft Project: January 01 00:00:00 1984.
static Date LAST_DATE
          Last date supported by Microsoft Project: Friday December 31 23:59:00 2049.
 
Method Summary
static int compare(Date d1, Date d2)
          Compare two dates, handling null values.
static int compare(Date startDate, Date endDate, Date targetDate)
          This method compares a target date with a date range.
static int compare(Date startDate, Date endDate, long targetDate)
          This method compares a target date with a date range.
static Date getCanonicalTime(Date date)
          This method resets the date part of a date time value to a standard date (1/1/1).
static Date getDateFromLong(long date)
          Creates a date from the equivalent long value.
static Date getDayEndDate(Date date)
          Returns a new Date instance whose value represents the end of the day (i.e.
static Date getDayStartDate(Date date)
          Returns a new Date instance whose value represents the start of the day (i.e.
static Date getTime(int hour, int minutes)
          Create a Date instance representing a specific time.
static Date getTimestampFromLong(long timestamp)
          Creates a timestamp from the equivalent long value.
static Duration getVariance(Task task, Date date1, Date date2, TimeUnit format)
          This utility method calculates the difference in working time between two dates, given the context of a task.
static void setTime(Calendar cal, Date time)
          Given a date represented by a Calendar instance, set the time component of the date based on the hours and minutes of the time supplied by the Date instance.
static Date setTime(Date date, Date canonicalTime)
          Given a date represented by a Date instance, set the time component of the date based on the hours and minutes of the time supplied by the Date instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST_DATE

public static final Date FIRST_DATE
First date supported by Microsoft Project: January 01 00:00:00 1984.


LAST_DATE

public static final Date LAST_DATE
Last date supported by Microsoft Project: Friday December 31 23:59:00 2049.

Method Detail

getDayStartDate

public static Date getDayStartDate(Date date)
Returns a new Date instance whose value represents the start of the day (i.e. the time of day is 00:00:00.000)

Parameters:
date - date to convert
Returns:
day start date

getDayEndDate

public static Date getDayEndDate(Date date)
Returns a new Date instance whose value represents the end of the day (i.e. the time of days is 11:59:59.999)

Parameters:
date - date to convert
Returns:
day start date

getCanonicalTime

public static Date getCanonicalTime(Date date)
This method resets the date part of a date time value to a standard date (1/1/1). This is used to allow times to be compared and manipulated.

Parameters:
date - date time value
Returns:
date time with date set to a standard value

compare

public static int compare(Date startDate,
                          Date endDate,
                          Date targetDate)
This method compares a target date with a date range. The method will return 0 if the date is within the range, less than zero if the date is before the range starts, and greater than zero if the date is after the range ends.

Parameters:
startDate - range start date
endDate - range end date
targetDate - target date
Returns:
comparison result

compare

public static int compare(Date startDate,
                          Date endDate,
                          long targetDate)
This method compares a target date with a date range. The method will return 0 if the date is within the range, less than zero if the date is before the range starts, and greater than zero if the date is after the range ends.

Parameters:
startDate - range start date
endDate - range end date
targetDate - target date in milliseconds
Returns:
comparison result

compare

public static int compare(Date d1,
                          Date d2)
Compare two dates, handling null values.

Parameters:
d1 - Date instance
d2 - Date instance
Returns:
int comparison result

getVariance

public static Duration getVariance(Task task,
                                   Date date1,
                                   Date date2,
                                   TimeUnit format)
This utility method calculates the difference in working time between two dates, given the context of a task.

Parameters:
task - parent task
date1 - first date
date2 - second date
format - required format for the resulting duration
Returns:
difference in working time between the two dates

getDateFromLong

public static Date getDateFromLong(long date)
Creates a date from the equivalent long value. This conversion takes account of the time zone.

Parameters:
date - date expressed as a long integer
Returns:
new Date instance

getTimestampFromLong

public static Date getTimestampFromLong(long timestamp)
Creates a timestamp from the equivalent long value. This conversion takes account of the time zone and any daylight savings time.

Parameters:
timestamp - timestamp expressed as a long integer
Returns:
new Date instance

getTime

public static Date getTime(int hour,
                           int minutes)
Create a Date instance representing a specific time.

Parameters:
hour - hour 0-23
minutes - minutes 0-59
Returns:
new Date instance

setTime

public static void setTime(Calendar cal,
                           Date time)
Given a date represented by a Calendar instance, set the time component of the date based on the hours and minutes of the time supplied by the Date instance.

Parameters:
cal - Calendar instance representing the date
time - Date instance representing the time of day

setTime

public static Date setTime(Date date,
                           Date canonicalTime)
Given a date represented by a Date instance, set the time component of the date based on the hours and minutes of the time supplied by the Date instance.

Parameters:
date - Date instance representing the date
canonicalTime - Date instance representing the time of day
Returns:
new Date instance with the required time set


Copyright © 2012. All Rights Reserved.