org.dspace.content
Class DCDate

java.lang.Object
  extended by org.dspace.content.DCDate

public class DCDate
extends Object

Dublin Core date utility class

Dates in the DSpace database are held in the ISO 8601 format. They are always stored in UTC, converting to and from the current time zone.

YYYY-MM-DDThh:mm:ss

There are four levels of granularity, depending on how much date information is available: year, month, day, time.

Examples: 1994-05-03T15:30:24,1995-10-04, 2001-10,1975 The main() method is a simple test program: run it with an optional first argument that is a date string to decode, and it prints the results of all the accessor methods.

Version:
$Revision: 4892 $
Author:
Robert Tansley, Larry Stone

Constructor Summary
DCDate()
          Construct a clean date
DCDate(Date date)
          Construct a date object from a Java Date object.
DCDate(String fromDC)
          Construct a date from a Dublin Core value
 
Method Summary
 String displayDate(boolean showTime, boolean isLocalTime, Locale locale)
          Format a human-readable version of the DCDate, with optional time.
static DCDate getCurrent()
          Get a date representing the current instant in time.
 int getDay()
          Get the day, adjusting for current time zone.
 int getDayGMT()
          Get the day in GMT.
 int getHour()
          Get the hour, adjusting for current time zone.
 int getHourGMT()
          Get the hour in GMT.
 int getMinute()
          Get the minute, adjusting for current time zone.
 int getMinuteGMT()
          Get the minute in GMT.
 int getMonth()
          Get the month, adjusting for current time zone.
 int getMonthGMT()
          Get the month in GMT.
static String getMonthName(int m, Locale locale)
          Get a month's name for a month between 1 and 12.
 int getSecond()
          Get the second, adjusting for current time zone.
 int getSecondGMT()
          Get the second in GMT.
 int getYear()
          Get the year, adjusting for current time zone.
 int getYearGMT()
          Get the year in GMT.
static void main(String[] args)
          Simple test program Usage: java org.dspace.content.DCdate [DCDate | -l yyyy [mm [dd ..]]] ] where "DCDate" is the kind of value that would be in metadata, e.g.
 void setDateLocal(int yyyy, int mm, int dd, int hh, int mn, int ss)
          Set the date.
 Date toDate()
          Get the date as a Java Date object
 String toString()
          Get the date as a string to put back in the Dublin Core
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DCDate

public DCDate()
Construct a clean date


DCDate

public DCDate(Date date)
Construct a date object from a Java Date object.

Parameters:
date - the Java Date object.

DCDate

public DCDate(String fromDC)
Construct a date from a Dublin Core value

Parameters:
fromDC - the date string, in ISO 8601 (no timezone, always use UTC/GMT)
Method Detail

getCurrent

public static DCDate getCurrent()
Get a date representing the current instant in time.

Returns:
a DSpaceDate object representing the current instant.

toString

public String toString()
Get the date as a string to put back in the Dublin Core

Overrides:
toString in class Object
Returns:
The date as a string.

toDate

public Date toDate()
Get the date as a Java Date object

Returns:
a Date object

setDateLocal

public void setDateLocal(int yyyy,
                         int mm,
                         int dd,
                         int hh,
                         int mn,
                         int ss)
Set the date. The date passed in is assumed to be in the current time zone, and is adjusting to fit the current time zone. Unknown values should be given as -1.

Parameters:
yyyy - the year
mm - the month
dd - the day
hh - the hours
mn - the minutes
ss - the seconds

getYear

public int getYear()
Get the year, adjusting for current time zone.

Returns:
the year

getMonth

public int getMonth()
Get the month, adjusting for current time zone.

Returns:
the month

getDay

public int getDay()
Get the day, adjusting for current time zone.

Returns:
the day

getHour

public int getHour()
Get the hour, adjusting for current time zone.

Returns:
the hour

getMinute

public int getMinute()
Get the minute, adjusting for current time zone.

Returns:
the minute

getSecond

public int getSecond()
Get the second, adjusting for current time zone.

Returns:
the second

getYearGMT

public int getYearGMT()
Get the year in GMT.

Returns:
the year

getMonthGMT

public int getMonthGMT()
Get the month in GMT.

Returns:
the month

getDayGMT

public int getDayGMT()
Get the day in GMT.

Returns:
the day

getHourGMT

public int getHourGMT()
Get the hour in GMT.

Returns:
the hour

getMinuteGMT

public int getMinuteGMT()
Get the minute in GMT.

Returns:
the minute

getSecondGMT

public int getSecondGMT()
Get the second in GMT.

Returns:
the second

getMonthName

public static String getMonthName(int m,
                                  Locale locale)
Get a month's name for a month between 1 and 12. Any invalid month value (e.g. 0 or -1) will return a value of "Unspecified".

Parameters:
m - the month number
Returns:
the month name.

main

public static void main(String[] args)
                 throws Exception
Simple test program Usage: java org.dspace.content.DCdate [DCDate | -l yyyy [mm [dd ..]]] ] where "DCDate" is the kind of value that would be in metadata, e.g. "2006", "2006-02-03", etc. (-l form tests local time parsing) Default is to use current time.

Throws:
Exception

displayDate

public String displayDate(boolean showTime,
                          boolean isLocalTime,
                          Locale locale)
Format a human-readable version of the DCDate, with optional time. This needs to be in DCDate because it depends on the granularity of the original time. FIXME: This should probably be replaced with a localized DateFormat.

Parameters:
showTime - if true, display the time with the date
isLocalTime - if true, adjust for local time zone, otherwise GMT
locale - locale of the user
Returns:
String with the date in a human-readable form.


Copyright © 2010 DuraSpace. All Rights Reserved.