Package ucar.nc2.units
Class DateUnit
- java.lang.Object
-
- ucar.nc2.units.DateUnit
-
public class DateUnit extends Object
Handles udunits dates, represented as "n units of time since reference date" eg "1203 days since 1970-01-01 00:00:00".This is a wrapper around ucar.units package. It tracks the value, the base time unit, and the date origin separately.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DateUnitfactory(String text)DategetDate()Get the equivalent java.util.Date.DategetDateOrigin()Get the origin Date.static DategetStandardDate(String text)Create a java.util.Date from this udunits String.static DategetStandardOrISO(String text)Create a java.util.Date from a udunit or ISO String.TimeUnitgetTimeUnit()For udunit dates, get the time unit.StringgetTimeUnitString()For udunit dates, get the time unit only, as a String, eg "secs" or "days"StringgetUnitsString()The udunits string, but no value, ie its a base unit.static DateUnitgetUnixDateUnit()CalendarDatemakeCalendarDate(double val)Get the equivalent CalendarDate.DatemakeDate(double val)Create a Date from this base unit and the given value.StringmakeStandardDateString(double value)Make a standard GMT string representation from this unit and given value.doublemakeValue(Date date)Create the equivalent value from this base unit and the given Date.static CalendarDateparseCalendarDate(String text)StringtoString()
-
-
-
Constructor Detail
-
DateUnit
public DateUnit(String text) throws ucar.units.UnitException
Constructor.- Parameters:
text- udunits String, eg 3 secs since 1991-01-01T03:12- Throws:
ucar.units.UnitException- if malformed String.
-
DateUnit
public DateUnit(double value, String timeUnitString, Date since) throws ucar.units.UnitExceptionConstructor that takes a value, timeUnitString, and a Date since- Parameters:
value- number of time unitstimeUnitString- eg "secs"since- date since, eg "secs since 1970-01-01T00:00:00Z"- Throws:
ucar.units.UnitException- if not valid time unit.
-
-
Method Detail
-
getStandardDate
public static Date getStandardDate(String text)
Create a java.util.Date from this udunits String.- Parameters:
text- a udunit string.[number] (units) since [-]Y[Y[Y[Y]]]-MM-DD[(T| )hh[:mm[:ss[.sss*]]][ [+|-]hh[[:]mm]]]- Returns:
- Date or null if not date unit.
-
getStandardOrISO
public static Date getStandardOrISO(String text)
Create a java.util.Date from a udunit or ISO String.- Parameters:
text- a udunit or ISO string.- Returns:
- Date or null if not date unit.
- See Also:
getStandardDate(java.lang.String),DateFormatter.getISODate(java.lang.String)
-
parseCalendarDate
public static CalendarDate parseCalendarDate(String text)
-
getUnixDateUnit
public static DateUnit getUnixDateUnit()
-
getDateOrigin
public Date getDateOrigin()
Get the origin Date.- Returns:
- Date or null if not a time unit.
-
getTimeUnitString
public String getTimeUnitString()
For udunit dates, get the time unit only, as a String, eg "secs" or "days"- Returns:
- time unit as a string
-
getTimeUnit
public TimeUnit getTimeUnit()
For udunit dates, get the time unit.- Returns:
- time unit
-
getDate
public Date getDate()
Get the equivalent java.util.Date.- Returns:
- Date or null if failure
-
makeCalendarDate
public CalendarDate makeCalendarDate(double val)
Get the equivalent CalendarDate.- Returns:
- CalendarDate or null if failure
-
makeDate
public Date makeDate(double val)
Create a Date from this base unit and the given value.- Parameters:
val- value in the units of this base unit, eg sec since base date- Returns:
- Date .
-
makeValue
public double makeValue(Date date)
Create the equivalent value from this base unit and the given Date. Inverse of makeDate.- Parameters:
date- to convert.- Returns:
- value in units of this base unit.
-
makeStandardDateString
public String makeStandardDateString(double value)
Make a standard GMT string representation from this unit and given value.- Parameters:
value- of time in these units.- Returns:
- String or null if not time unit.
-
getUnitsString
public String getUnitsString()
The udunits string, but no value, ie its a base unit.- Returns:
- the udunits base string
-
-