Class 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. 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

    Version:
    $Revision$
    Author:
    Robert Tansley, Larry Stone
    • Constructor Detail

      • DCDate

        public DCDate​(Date date)
        Construct a date object from a Java Date object.
        Parameters:
        date - the Java Date object.
      • 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 year
        mm - the month
        dd - the day
        hh - the hours
        mn - the minutes
        ss - 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.
        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
      • 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 UTC
        locale - locale of the user
        Returns:
        String with the date in a human-readable form.
      • displayLocalDate

        public String displayLocalDate​(boolean showTime,
                                       Locale locale)
      • displayUTCDate

        public String displayUTCDate​(boolean showTime,
                                     Locale locale)
      • 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 number
        locale - which locale to render the month name in
        Returns:
        the month name.