Package org.dspace.content
Class DCDate
java.lang.Object
org.dspace.content.DCDate
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. In practice only dates with a time component need to be converted.
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
- Author:
- Robert Tansley, Larry Stone
-
Constructor Summary
ConstructorsConstructorDescriptionDCDate(int yyyy, int mm, int dd, int hh, int mn, int ss) Construct a date object from a bunch of component parts.Construct a date from a Dublin Core valueDCDate(ZonedDateTime date) Construct a date object from a JavaInstantobject. -
Method Summary
Modifier and TypeMethodDescriptiondisplayDate(boolean showTime, boolean isLocalTime, Locale locale) Format a human-readable version of the DCDate, with optional time.displayLocalDate(boolean showTime, Locale locale) displayUTCDate(boolean showTime, Locale locale) static DCDateGet a date representing the current instant in UTC time.intgetDay()Get the day, adjusting for current time zone.intGet the day in UTC.intgetHour()Get the hour, adjusting for current time zone.intGet the hour in UTC.intGet the minute, adjusting for current time zone.intGet 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.intGet the month in UTC.intGet the second, adjusting for current time zone.intGet the second in UTC.intgetYear()Get the year, adjusting for current time zone.intGet the year in UTC.toDate()Get the date as a Java ZonedDateTime object in UTC timezone.toString()Get the date as a string to put back in the Dublin Core.
-
Constructor Details
-
DCDate
Construct a date object from a JavaInstantobject.- Parameters:
date- the JavaInstantobject.
-
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
Construct a date from a Dublin Core value- Parameters:
fromDC- the date string, in ISO 8601 (no timezone, always use UTC)
-
-
Method Details
-
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
Get the date as a string to put back in the Dublin Core. Use the UTC/GMT calendar version. -
toDate
Get the date as a Java ZonedDateTime object in UTC timezone.- Returns:
- a ZonedDateTime object
-
displayDate
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.
-
displayLocalDate
-
displayUTCDate
-
getCurrent
Get a date representing the current instant in UTC time.- Returns:
- a DSpaceDate object representing the current instant.
-
getMonthName
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.
-