ucar.nc2.units
Class DateType

java.lang.Object
  extended by 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:

  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"

Author:
john caron
See Also:
THREDDS dateType

Constructor Summary
DateType()
          no argument constructor for beans
DateType(boolean isPresent, Date date)
          Constructor using a java.util.Date
DateType(DateType src)
          copy constructor
DateType(String text, String format, String type)
          Constructor.
 
Method Summary
 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)
           
 Date getDate()
          Get this as a Date
 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()
           
static String hiddenProperties()
          For bean editing, public by accident.
 boolean isBlank()
          Was blank text passed to the constructor.
 boolean isPresent()
          Does this represent the present time.
static void main(String[] args)
          test
 void setDate(Date date)
          Set the Date.
 void 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 DateFormatter.toDateTimeString()
 String toDateTimeStringISO()
          Same as DateFormatter.toDateTimeStringISO()
 String toString()
          String representation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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()
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
Method Detail

hiddenProperties

public static String hiddenProperties()
For bean editing, public by accident.


getDate

public Date getDate()
Get this as a Date

Returns:
Date

setDate

public void setDate(Date date)
Set the Date. isPresent is set to false.

Parameters:
date - set to this Date

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 void 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 DateFormatter.toDateTimeString()

Returns:
formatted date

toDateTimeStringISO

public String toDateTimeStringISO()
Same as DateFormatter.toDateTimeStringISO()

Returns:
formatted date

toString

public String toString()
String representation

Overrides:
toString in class Object
Returns:
getText()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

add

public DateType add(TimeDuration d)

add

public DateType add(TimeUnit d)

subtract

public DateType subtract(TimeDuration d)

subtract

public DateType subtract(TimeUnit d)

main

public static void main(String[] args)
test



Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.