2.9.1: 2008-12-18

net.sf.basedb.core
Class DateUtil

java.lang.Object
  extended by net.sf.basedb.core.DateUtil

public class DateUtil
extends Object

Utility methods that will make it easier to handle date values. Especially, dates must be cloned whenver they are returned to or passed from client applications.

Version:
2.0
Author:
Nicklas

Field Summary
private static SimpleDateFormat DATE_FORMAT
           
 
Constructor Summary
DateUtil()
           
 
Method Summary
static Date copy(Date value)
          Get a copy of the date.
static String formatDate(Date d)
          Formats a date in yyyy-MM-dd format.
static Date parseString(String value)
          Parses a string to create a Date.
static Date setNotNullDate(Date value, String name)
          Make a copy of a Date object.
static Date setNullableDate(Date value, String name)
          Make a copy of a Date object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_FORMAT

private static final SimpleDateFormat DATE_FORMAT
Constructor Detail

DateUtil

public DateUtil()
Method Detail

setNullableDate

public static Date setNullableDate(Date value,
                                   String name)
Make a copy of a Date object. Null values are allowed.

Parameters:
value - The date to check
name - The name of the attribute to use if an exception is thrown
Returns:
A copy of the original date

setNotNullDate

public static Date setNotNullDate(Date value,
                                  String name)
                           throws InvalidUseOfNullException
Make a copy of a Date object. Null values are not allowed.

Parameters:
value - The date to check. Can not be null.
name - The name of the attribute to use if an exception is thrown
Returns:
A copy of the original date
Throws:
InvalidUseOfNullException - If the value parameter is null.

copy

public static Date copy(Date value)
Get a copy of the date. Null values are allowed.

Parameters:
value - Date value to copy
Returns:
A cloned Date object or null if argument is null.

parseString

public static Date parseString(String value)
                        throws InvalidDataException
Parses a string to create a Date. This method supports date in yyyy-MM-dd format or as long timevalues.

Parameters:
value - the String to be parsed
Returns:
a Date object
Throws:
InvalidDataException - if value isn't a valid date.

formatDate

public static String formatDate(Date d)
Formats a date in yyyy-MM-dd format.

Parameters:
d - The date to format.
Returns:
Formated date as a String.
Since:
2.2

2.9.1: 2008-12-18