fedora.server.utilities
Class DateUtility

java.lang.Object
  extended by fedora.server.utilities.DateUtility

public abstract class DateUtility
extends java.lang.Object

Title: DateUtility.java

Description: A collection of utility methods for performing

frequently required tasks.

Version:
$Id: DateUtility.java 6425 2007-12-17 17:17:27Z pangloss $
Author:
rlw@virginia.edu

Constructor Summary
DateUtility()
           
 
Method Summary
static java.lang.String convertDateToDateString(java.util.Date date)
           Converts an instance of java.util.Date into a String using the date format: yyyy-MM-ddZ.
static java.lang.String convertDateToString(java.util.Date date)
           Converts an instance of java.util.Date into a String using the date format: yyyy-MM-ddTHH:mm:ss.SSSZ.
static java.lang.String convertDateToString(java.util.Date date, boolean millis)
          Converts an instance of java.util.Date into an ISO 8601 String representation.
static java.lang.String convertDateToTimeString(java.util.Date date)
           Converts an instance of java.util.Date into a String using the date format: HH:mm:ss.SSSZ.
static java.lang.String convertDateToXSDString(java.util.Date date)
          Converts an instance of Date into the canonical lexical representation of an XSD dateTime with the following exceptions: - Dates before 1 CE (i.e.
static java.util.Date convertStringToDate(java.lang.String dateTime)
           Converts a datetime string into and instance of java.util.Date using the date format: yyyy-MM-ddTHH:mm:ss.SSSZ.
static java.util.Date parseDateAsUTC(java.lang.String dateString)
          Attempt to parse the given string of form: yyyy-MM-dd[THH:mm:ss[.SSS][Z]] as a Date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtility

public DateUtility()
Method Detail

convertStringToDate

public static java.util.Date convertStringToDate(java.lang.String dateTime)

Converts a datetime string into and instance of java.util.Date using the date format: yyyy-MM-ddTHH:mm:ss.SSSZ.

Follows Postel's Law (lenient about what it accepts, as long as it's sensible)

Parameters:
dateTime - A datetime string
Returns:
Corresponding instance of java.util.Date (returns null if dateTime string argument is empty string or null)

convertDateToString

public static java.lang.String convertDateToString(java.util.Date date)

Converts an instance of java.util.Date into a String using the date format: yyyy-MM-ddTHH:mm:ss.SSSZ.

Parameters:
date - Instance of java.util.Date.
Returns:
ISO 8601 String representation (yyyy-MM-ddTHH:mm:ss.SSSZ) of the Date argument or null if the Date argument is null.

convertDateToString

public static java.lang.String convertDateToString(java.util.Date date,
                                                   boolean millis)
Converts an instance of java.util.Date into an ISO 8601 String representation. Uses the date format yyyy-MM-ddTHH:mm:ss.SSSZ or yyyy-MM-ddTHH:mm:ssZ, depending on whether millisecond precision is desired.

Parameters:
date - Instance of java.util.Date.
millis - Whether or not the return value should include milliseconds.
Returns:
ISO 8601 String representation of the Date argument or null if the Date argument is null.

convertDateToXSDString

public static java.lang.String convertDateToXSDString(java.util.Date date)
Converts an instance of Date into the canonical lexical representation of an XSD dateTime with the following exceptions: - Dates before 1 CE (i.e. 1 AD) are handled according to ISO 8601:2000 Second Edition: "0000" is the lexical representation of 1 BCE "-0001" is the lexical representation of 2 BCE

Parameters:
date - Instance of java.util.Date.
Returns:
the lexical form of the XSD dateTime value, e.g. "2006-11-13T09:40:55.001Z".
See Also:
3.2.7.2 Canonical representation

convertDateToDateString

public static java.lang.String convertDateToDateString(java.util.Date date)

Converts an instance of java.util.Date into a String using the date format: yyyy-MM-ddZ.

Parameters:
date - Instance of java.util.Date.
Returns:
Corresponding date string (returns null if Date argument is null).

convertDateToTimeString

public static java.lang.String convertDateToTimeString(java.util.Date date)

Converts an instance of java.util.Date into a String using the date format: HH:mm:ss.SSSZ.

Parameters:
date - Instance of java.util.Date.
Returns:
Corresponding time string (returns null if Date argument is null).

parseDateAsUTC

public static java.util.Date parseDateAsUTC(java.lang.String dateString)
Attempt to parse the given string of form: yyyy-MM-dd[THH:mm:ss[.SSS][Z]] as a Date. If the string is not of that form, return null.

Parameters:
dateString - the date string to parse
Returns:
Date the date, if parse was successful; null otherwise