Package net.time4j

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 Details

    • MONTH_OF_YEAR

      @FormattableElement(format="M", alt="L") public static final ChronoElement<Month> MONTH_OF_YEAR

      Element with the calendar month as enum in the value range JANUARY-DECEMBER).

    • MONTH_AS_NUMBER

      public static final ChronoElement<Integer> 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

      @FormattableElement(format="d") public static final ChronoElement<Integer> DAY_OF_MONTH

      Element with the day of month in the value range 1-28/29/30/31.

  • Method Details

    • of

      public static AnnualDate of(Month month, int dayOfMonth)

      Creates a new annual date.

      Parameters:
      month - gregorian month as enum
      dayOfMonth - the day of month in range 1-29/30/31
      Returns:
      new annual date
    • of

      public static AnnualDate of(int month, int dayOfMonth)

      Creates a new annual date.

      Parameters:
      month - gregorian month in range 1-12
      dayOfMonth - the day of month in range 1-29/30/31
      Returns:
      new annual date
    • from

      public static AnnualDate from(GregorianDate date)

      Converts given gregorian date to an annual date.

      Parameters:
      date - gregorian calendar date (for example PlainDate
      Returns:
      AnnualDate
      Throws:
      IllegalArgumentException - if given date is invalid
      Since:
      3.28/4.24
    • from

      public static AnnualDate from(MonthDay monthDay)

      Converts given JSR-310 type to an annual date.

      Parameters:
      monthDay - JSR-310-equivalent
      Returns:
      corresponding annual date
      See Also:
      toTemporalAccessor()
    • nowInSystemTime

      public static AnnualDate 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

      public Month getMonth()

      Obtains the gregorian month.

      Returns:
      Month
    • getDayOfMonth

      public int getDayOfMonth()

      Obtains the day of month.

      Returns:
      int
    • isAfter

      public boolean isAfter(AnnualDate temporal)
      Description copied from interface: Temporal

      Queries if this object is after given object on a timeline.

      Specified by:
      isAfter in interface Temporal<AnnualDate>
      Parameters:
      temporal - object this instance is compared to
      Returns:
      true if this instance is temporally after temporal else false
    • isBefore

      public boolean isBefore(AnnualDate temporal)
      Description copied from interface: Temporal

      Queries if this object is before given object on a timeline.

      Specified by:
      isBefore in interface Temporal<AnnualDate>
      Parameters:
      temporal - object this instance is compared to
      Returns:
      true if this instance is temporally before temporal else false
    • isSimultaneous

      public boolean isSimultaneous(AnnualDate temporal)
      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 the Object-method equals() 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 interface Temporal<AnnualDate>
      Parameters:
      temporal - object this instance is compared to
      Returns:
      true if this instance is temporally equal to temporal else false
    • compareTo

      public int compareTo(AnnualDate other)
      Specified by:
      compareTo in interface Comparable<AnnualDate>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()

      Yields the full description in the XML-format "--MM-dd".

      Overrides:
      toString in class Object
      Returns:
      String compatible to lexical space of xsd:gMonthDay
      See Also:
      parseXML(String)
    • parseXML

      public static AnnualDate parseXML(String xml) throws ParseException

      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

      public PlainDate atYear(int year)

      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 else false
      See Also:
      atYear(int)
    • toTemporalAccessor

      public MonthDay 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 interface ThreetenAdapter
      Returns:
      converted Threeten-object (always as new object)
    • asNextExactEvent

      public ChronoOperator<PlainDate> 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

      public ChronoOperator<PlainDate> 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

      public static Chronology<AnnualDate> chronology()

      Yields the associated chronology.

      Returns:
      the underlying rule engine
    • threeten

      public static Chronology<MonthDay> threeten()

      Obtains a bridge chronology for the type java.time.MonthDay.

      Returns:
      rule engine adapted for the type java.time.MonthDay
      See Also:
      chronology()