Package ucar.nc2.units
Class DateType
- java.lang.Object
-
- ucar.nc2.units.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:- an xsd:date, with form "CCYY-MM-DD"
- an xsd:dateTime with form "CCYY-MM-DDThh:mm:ss"
- a valid udunits date string
- the string "present"
- See Also:
- THREDDS dateType
-
-
Constructor Summary
Constructors Constructor Description DateType()
no argument constructor for beansDateType(boolean isPresent, Date date)
Constructor using a java.util.DateDateType(String text, String format, String type)
Constructor.DateType(String text, String format, String type, Calendar cal2)
Constructor.DateType(CalendarDate date)
Constructor using a java.util.CalendarDateDateType(DateType src)
copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DateType
add(TimeDuration d)
DateType
add(TimeUnit d)
boolean
after(Date d)
Is this date after the given date.boolean
before(Date d)
Is this date before the given date.boolean
before(DateType d)
Is this date before the given date.boolean
equals(Object o)
CalendarDate
getCalendarDate()
Get this as a CalendarDateDate
getDate()
Deprecated.use getCalendarDate()String
getFormat()
Get the SimpleDateFormat format for parsing the text.String
getText()
Get a text representation.String
getType()
Get the type of Date.int
hashCode()
boolean
isBlank()
Was blank text passed to the constructor.boolean
isPresent()
Does this represent the present time.DateType
setType(String type)
Set the type of Date.DateType
subtract(TimeDuration d)
DateType
subtract(TimeUnit d)
String
toDateString()
Same as DateFormatter.toDateOnlyString()String
toDateTimeString()
Same as CalendarDateFormatter.toDateTimeStringISOString
toDateTimeStringISO()
Get ISO formatted stringString
toString()
String representation
-
-
-
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 representationformat
- using java.text.SimpleDateFormat, or nulltype
- 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 representationformat
- using java.text.SimpleDateFormat, or nulltype
- type of date, or nullcal2
- 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
-
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
-
add
public DateType add(TimeDuration d)
-
subtract
public DateType subtract(TimeDuration d)
-
-