Interface CalendarDate

  • All Superinterfaces:
    Comparable<CalendarDate>

    @Immutable
    public interface CalendarDate
    extends Comparable<CalendarDate>
    A Calendar Date, replaces java.util.Date, using java.time. Allows non-standard calendars. Default is ISO8601. Always in UTC time zone. A Calendar Date is always composed of year, month, day, hour, min, sec, nano integer fields.
    • Field Detail

      • unixEpoch

        static final CalendarDate unixEpoch
        The Unix epoch (Jan, 1, 1970 00:00 UTC)
    • Method Detail

      • present

        static CalendarDate present()
        Create a CalendarDate representing the present moment in ISO8601 UTC
      • fromUdunitIsoDate

        static Optional<CalendarDate> fromUdunitIsoDate​(@Nullable
                                                        String calendarName,
                                                        String udunitString)
                                                 throws IllegalArgumentException
        Create a CalendarDate from an ISO date string, with extensions for udunit backward compatibility.
        Parameters:
        calendarName - get Calendar from Calendar.get(calendarName). Must be null, or a valid calendar name.
        udunitString - udunit ISO date string
        Returns:
        CalendarDate or empty if the String is not a valid ISO 8601 date
        Throws:
        IllegalArgumentException
      • of

        static CalendarDate of​(int year,
                               int monthOfYear,
                               int dayOfMonth,
                               int hourOfDay,
                               int minuteOfHour,
                               int secondOfMinute)
        Create Calendar date from fields, using UTC and ISO8601 calendar.
        Parameters:
        year - any integer
        monthOfYear - 1-12
        dayOfMonth - 1-31
        hourOfDay - 0-23
        minuteOfHour - 0-59
        secondOfMinute - 0-59
        Returns:
        CalendarDate
      • of

        static CalendarDate of​(@Nullable
                               Calendar cal,
                               int year,
                               int monthOfYear,
                               int dayOfMonth,
                               int hourOfDay,
                               int minuteOfHour,
                               int secondOfMinute,
                               int nanoOfSecond,
                               @Nullable
                               ZoneOffset zoneId)
        Create Calendar date from fields.
        Parameters:
        cal - calendar to use, or null for default
        year - any integer
        monthOfYear - 1-12
        dayOfMonth - may depend on calendar, but typically 1-31
        hourOfDay - 0-23
        minuteOfHour - 0-59
        secondOfMinute - 0-59
        nanoOfSecond - from 0 to 999,999,999
        zoneId - may be null, indicating ZoneOffset.UTC
        Returns:
        CalendarDate
      • ofDoy

        static CalendarDate ofDoy​(int year,
                                  int dayOfYear,
                                  int hourOfDay,
                                  int minuteOfHour,
                                  int secondOfMinute,
                                  int nanoOfSecond)
        Create Calendar date from dayOfYear and other fields, using UTC and ISO8601 calendar.
        Parameters:
        year - any integer
        dayOfYear - 1-366
        hourOfDay - 0-23
        minuteOfHour - 0-59
        secondOfMinute - 0-59
        nanoOfSecond - from 0 to 999,999,999
        Returns:
        CalendarDate
      • of

        static CalendarDate of​(Date date)
        Create CalendarDate from a java.util.Date. Uses ISO8601 UTC.
        Parameters:
        date - java.util.Date
        Returns:
        ISO8601 CalendarDate in UTC
      • of

        static CalendarDate of​(long msecs)
        Create CalendarDate from msecs since epoch, using ISO8601 UTC.
        Parameters:
        msecs - milliseconds from 1970-01-01T00:00:00Z
        Returns:
        ISO8601 CalendarDate in UTC
      • getCalendar

        Calendar getCalendar()
        Get the Calendar used by this CalendarDate.
      • getMillisFromEpoch

        long getMillisFromEpoch()
        Get the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.
      • getFieldValue

        int getFieldValue​(CalendarPeriod.Field fld)
        Get the value of the given field, eg Year, Month, Day, Hour...
      • toDate

        Date toDate()
        Get the equivilent java.util.Date. Must be in ISO calendar.
      • getYear

        default int getYear()
        Get the year field for this chronology.
      • getMonthOfYear

        default int getMonthOfYear()
        Get the month of year field for this chronology.
      • getDayOfMonth

        default int getDayOfMonth()
        Get the day of the month field for this chronology.
      • getHourOfDay

        default int getHourOfDay()
        Get the hour of day field for this chronology.
      • getMinuteOfHour

        default int getMinuteOfHour()
        Get the hour of day field for this chronology.
      • getSecondOfMinute

        default int getSecondOfMinute()
        Get the hour of day field for this chronology.
      • getMillisOfSecond

        default int getMillisOfSecond()
        Get the hour of day field for this chronology.
      • getDifferenceInMsecs

        default long getDifferenceInMsecs​(CalendarDate o)
        Get difference between (this - other) in millisecs. Must be same Calendar.
      • truncate

        default CalendarDate truncate​(CalendarPeriod.Field fld)
        Truncate the CalendarDate, by zeroing all the fields that are less than the named 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
      • add

        CalendarDate add​(long multiply,
                         CalendarPeriod period)
        Multiply the given period and add to this CalendarDate, return a new one.
      • isAfter

        boolean isAfter​(CalendarDate o)
        Return true if this CalendarDate is after the given one. Must be same Calendar.
      • isBefore

        boolean isBefore​(CalendarDate o)
        Return true if this CalendarDate is before the given one. Must be same Calendar.
      • since

        long since​(CalendarDate start,
                   CalendarPeriod period)
        Return value of (this - start) in the given CalendarPeriod units. Must be same Calendar.
      • toInstant

        Instant toInstant()
        Public by accident.