Class HistoricCalendar
- All Implemented Interfaces:
Serializable
,Comparable<HistoricCalendar>
,CalendarDate
,ChronoDisplay
,Temporal<CalendarDate>
,VariantSource
,LocalizedPatternSupport
Represents the historic christian calendar used in most European countries.
Following elements which are declared as constants are registered by this class
DAY_OF_WEEK
DAY_OF_MONTH
DAY_OF_YEAR
WEEKDAY_IN_MONTH
MONTH_OF_YEAR
RELATED_STANDARD_YEAR
CENTURY_OF_ERA
ERA
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 Summary
Modifier and TypeFieldDescriptionstatic ChronoElement<Integer>
Represents the historic century.static StdCalendarElement<Integer,HistoricCalendar>
Represents the historic day of month.static StdCalendarElement<Weekday,HistoricCalendar>
Represents the historic day of week.static StdCalendarElement<Integer,HistoricCalendar>
Represents the historic day of year.static ChronoElement<HistoricEra>
Represents the historic era.static StdCalendarElement<Month,HistoricCalendar>
Represents the historic month.static TextElement<Integer>
Represents the related standard year within current era which starts on first of January.Element with the ordinal day-of-week within given calendar month. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new local timestamp with this date and given wall time.atTime(int hour, int minute)
Is equivalent toat(PlainTime.of(hour, minute))
.boolean
Compares the whole state of this instance with given object.static CalendarFamily<HistoricCalendar>
family()
Returns the associated calendar family.int
Obtains the century of era.int
Yields the historic day of month.Determines the day of week.int
Yields the historic day of year.static Weekmodel
Obtains the standard week model of this calendar.getEra()
Yields the historic era.Obtains the underlying calendar history.getMonth()
Yields the historic month.Yields the variant name of a calendar system.int
getYear()
Obtains the true historic year as displayed in historic documents.int
hashCode()
Subclasses must redefine this method corresponding to the behaviour ofequals()
.int
Yields the length of current historic month in days.int
Yields the length of current historic year in days.nextDay()
Convenient short form forwith(DAY_OF_MONTH.incremented())
orplus(CalendarDays.ONE)
.static HistoricCalendar
nowInSystemTime(ChronoHistory history)
Obtains the current historic calendar date in system time.static HistoricCalendar
of(ChronoHistory history, HistoricEra era, int relatedStandardYear, int historicMonth, int historicDayOfMonth)
Constructs a new historic calendar.static HistoricCalendar
of(ChronoHistory history, HistoricEra era, int yearOfEra, YearDefinition yearDefinition, int historicMonth, int historicDayOfMonth)
Constructs a new historic calendar.toString()
Provides a complete textual representation of the state of this calendar variant.Obtains the start of this year (which is often not the first of January).Methods inherited from class net.time4j.engine.CalendarVariant
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plus, withVariant, withVariant
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.engine.CalendarDate
transform, transform, transform, transform, transform, transform
Methods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, getFormatPattern, useDynamicFormatPattern
Methods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
-
Field Details
-
ERA
Represents the historic era.
The era value cannot be changed in any way which makes sense so this element is like a display-only element.
-
CENTURY_OF_ERA
Represents the historic century.
-
RELATED_STANDARD_YEAR
Represents the related standard year within current era which starts on first of January.
Note: Getting true historic years which take care of different new-year-rules is possible via the expression
getYear()
. This year definition is similar toCommonElements.RELATED_GREGORIAN_YEAR
but takes into account the change from julian to gregorian calendar.When used in formatting of historic dates, Time4J will apply dual dating unless a special year definition has been set as
format attribute
. -
MONTH_OF_YEAR
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<Month,HistoricCalendar> MONTH_OF_YEARRepresents the historic month.
The expression
with(MONTH_OF_YEAR.incremented())
works in the following way:- If possible the current day of month will be kept.
- If the new month has a shorter length than the current day of month then the day of month will be the maximum day of the new month.
- If this date is the first day of month and is not valid on next month due to a gap on the date line then the new day of month will be corrected to be the first valid day of the new month.
Example (AD-1610-09-01 is invalid!):
ChronoHistory history = ChronoHistory.of(new Locale("de", "DE", "PREUSSEN")); HistoricCalendar cal = HistoricCalendar.of(history, HistoricEra.AD, 1610, 8, 1); System.out.println(cal.with(HistoricCalendar.MONTH_OF_YEAR.incremented())); // AD-1610-09-02[...]
-
DAY_OF_MONTH
@FormattableElement(format="d") public static final StdCalendarElement<Integer,HistoricCalendar> DAY_OF_MONTHRepresents the historic day of month.
-
DAY_OF_YEAR
@FormattableElement(format="D") public static final StdCalendarElement<Integer,HistoricCalendar> DAY_OF_YEARRepresents the historic day of year.
-
DAY_OF_WEEK
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,HistoricCalendar> DAY_OF_WEEKRepresents the historic day of week.
If the day-of-week is set to a new value then Time4J handles the historic calendar week as starting on Sunday (usual in christian context).
-
WEEKDAY_IN_MONTH
@FormattableElement(format="F") public static final OrdinalWeekdayElement<HistoricCalendar> WEEKDAY_IN_MONTHElement with the ordinal day-of-week within given calendar month.
-
-
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 modelera
- historic erarelatedStandardYear
- the related standard year of era (>= 1
) starting on January the firsthistoricMonth
- 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 modelera
- historic erayearOfEra
- year of era which will be interpreted according to given year definition (>= 1
)yearDefinition
- defines a strategy how to interprete year of erahistoricMonth
- 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
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
Obtains the underlying calendar history.
- Returns:
- ChronoHistory
-
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
Yields the historic month.
- Returns:
- enum
-
getDayOfMonth
public int getDayOfMonth()Yields the historic day of month.
- Returns:
- int
-
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
Description copied from interface:VariantSource
Yields the variant name of a calendar system.
- Specified by:
getVariant
in interfaceVariantSource
- 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
Obtains the start of this year (which is often not the first of January).
- Returns:
- new year
-
nextDay
Convenient short form for
with(DAY_OF_MONTH.incremented())
orplus(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
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
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 classCalendarVariant<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 classCalendarVariant<HistoricCalendar>
-
toString
Description copied from class:CalendarVariant
Provides a complete textual representation of the state of this calendar variant.
- Specified by:
toString
in classCalendarVariant<HistoricCalendar>
-
getDefaultWeekmodel
Obtains the standard week model of this calendar.
Christian calendars usually starts on Sunday.
- Returns:
- Weekmodel
-
family
Returns the associated calendar family.
- Returns:
- chronology as calendar family
-