Asterisk-Java

org.asteriskjava.util
Class DateUtil

java.lang.Object
  extended by org.asteriskjava.util.DateUtil

public class DateUtil
extends java.lang.Object

Utility class to obtain the current date and allows to override with a fixed value for unit testing. Includes some convenience methods for date conversion.

Client code is not supposed to use this class.

Version:
$Id: DateUtil.java 1314 2009-05-28 12:24:54Z srt $
Author:
srt

Method Summary
static java.util.Date getDate()
          Returns the real current date or the date set with overrideCurrentDate().
static void overrideCurrentDate(java.util.Date currentDate)
          If set to a non null value uses the date given as current date on calls to getDate().
static java.util.Date parseDateTime(java.lang.String s)
          Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the default time zone.
static java.util.Date parseDateTime(java.lang.String s, java.util.TimeZone tz)
          Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the given time zone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

overrideCurrentDate

public static void overrideCurrentDate(java.util.Date currentDate)
If set to a non null value uses the date given as current date on calls to getDate(). Set to null to restore the normal behavior.

Parameters:
currentDate - the date to return on calls to getDate() or null to return the real current date.

getDate

public static java.util.Date getDate()
Returns the real current date or the date set with overrideCurrentDate().

Returns:
the real current date or the date set with overrideCurrentDate().

parseDateTime

public static java.util.Date parseDateTime(java.lang.String s)
Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the default time zone.

Parameters:
s - date string in the form of "yy-MM-dd HH:mm:ss"
Returns:
the corresponding Java date object or null if it is not parsable.

parseDateTime

public static java.util.Date parseDateTime(java.lang.String s,
                                           java.util.TimeZone tz)
Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the given time zone.

Parameters:
s - date string in the form of "yy-MM-dd HH:mm:ss"
tz - the timezone to use or null for the default time zone.
Returns:
the corresponding Java date object or null if it is not parsable.

Asterisk-Java

Copyright © 2004-2009 Stefan Reuter. All Rights Reserved.