Package ucar.nc2.calendar
Class CalendarPeriod
- java.lang.Object
-
- ucar.nc2.calendar.CalendarPeriod
-
@Immutable public class CalendarPeriod extends Object
A CalendarPeriod is a logical duration of time, it requires a Calendar to convert to an actual duration of time. A CalendarPeriod is expressed as {integer x Field}.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CalendarPeriod.Field
-
Field Summary
Fields Modifier and Type Field Description static CalendarPeriod
Hour
1 hourstatic CalendarPeriod
Millisec
1 millisecstatic CalendarPeriod
Minute
1 minutestatic CalendarPeriod
Second
1 second
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static CalendarPeriod.Field
fromUnitString(String udunit)
Convert a udunit period string into a CalendarPeriod.Field.ChronoUnit
getChronoUnit()
The java.time.ChronoUnitdouble
getConvertFactor(CalendarPeriod from)
Get the conversion factor of the other CalendarPeriod to this one.CalendarPeriod.Field
getField()
The underlying Field, eg minutes.int
getValue()
The number of Fields, eg 30 minutes.int
hashCode()
boolean
isDefaultCalendarField()
Whether a field has CALENDAR on by default.static CalendarPeriod
of(int value, CalendarPeriod.Field field)
static CalendarPeriod
of(String udunit)
Convert a udunit period string into a CalendarPeriodString
toString()
CalendarPeriod
withValue(int value)
Create a new CalendarPeriod with same Field and different value.
-
-
-
Field Detail
-
Hour
public static final CalendarPeriod Hour
1 hour
-
Minute
public static final CalendarPeriod Minute
1 minute
-
Second
public static final CalendarPeriod Second
1 second
-
Millisec
public static final CalendarPeriod Millisec
1 millisec
-
-
Method Detail
-
fromUnitString
@Nullable public static CalendarPeriod.Field fromUnitString(String udunit)
Convert a udunit period string into a CalendarPeriod.Field.- Parameters:
udunit
- period string- Returns:
- CalendarPeriod.Field enum or null if not valid format
-
of
public static CalendarPeriod of(int value, CalendarPeriod.Field field)
-
of
@Nullable public static CalendarPeriod of(String udunit)
Convert a udunit period string into a CalendarPeriod- Parameters:
udunit
- period string : "[val] unit"- Returns:
- CalendarPeriod or null if illegal format or unknown unit
-
withValue
public CalendarPeriod withValue(int value)
Create a new CalendarPeriod with same Field and different value.
-
getValue
public int getValue()
The number of Fields, eg 30 minutes.
-
getField
public CalendarPeriod.Field getField()
The underlying Field, eg minutes.
-
getChronoUnit
public ChronoUnit getChronoUnit()
The java.time.ChronoUnit
-
isDefaultCalendarField
public boolean isDefaultCalendarField()
Whether a field has CALENDAR on by default. True for Month and Year.
-
getConvertFactor
public double getConvertFactor(CalendarPeriod from)
Get the conversion factor of the other CalendarPeriod to this one. Cant be used for Month or Year.- Parameters:
from
- convert from this- Returns:
- conversion factor, so that getConvertFactor(from) * from = this
-
-