Class HistoricCalendar

All Implemented Interfaces:
Serializable, Comparable<HistoricCalendar>, CalendarDate, ChronoDisplay, Temporal<CalendarDate>, VariantSource, LocalizedPatternSupport

@CalendarType("historic") public final class HistoricCalendar extends CalendarVariant<HistoricCalendar> implements LocalizedPatternSupport

Represents the historic christian calendar used in most European countries.

Following elements which are declared as constants are registered by this class

Furthermore, all elements defined in EpochDays and CommonElements are supported.

Formatting example

      ChronoHistory history = ChronoHistory.of(Locale.UK);
      ChronoFormatter<HistoricCalendar> f =
          ChronoFormatter.ofStyle(DisplayMode.FULL, Locale.ENGLISH, HistoricCalendar.family()).with(history);
      HistoricCalendar cal = HistoricCalendar.of(history, HistoricEra.AD, 1603, 3, 24);
      String text = "Thursday, March 24, 1602/03 AD" // dual dating for the historic year
      assertThat(f.format(cal), is(text));
      assertThat(f.parse(text), is(cal));
 

Transformation from ISO-8601

Any gregorian date (ISO-8601) can be transformed to HistoricCalendar this simple way:

     ChronoHistory history = ChronoHistory.ofFirstGregorianReform();
     HistoricCalendar cal = PlainDate.of(1582, 10, 5).transform(HistoricCalendar.family(), history)
     System.out.println(cal); // AD-1582-09-25[...], ten days were cut off by pope Gregor
 

Support for unicode ca-extensions

     Locale locale = Locale.forLanguageTag("de-DE-PREUSSEN-u-ca-historic");
     ChronoFormatter<CalendarDate> f = ChronoFormatter.ofGenericCalendarStyle(DisplayMode.FULL, locale);
     assertThat(
          f.format(PlainDate.of(1610, 9, 1)),
          is("Mittwoch, 22. August 1610 n. Chr."));
 

The key word is "historic". The ca-extension finally evaluates ChronoHistory.of(Locale) for automatical conversions to HistoricCalendar before formatting (as shown above).

