Class AnnualDate
- All Implemented Interfaces:
Serializable
,Comparable<AnnualDate>
,TemporalAccessor
,ChronoDisplay
,Temporal<AnnualDate>
,ThreetenAdapter
,LocalizedPatternSupport
Represents a combination of month and day-of-month as XML-pendant for xsd:gMonthDay
.
February, the 29th is always valid within the context of this class only.
Following elements which are declared as constants are registered by this class:
The calendar year is missing. Therefore this class cannot model a complete calendar date like
PlainDate
. For the same reason, a temporal arithmetic is not defined. The main purpose
of this class is just modelling partial dates like birthdays etc. Formatting example for localized
formatting styles:
ChronoFormatter<AnnualDate> usStyle = ChronoFormatter.ofStyle(DisplayMode.SHORT, Locale.US, AnnualDate.chronology()); ChronoFormatter<AnnualDate> germanStyle = ChronoFormatter.ofStyle(DisplayMode.SHORT, Locale.GERMANY, AnnualDate.chronology()); System.out.println("US-format: " + usStyle.format(AnnualDate.of(9, 11))); // US-format: 9/11 System.out.println("German: " + germanStyle.format(AnnualDate.of(9, 11))); // German: 11.9.
Note: The current annual date can be determined by an expression like:
AnnualDate current = SystemClock.inLocalView().now(AnnualDate.chronology())
.
- Since:
- 3.22/4.18
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionstatic ChronoElement<Integer>
Element with the day of month in the value range1-28/29/30/31
.static ChronoElement<Integer>
Element with the calendar month in numerical form and the value range1-12
.static ChronoElement<Month>
Element with the calendar month as enum in the value rangeJANUARY-DECEMBER
). -
Method Summary
Modifier and TypeMethodDescriptionDetermines the next possible exact annual date.Determines the next possible annual date and rounds up to next day if necessary.atYear(int year)
Creates a complete ISO calendar date for given gregorian year.static Chronology<AnnualDate>
Yields the associated chronology.int
compareTo(AnnualDate other)
boolean
static AnnualDate
Converts given JSR-310 type to an annual date.static AnnualDate
from(GregorianDate date)
Converts given gregorian date to an annual date.int
Obtains the day of month.getMonth()
Obtains the gregorian month.int
hashCode()
boolean
isAfter(AnnualDate temporal)
Queries if this object is after given object on a timeline.boolean
isBefore(AnnualDate temporal)
Queries if this object is before given object on a timeline.boolean
isSimultaneous(AnnualDate temporal)
Queries if this object and given object have the same position on the time axis.boolean
isValidDate(int year)
Checks if this instance results in a valid ISO calendar date for given gregorian year.static AnnualDate
Obtains the current annual date in system time.static AnnualDate
of(int month, int dayOfMonth)
Creates a new annual date.static AnnualDate
Creates a new annual date.static AnnualDate
Parses given string to an annual date where the input is in XML-format "--MM-dd".static Chronology<MonthDay>
threeten()
Obtains a bridge chronology for the typejava.time.MonthDay
.toString()
Yields the full description in the XML-format "--MM-dd".Converts this object to aTemporalAccessor
.Methods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
Methods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, getFormatPattern, useDynamicFormatPattern
Methods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
Methods inherited from interface net.time4j.engine.ThreetenAdapter
get, getLong, isSupported, query, range
-
Field Details
-
MONTH_OF_YEAR
Element with the calendar month as enum in the value range
JANUARY-DECEMBER
). -
MONTH_AS_NUMBER
Element with the calendar month in numerical form and the value range
1-12
.Normally the enum-variant is recommended due to clarity and type-safety. The enum-form can also be formatted as text.
- See Also:
MONTH_OF_YEAR
-
DAY_OF_MONTH
Element with the day of month in the value range
1-28/29/30/31
.
-
-
Method Details
-
of
Creates a new annual date.
- Parameters:
month
- gregorian month as enumdayOfMonth
- the day of month in range 1-29/30/31- Returns:
- new annual date
-
of
Creates a new annual date.
- Parameters:
month
- gregorian month in range 1-12dayOfMonth
- the day of month in range 1-29/30/31- Returns:
- new annual date
-
from
Converts given gregorian date to an annual date.
- Parameters:
date
- gregorian calendar date (for examplePlainDate
- Returns:
- AnnualDate
- Throws:
IllegalArgumentException
- if given date is invalid- Since:
- 3.28/4.24
-
from
Converts given JSR-310 type to an annual date.
- Parameters:
monthDay
- JSR-310-equivalent- Returns:
- corresponding annual date
- See Also:
toTemporalAccessor()
-
nowInSystemTime
Obtains the current annual date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(AnnualDate.chronology())
.- Returns:
- current annual date in system time zone using the system clock
- Since:
- 3.32/4.27
- See Also:
SystemClock.inLocalView()
,ZonalClock.now(net.time4j.engine.Chronology)
-
getMonth
Obtains the gregorian month.
- Returns:
- Month
-
getDayOfMonth
public int getDayOfMonth()Obtains the day of month.
- Returns:
- int
-
isAfter
Description copied from interface:Temporal
Queries if this object is after given object on a timeline.
- Specified by:
isAfter
in interfaceTemporal<AnnualDate>
- Parameters:
temporal
- object this instance is compared to- Returns:
true
if this instance is temporally aftertemporal
elsefalse
-
isBefore
Description copied from interface:Temporal
Queries if this object is before given object on a timeline.
- Specified by:
isBefore
in interfaceTemporal<AnnualDate>
- Parameters:
temporal
- object this instance is compared to- Returns:
true
if this instance is temporally beforetemporal
elsefalse
-
isSimultaneous
Description copied from interface:Temporal
Queries if this object and given object have the same position on the time axis.
Is equivalent to
!isAfter(temporal) && !isBefore(temporal)
. This method differs from theObject
-methodequals()
such that first the comparison type must be a temporal one and second that only temporal-only state will be considered.- Specified by:
isSimultaneous
in interfaceTemporal<AnnualDate>
- Parameters:
temporal
- object this instance is compared to- Returns:
true
if this instance is temporally equal totemporal
elsefalse
-
compareTo
- Specified by:
compareTo
in interfaceComparable<AnnualDate>
-
equals
-
hashCode
public int hashCode() -
toString
Yields the full description in the XML-format "--MM-dd".
- Overrides:
toString
in classObject
- Returns:
- String compatible to lexical space of xsd:gMonthDay
- See Also:
parseXML(String)
-
parseXML
Parses given string to an annual date where the input is in XML-format "--MM-dd".
- Parameters:
xml
- string compatible to lexical space of xsd:gMonthDay- Returns:
- AnnualDate
- Throws:
ParseException
- if parsing fails- See Also:
toString()
-
atYear
Creates a complete ISO calendar date for given gregorian year.
- Parameters:
year
- proleptic iso year [(-999,999,999)-999,999,999]- Returns:
- new or cached calendar date instance
- Throws:
IllegalArgumentException
- if the year argument is out of range or if this instance represents the 29th of February and is not valid for given year- See Also:
isValidDate(int)
-
isValidDate
public boolean isValidDate(int year)Checks if this instance results in a valid ISO calendar date for given gregorian year.
- Parameters:
year
- proleptic iso year [(-999,999,999)-999,999,999]- Returns:
true
if the year argument is out of range or if this instance represents the 29th of February and is not valid for given year elsefalse
- See Also:
atYear(int)
-
toTemporalAccessor
Description copied from interface:ThreetenAdapter
Converts this object to a
TemporalAccessor
.Any implementation is required to return a new object with a different concrete type, not this instance.
- Specified by:
toTemporalAccessor
in interfaceThreetenAdapter
- Returns:
- converted Threeten-object (always as new object)
-
asNextExactEvent
Determines the next possible exact annual date.
If this annual date is a leap day then the next date can be some years later. Example:
System.out.println(PlainDate.of(2015, 2, 28).with(AnnualDate.of(Month.FEBRUARY, 29).asNextEvent())); // 2016-02-29 System.out.println(PlainDate.of(2016, 2, 28).with(AnnualDate.of(Month.FEBRUARY, 29).asNextEvent())); // 2016-02-29 System.out.println(PlainDate.of(2016, 2, 29).with(AnnualDate.of(Month.FEBRUARY, 29).asNextEvent())); // 2020-02-29
- Returns:
- chronological operator
- See Also:
asNextRoundedEvent()
-
asNextRoundedEvent
Determines the next possible annual date and rounds up to next day if necessary.
If this annual date is a leap day then the next date can be advanced to begin of March. Example:
System.out.println(PlainDate.of(2015, 2, 28).with(AnnualDate.of(Month.FEBRUARY, 29).asNextEvent())); // 2015-03-01
- Returns:
- chronological operator
- See Also:
asNextExactEvent()
-
chronology
Yields the associated chronology.
- Returns:
- the underlying rule engine
-
threeten
Obtains a bridge chronology for the type
java.time.MonthDay
.- Returns:
- rule engine adapted for the type
java.time.MonthDay
- See Also:
chronology()
-