Package ucar.nc2.calendar
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 Summary
Fields Modifier and Type Field Description static CalendarDate
unixEpoch
The Unix epoch (Jan, 1, 1970 00:00 UTC)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CalendarDate
add(long multiply, CalendarPeriod period)
Multiply the given period and add to this CalendarDate, return a new one.CalendarDate
add(long value, CalendarPeriod.Field unit)
Add the given period (value and unit) to this CalendarDate, return a new one.CalendarDate
add(CalendarPeriod period)
Add the given period to this CalendarDate, return a new one.String
format(DateTimeFormatter dtf)
String using the given formatterstatic Optional<CalendarDate>
fromUdunitIsoDate(String calendarName, String udunitString)
Create a CalendarDate from an ISO date string, with extensions for udunit backward compatibility.Calendar
getCalendar()
Get the Calendar used by this CalendarDate.default int
getDayOfMonth()
Get the day of the month field for this chronology.default long
getDifferenceInMsecs(CalendarDate o)
Get difference between (this - other) in millisecs.int
getFieldValue(CalendarPeriod.Field fld)
Get the value of the given field, eg Year, Month, Day, Hour...default int
getHourOfDay()
Get the hour of day field for this chronology.long
getMillisFromEpoch()
Get the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.default int
getMillisOfSecond()
Get the hour of day field for this chronology.default int
getMinuteOfHour()
Get the hour of day field for this chronology.default int
getMonthOfYear()
Get the month of year field for this chronology.default int
getSecondOfMinute()
Get the hour of day field for this chronology.default int
getYear()
Get the year field for this chronology.boolean
isAfter(CalendarDate o)
Return true if this CalendarDate is after the given one.boolean
isBefore(CalendarDate o)
Return true if this CalendarDate is before the given one.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.static CalendarDate
of(long msecs)
Create CalendarDate from msecs since epoch, using ISO8601 UTC.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, int nanoOfSecond, ZoneOffset zoneId)
Create Calendar date from fields.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.static CalendarDate
ofInstant(Calendar cal, Instant instant)
Public by accident.static CalendarDate
present()
Create a CalendarDate representing the present moment in ISO8601 UTClong
since(CalendarDate start, CalendarPeriod period)
Return value of (this - start) in the given CalendarPeriod units.long
since(CalendarDate start, CalendarPeriod.Field field)
Return value of (this - start) in the given Field units.Date
toDate()
Get the equivilent java.util.Date.Instant
toInstant()
Public by accident.String
toString()
String in ISO8601 formatdefault CalendarDate
truncate(CalendarPeriod.Field fld)
Truncate the CalendarDate, by zeroing all the fields that are less than the named field.-
Methods inherited from interface java.lang.Comparable
compareTo
-
-
-
-
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 integermonthOfYear
- 1-12dayOfMonth
- 1-31hourOfDay
- 0-23minuteOfHour
- 0-59secondOfMinute
- 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 defaultyear
- any integermonthOfYear
- 1-12dayOfMonth
- may depend on calendar, but typically 1-31hourOfDay
- 0-23minuteOfHour
- 0-59secondOfMinute
- 0-59nanoOfSecond
- from 0 to 999,999,999zoneId
- 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 integerdayOfYear
- 1-366hourOfDay
- 0-23minuteOfHour
- 0-59secondOfMinute
- 0-59nanoOfSecond
- 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
-
format
String format(DateTimeFormatter dtf)
String using the given formatter
-
add
CalendarDate add(CalendarPeriod period)
Add the given period to this CalendarDate, return a new one.
-
add
CalendarDate add(long multiply, CalendarPeriod period)
Multiply the given period and add to this CalendarDate, return a new one.
-
add
CalendarDate add(long value, CalendarPeriod.Field unit)
Add the given period (value and unit) 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.Field field)
Return value of (this - start) in the given Field units. 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.
-
ofInstant
static CalendarDate ofInstant(@Nullable Calendar cal, Instant instant)
Public by accident.
-
-