Since:
3.36/4.31
Author:
Meno Hochschild
See Also:
Serialized Form
  • Field Details

  • Method Details

    • of

      public static HistoricCalendar of(ChronoHistory history, HistoricEra era, int relatedStandardYear, int historicMonth, int historicDayOfMonth)

      Constructs a new historic calendar.

      Equivalent to of(ChronoHistory, HistoricEra, int, YearDefinition, int, int) of(history, era, relatedStandardYear, historicMonth, historicDayOfMonth, YearDefinition.DUAL_DATING)}.

      Parameters:
      history - historization model
      era - historic era
      relatedStandardYear - the related standard year of era (>= 1) starting on January the first
      historicMonth - historic month (1-12)
      historicDayOfMonth - historic day of month (1-31)
      Returns:
      new historic calendar
      Throws:
      IllegalArgumentException - if any argument is out of required maximum range or invalid for other reasons
    • of

      public static HistoricCalendar of(ChronoHistory history, HistoricEra era, int yearOfEra, YearDefinition yearDefinition, int historicMonth, int historicDayOfMonth)

      Constructs a new historic calendar.

      Parameters:
      history - historization model
      era - historic era
      yearOfEra - year of era which will be interpreted according to given year definition (>= 1)
      yearDefinition - defines a strategy how to interprete year of era
      historicMonth - historic month (1-12)
      historicDayOfMonth - historic day of month (1-31)
      Returns:
      new historic calendar
      Throws:
      IllegalArgumentException - if any argument is out of required maximum range or invalid for other reasons
    • nowInSystemTime

      public static HistoricCalendar nowInSystemTime(ChronoHistory history)

      Obtains the current historic calendar date in system time.

      Convenient short-cut for: SystemClock.inLocalView().now(HistoricCalendar.family(), history, StartOfDay.MIDNIGHT).toDate()).

      Parameters:
      history - historization model
      Returns:
      current historic calendar in system time zone using the system clock
      See Also:
      SystemClock.inLocalView()
    • getHistory

      public ChronoHistory getHistory()

      Obtains the underlying calendar history.

      Returns:
      ChronoHistory
    • getEra

      public HistoricEra getEra()

      Yields the historic era.

      Returns:
      HistoricEra
    • getCentury

      public int getCentury()

      Obtains the century of era.

      Returns:
      int
    • getYear

      public int getYear()

      Obtains the true historic year as displayed in historic documents.

      Important: The begin of a historic year can deviate from first of January. Historic years are often not synchronized with month cycles. Users can apply the expression getInt(RELATED_STANDARD_YEAR) in order to obtain the year beginning on first of January.

      Returns:
      int
      See Also:
      HistoricDate.getYearOfEra(NewYearStrategy), ChronoHistory.getNewYearStrategy()
    • getMonth

      public Month getMonth()

      Yields the historic month.

      Returns:
      enum
    • getDayOfMonth

      public int getDayOfMonth()

      Yields the historic day of month.

      Returns:
      int
    • getDayOfWeek

      public Weekday getDayOfWeek()

      Determines the day of week.

      The week model has never been subject to historical changes leaving aside radical calendar reforms like the Frenh revolutionary calendar.

      Returns:
      Weekday
    • getDayOfYear

      public int getDayOfYear()

      Yields the historic day of year.

      Returns:
      int
    • getVariant

      public String getVariant()
      Description copied from interface: VariantSource

      Yields the variant name of a calendar system.

      Specified by:
      getVariant in interface VariantSource
      Returns:
      String which is empty if there are no variants
    • lengthOfMonth

      public int lengthOfMonth()

      Yields the length of current historic month in days.

      Returns:
      length of historic month in days or -1 if the length cannot be determined
    • lengthOfYear

      public int lengthOfYear()

      Yields the length of current historic year in days.

      Returns:
      length of historic year in days or -1 if the length cannot be determined
    • withNewYear

      public HistoricCalendar withNewYear()

      Obtains the start of this year (which is often not the first of January).

      Returns:
      new year
    • nextDay

      public HistoricCalendar nextDay()

      Convenient short form for with(DAY_OF_MONTH.incremented()) or plus(CalendarDays.ONE).

      Returns:
      copy of this instance at next day
      See Also:
      CalendarVariant.plus(CalendarDays), CalendarDays.ONE
    • at

      Creates a new local timestamp with this date and given wall time.

      If the time T24:00 is used then the resulting timestamp will automatically be normalized such that the timestamp will contain the following day instead.

      Parameters:
      time - wall time
      Returns:
      general timestamp as composition of this date and given time
    • atTime

      public GeneralTimestamp<HistoricCalendar> atTime(int hour, int minute)

      Is equivalent to at(PlainTime.of(hour, minute)).

      Parameters:
      hour - hour of day in range (0-24)
      minute - minute of hour in range (0-59)
      Returns:
      general timestamp as composition of this date and given time
      Throws:
      IllegalArgumentException - if any argument is out of range
    • equals

      public boolean equals(Object obj)
      Description copied from class: CalendarVariant

      Compares the whole state of this instance with given object.

      Implementations will usually define their state based on the temporal position and the variant name. Exceptions from this rule should be explicitly documented and reasoned.

      Specified by:
      equals in class CalendarVariant<HistoricCalendar>
      See Also:
      CalendarVariant.compareTo(CalendarVariant)
    • hashCode

      public int hashCode()
      Description copied from class: CalendarVariant

      Subclasses must redefine this method corresponding to the behaviour of equals().

      Specified by:
      hashCode in class CalendarVariant<HistoricCalendar>
    • toString

      public String toString()
      Description copied from class: CalendarVariant

      Provides a complete textual representation of the state of this calendar variant.

      Specified by:
      toString in class CalendarVariant<HistoricCalendar>
    • getDefaultWeekmodel

      public static Weekmodel getDefaultWeekmodel()

      Obtains the standard week model of this calendar.

      Christian calendars usually starts on Sunday.

      Returns:
      Weekmodel
    • family

      public static CalendarFamily<HistoricCalendar> family()

      Returns the associated calendar family.

      Returns:
      chronology as calendar family