Package ucar.nc2.time
Class CalendarDate
- java.lang.Object
-
- ucar.nc2.time.CalendarDate
-
- All Implemented Interfaces:
Comparable<CalendarDate>
@Immutable public class CalendarDate extends Object implements Comparable<CalendarDate>
A Calendar Date. Replaces java.util.Date. Allows non-standard calendars. Default is Calendar.gregorian. Always in UTC time zone.- Since:
- 3/21/11
-
-
Field Summary
Fields Modifier and Type Field Description static double
MILLISECS_IN_DAY
static double
MILLISECS_IN_HOUR
static double
MILLISECS_IN_MINUTE
static double
MILLISECS_IN_MONTH
static double
MILLISECS_IN_SECOND
static double
MILLISECS_IN_YEAR
static CalendarDate
UNKNOWN
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CalendarDate
add(double value, CalendarPeriod.Field unit)
Deprecated.use CalendarDate add(CalendarPeriod period)CalendarDate
add(CalendarPeriod period)
int
compareTo(CalendarDate o)
boolean
equals(Object o)
Calendar
getCalendar()
int
getDayOfMonth()
long
getDifference(CalendarDate o, CalendarPeriod.Field fld)
Get difference between two calendar dates in given Field unitslong
getDifferenceInMsecs(CalendarDate o)
Get difference between two calendar dates in millisecsint
getFieldValue(CalendarPeriod.Field fld)
int
getHourOfDay()
Get the hour of day (0-23) field for this chronology.long
getMillis()
Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.String
getTimeUnits()
udunits formattingint
hashCode()
boolean
isAfter(CalendarDate o)
boolean
isBefore(CalendarDate o)
static CalendarDate
of(long msecs)
Create CalendarDate from msecs since epoch Uses standard Calendar.static CalendarDate
of(Date date)
Create CalendarDate from a java.util.Date.static CalendarDate
of(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute)
Get Calendar date from fields.static CalendarDate
of(Calendar cal, long msecs)
Create CalendarDate from msecs since epoch Uses the given Calendar.static CalendarDate
parseISOformat(String calendarName, String isoDateString)
Get CalendarDate from ISO date stringstatic CalendarDate
parseUdunits(String calendarName, String udunits)
Get CalendarDate from udunit date stringstatic CalendarDate
parseUdunitsOrIso(String calendarName, String isoOrUdunits)
Get CalendarDate from ISO date stringstatic CalendarDate
present()
Get a CalendarDate representing the present momentstatic CalendarDate
present(Calendar cal)
CalendarDate
subtract(CalendarPeriod period)
Date
toDate()
Get the equivilent java.util.DateGregorianCalendar
toGregorianCalendar()
String
toString()
ISO formatted stringCalendarDate
truncate(CalendarPeriod.Field fld)
truncate the CalendarDate, by zeroing all the fields that are less than the field.static CalendarDate
withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute)
-
-
-
Field Detail
-
UNKNOWN
public static final CalendarDate UNKNOWN
-
MILLISECS_IN_SECOND
public static final double MILLISECS_IN_SECOND
- See Also:
- Constant Field Values
-
MILLISECS_IN_MINUTE
public static final double MILLISECS_IN_MINUTE
- See Also:
- Constant Field Values
-
MILLISECS_IN_HOUR
public static final double MILLISECS_IN_HOUR
- See Also:
- Constant Field Values
-
MILLISECS_IN_DAY
public static final double MILLISECS_IN_DAY
- See Also:
- Constant Field Values
-
MILLISECS_IN_YEAR
public static final double MILLISECS_IN_YEAR
- See Also:
- Constant Field Values
-
MILLISECS_IN_MONTH
public static final double MILLISECS_IN_MONTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
present
public static CalendarDate present()
Get a CalendarDate representing the present moment- Returns:
- CalendarDate representing the present moment in UTC
-
present
public static CalendarDate present(Calendar cal)
-
of
public static CalendarDate of(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute)
Get Calendar date from fields. Uses UTZ time zone- Parameters:
cal
- calendar to use, or null for defaultyear
- any integermonthOfYear
- 1-12dayOfMonth
- 1-31hourOfDay
- 0-23minuteOfHour
- 0-59secondOfMinute
- 0-59- Returns:
- CalendarDate
-
withDoy
public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute)
-
of
public static CalendarDate of(Date date)
Create CalendarDate from a java.util.Date. Uses standard Calendar.- Parameters:
date
- java.util.Date- Returns:
- CalendarDate in UTC
-
of
public static CalendarDate of(long msecs)
Create CalendarDate from msecs since epoch Uses standard Calendar.- Parameters:
msecs
- milliseconds from 1970-01-01T00:00:00Z- Returns:
- CalendarDate in UTC
-
of
public static CalendarDate of(Calendar cal, long msecs)
Create CalendarDate from msecs since epoch Uses the given Calendar.- Parameters:
cal
- calendar to use, or null for defaultmsecs
- milliseconds from 1970-01-01T00:00:00Z- Returns:
- CalendarDate in UTC time zone.
-
parseUdunitsOrIso
@Nullable public static CalendarDate parseUdunitsOrIso(String calendarName, String isoOrUdunits)
Get CalendarDate from ISO date string- Parameters:
calendarName
- get Calendar from Calendar.get(calendarName). may be nullisoOrUdunits
- ISO or udunits date string- Returns:
- CalendarDate or null if not valid
-
parseISOformat
public static CalendarDate parseISOformat(String calendarName, String isoDateString)
Get CalendarDate from ISO date string- Parameters:
calendarName
- get Calendar from Calendar.get(calendarName). may be nullisoDateString
- ISO date string- Returns:
- CalendarDate
-
parseUdunits
public static CalendarDate parseUdunits(String calendarName, String udunits)
Get CalendarDate from udunit date string- Parameters:
calendarName
- get Calendar from Calendar.get(calendarName). may be nulludunits
- must be value (space) udunits string- Returns:
- CalendarDate
-
getCalendar
public Calendar getCalendar()
-
getMillis
public long getMillis()
Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.- Returns:
- the number of milliseconds since 1970-01-01T00:00:00Z
-
compareTo
public int compareTo(CalendarDate o)
- Specified by:
compareTo
in interfaceComparable<CalendarDate>
-
isAfter
public boolean isAfter(CalendarDate o)
-
isBefore
public boolean isBefore(CalendarDate o)
-
toString
public String toString()
ISO formatted string
-
getTimeUnits
public String getTimeUnits()
udunits formatting- Returns:
- udunits formatted date
-
getHourOfDay
public int getHourOfDay()
Get the hour of day (0-23) field for this chronology.- Returns:
- hour of day (0-23)
-
getFieldValue
public int getFieldValue(CalendarPeriod.Field fld)
-
getDayOfMonth
public int getDayOfMonth()
-
add
public CalendarDate add(double value, CalendarPeriod.Field unit)
Deprecated.use CalendarDate add(CalendarPeriod period)
-
add
public CalendarDate add(CalendarPeriod period)
-
subtract
public CalendarDate subtract(CalendarPeriod period)
-
truncate
public CalendarDate truncate(CalendarPeriod.Field fld)
truncate the CalendarDate, by zeroing all the fields that are less than the field. So 2013-03-01T19:30 becomes 2013-03-01T00:00 if the field is "day"- Parameters:
fld
- set to 0 all fields less than this one- Returns:
- truncated result
-
toDate
public Date toDate()
Get the equivilent java.util.Date- Returns:
- the equivalent Date
-
getDifferenceInMsecs
public long getDifferenceInMsecs(CalendarDate o)
Get difference between two calendar dates in millisecs- Parameters:
o
- other calendar date- Returns:
- (this minus o) difference in millisecs
-
getDifference
public long getDifference(CalendarDate o, CalendarPeriod.Field fld)
Get difference between two calendar dates in given Field units- Parameters:
o
- other calendar date- Returns:
- (this minus o) difference in units of this Field
-
toGregorianCalendar
public GregorianCalendar toGregorianCalendar()
-
-