Package ucar.nc2.calendar
Class CalendarDateUnit
- java.lang.Object
-
- ucar.nc2.calendar.CalendarDateUnit
-
@Immutable public class CalendarDateUnit extends Object
A Calendar Date Unit: "[CALENDAR] unit SINCE baseDate". Its main job is to convert "value unit since baseDate" to a CalendarDate.
-
-
Field Summary
Fields Modifier and Type Field Description static CalendarDateUnit
unixDateUnit
"seconds since the Unix epoch".
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static Optional<CalendarDateUnit>
fromAttributes(AttributeContainer atts, String units)
Create a CalendarDateUnit from attributes.static Optional<CalendarDateUnit>
fromUdunitString(Calendar calt, String udunitString)
Create a CalendarDateUnit from a calendar and a udunit string = "unit since calendarDate"CalendarDate
getBaseDateTime()
The base date "[CALENDAR] unit SINCE baseDate".Calendar
getCalendar()
The Calendar used (default proleptic_gregorian).CalendarPeriod.Field
getCalendarField()
The period field taken from the unit: "[CALENDAR] unit SINCE baseDate".CalendarPeriod
getCalendarPeriod()
The period taken from the unit: "[CALENDAR] unit SINCE baseDate".int
hashCode()
boolean
isCalendarField()
Was CALENDAR specified? Only affects Period.Month, Period.Year.CalendarDate
makeCalendarDate(long value)
Add the given integer (value * period) to the baseDateTime to make a new CalendarDate.CalendarDate
makeFractionalCalendarDate(double value)
Add the given (value * period) to the baseDateTime to make a new CalendarDate.double
makeFractionalOffsetFromRefDate(CalendarDate date)
Find the offset of date in fractional units of this period from the baseDateTime.long
makeOffsetFromRefDate(CalendarDate date)
Find the offset of date in integral units of this period from the baseDateTime.static CalendarDateUnit
of(CalendarPeriod.Field periodField, boolean isCalendarField, CalendarDate baseDate)
Create a CalendarDateUnit from a CalendarPeriod.Field, and a base datestatic CalendarDateUnit
of(CalendarPeriod period, boolean isCalendarField, CalendarDate baseDate)
Create a CalendarDateUnit from a CalendarPeriod, and a base dateString
toString()
-
-
-
Field Detail
-
unixDateUnit
public static final CalendarDateUnit unixDateUnit
"seconds since the Unix epoch".
-
-
Method Detail
-
fromUdunitString
public static Optional<CalendarDateUnit> fromUdunitString(@Nullable Calendar calt, String udunitString)
Create a CalendarDateUnit from a calendar and a udunit string = "unit since calendarDate"- Parameters:
calt
- use this Calendar, or null for default calendarudunitString
- "unit since calendarDate"- Returns:
- CalendarDateUnit or empty if udunitString is not parseable
-
of
public static CalendarDateUnit of(CalendarPeriod.Field periodField, boolean isCalendarField, CalendarDate baseDate)
Create a CalendarDateUnit from a CalendarPeriod.Field, and a base date- Parameters:
periodField
- a CalendarPeriod.Field like Hour or secondbaseDate
- "since baseDate"- Returns:
- CalendarDateUnit
-
of
public static CalendarDateUnit of(CalendarPeriod period, boolean isCalendarField, CalendarDate baseDate)
Create a CalendarDateUnit from a CalendarPeriod, and a base date- Parameters:
period
- a CalendarPeriod like 1 Hour or 30 secondsbaseDate
- "since baseDate"- Returns:
- CalendarDateUnit
-
fromAttributes
public static Optional<CalendarDateUnit> fromAttributes(AttributeContainer atts, @Nullable String units)
Create a CalendarDateUnit from attributes.- Parameters:
atts
- AttributeContainer, look for 'units' attribute and 'calendar' attributeunits
- the units string, may be null- Returns:
- CalendarDateUnit if possible
-
getBaseDateTime
public CalendarDate getBaseDateTime()
The base date "[CALENDAR] unit SINCE baseDate".
-
getCalendar
public Calendar getCalendar()
The Calendar used (default proleptic_gregorian).
-
getCalendarField
public CalendarPeriod.Field getCalendarField()
The period field taken from the unit: "[CALENDAR] unit SINCE baseDate".
-
getCalendarPeriod
public CalendarPeriod getCalendarPeriod()
The period taken from the unit: "[CALENDAR] unit SINCE baseDate".
-
isCalendarField
public boolean isCalendarField()
Was CALENDAR specified? Only affects Period.Month, Period.Year.
-
makeCalendarDate
public CalendarDate makeCalendarDate(long value)
Add the given integer (value * period) to the baseDateTime to make a new CalendarDate.- Parameters:
value
- number of periods to add. May be negative.
-
makeOffsetFromRefDate
public long makeOffsetFromRefDate(CalendarDate date)
Find the offset of date in integral units of this period from the baseDateTime. Inverse of makeCalendarDate. TODO not working when period is month, see TestCalendarDateUnit
-
makeFractionalCalendarDate
public CalendarDate makeFractionalCalendarDate(double value)
Add the given (value * period) to the baseDateTime to make a new CalendarDate. Inverse of makeFractionalOffsetFromRefDate. This uses makeCalendarDate when its a calendar date or uses a non-ISO calendar, and rounds the value to a long.- Parameters:
value
- number of (possibly non-integral) periods to add. May be negative.
-
makeFractionalOffsetFromRefDate
public double makeFractionalOffsetFromRefDate(CalendarDate date)
Find the offset of date in fractional units of this period from the baseDateTime. Inverse of makeFractionalCalendarDate. This uses makeOffsetFromRefDate when its a calendar date or uses a non-ISO calendar, and rounds the value to a long.- Returns:
- number of (possibly non-integral) periods since base date. May be negative.
-
-