Class DateType


  • public class DateType
    extends Object
    Implements the thredds "dateType" and "dateTypeFormatted" XML element types. This is mostly a general way to specify dates in a string. It allows a date to mean "present". "Present" always sorts after any date, including dates in the future. It allows an optional attribute called "type" which is an enumeration like "created", "modified", etc taken from Dublin Core vocabulary.

    A DateType can be specified in the following ways:

    1. an xsd:date, with form "CCYY-MM-DD"
    2. an xsd:dateTime with form "CCYY-MM-DDThh:mm:ss"
    3. a valid udunits date string
    4. the string "present"
    See Also:
    THREDDS dateType
    • Constructor Detail

      • DateType

        public DateType​(boolean isPresent,
                        Date date)
        Constructor using a java.util.Date
        Parameters:
        isPresent - if true, this represents the "present time"
        date - the given Date
      • DateType

        public DateType​(CalendarDate date)
        Constructor using a java.util.CalendarDate
        Parameters:
        date - the given CalendarDate
      • DateType

        public DateType()
        no argument constructor for beans
      • DateType

        public DateType​(DateType src)
        copy constructor
        Parameters:
        src - copy from here
      • DateType

        public DateType​(String text,
                        String format,
                        String type)
                 throws ParseException
        Constructor.
        Parameters:
        text - string representation
        format - using java.text.SimpleDateFormat, or null
        type - type of date, or null
        Throws:
        ParseException - if error parsing text
      • DateType

        public DateType​(String text,
                        String format,
                        String type,
                        Calendar cal2)
                 throws ParseException
        Constructor.
        Parameters:
        text - string representation
        format - using java.text.SimpleDateFormat, or null
        type - type of date, or null
        cal2 - ucar.nc2.time.Calendar of date, or null
        Throws:
        ParseException - if error parsing text
    • Method Detail

      • getDate

        public Date getDate()
        Deprecated.
        use getCalendarDate()
        Get this as a Date. Does not handle non-standard Calendars.
        Returns:
        Date
      • getCalendarDate

        public CalendarDate getCalendarDate()
        Get this as a CalendarDate
        Returns:
        CalendarDate
      • isPresent

        public boolean isPresent()
        Does this represent the present time.
        Returns:
        true if present time.
      • isBlank

        public boolean isBlank()
        Was blank text passed to the constructor.
        Returns:
        true if blank text passed to the constructor.
      • getText

        public String getText()
        Get a text representation.
        Returns:
        text representation
      • getFormat

        public String getFormat()
        Get the SimpleDateFormat format for parsing the text.
        Returns:
        SimpleDateFormat format, or null
      • getType

        public String getType()
        Get the type of Date.
        Returns:
        type of Date, or null
      • setType

        public DateType setType​(String type)
        Set the type of Date.
        Parameters:
        type - type of Date
      • before

        public boolean before​(Date d)
        Is this date before the given date. if isPresent, always false.
        Parameters:
        d - test against this date
        Returns:
        true if this date before the given date
      • before

        public boolean before​(DateType d)
        Is this date before the given date. if d.isPresent, always true, else if this.isPresent, false.
        Parameters:
        d - test against this date
        Returns:
        true if this date before the given date
      • after

        public boolean after​(Date d)
        Is this date after the given date. if isPresent, always true.
        Parameters:
        d - test against this date
        Returns:
        true if this date after the given date
      • toDateString

        public String toDateString()
        Same as DateFormatter.toDateOnlyString()
        Returns:
        formatted date
      • toDateTimeString

        public String toDateTimeString()
        Same as CalendarDateFormatter.toDateTimeStringISO
        Returns:
        formatted date
      • toDateTimeStringISO

        public String toDateTimeStringISO()
        Get ISO formatted string
        Returns:
        ISO formatted date
      • toString

        public String toString()
        String representation
        Overrides:
        toString in class Object
        Returns:
        getText()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object