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 Details

  • Method Details

    • 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 default
      year - any integer
      monthOfYear - 1-12
      dayOfMonth - 1-31
      hourOfDay - 0-23
      minuteOfHour - 0-59
      secondOfMinute - 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 default
      msecs - 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 null
      isoOrUdunits - 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 null
      isoDateString - 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 null
      udunits - 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 interface Comparable<CalendarDate>
    • isAfter

      public boolean isAfter(CalendarDate o)
    • isBefore

      public boolean isBefore(CalendarDate o)
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      ISO formatted string
      Overrides:
      toString in class Object
      Returns:
      ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZ)
    • 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()