Package org.dspace.content
Class DCDate
- java.lang.Object
-
- org.dspace.content.DCDate
-
public class DCDate extends Object
Dublin Core date utility classDates 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. In practice only dates with a time component need to be converted.
YYYY-MM-DDThh:mm:ssThere 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- Author:
- Robert Tansley, Larry Stone
-
-
Constructor Summary
Constructors Constructor Description DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss)Construct a date object from a bunch of component parts.DCDate(String fromDC)Construct a date from a Dublin Core valueDCDate(Date date)Construct a date object from a JavaDateobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringdisplayDate(boolean showTime, boolean isLocalTime, Locale locale)Format a human-readable version of the DCDate, with optional time.StringdisplayLocalDate(boolean showTime, Locale locale)StringdisplayUTCDate(boolean showTime, Locale locale)static DCDategetCurrent()Get a date representing the current instant in time.intgetDay()Get the day, adjusting for current time zone.intgetDayUTC()Get the day in UTC.intgetHour()Get the hour, adjusting for current time zone.intgetHourUTC()Get the hour in UTC.intgetMinute()Get the minute, adjusting for current time zone.intgetMinuteUTC()Get the minute in UTC.intgetMonth()Get the month, adjusting for current time zone.static StringgetMonthName(int m, Locale locale)Get a month's name for a month between 1 and 12.intgetMonthUTC()Get the month in UTC.intgetSecond()Get the second, adjusting for current time zone.intgetSecondUTC()Get the second in UTC.intgetYear()Get the year, adjusting for current time zone.intgetYearUTC()Get the year in UTC.DatetoDate()Get the date as a Java Date object.StringtoString()Get the date as a string to put back in the Dublin Core.
-
-
-
Constructor Detail
-
DCDate
public DCDate(Date date)
Construct a date object from a JavaDateobject.- Parameters:
date- the JavaDateobject.
-
DCDate
public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss)Construct a date object from a bunch of component parts. The date passed in is assumed to be in the current time zone. Unknown values should be given as -1.- Parameters:
yyyy- the yearmm- the monthdd- the dayhh- the hoursmn- the minutesss- the seconds
-
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)
-
-
Method Detail
-
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
-
getYearUTC
public int getYearUTC()
Get the year in UTC.- Returns:
- the year
-
getMonthUTC
public int getMonthUTC()
Get the month in UTC.- Returns:
- the month
-
getDayUTC
public int getDayUTC()
Get the day in UTC.- Returns:
- the day
-
getHourUTC
public int getHourUTC()
Get the hour in UTC.- Returns:
- the hour
-
getMinuteUTC
public int getMinuteUTC()
Get the minute in UTC.- Returns:
- the minute
-
getSecondUTC
public int getSecondUTC()
Get the second in UTC.- Returns:
- the second
-
toString
public String toString()
Get the date as a string to put back in the Dublin Core. Use the UTC/GMT calendar version.
-
toDate
public Date toDate()
Get the date as a Java Date object.- Returns:
- a Date object
-
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 dateisLocalTime- if true, adjust for local time zone, otherwise UTClocale- locale of the user- Returns:
- String with the date in a human-readable form.
-
getCurrent
public static DCDate getCurrent()
Get a date representing the current instant in time.- Returns:
- a DSpaceDate object representing the current instant.
-
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 numberlocale- which locale to render the month name in- Returns:
- the month name.
-
-