Class CalendarText
Source for localized calendrical informations on enum basis like month or weekday names.
This class is a facade for an underlying implementation of
TextProvider which will be loaded as SPI-interface
by help of a ServiceLoader. If no such SPI-interface can be
found then this class will resort to the sources of JDK (usually
as wrapper around java.text.DateFormatSymbols).
Furthermore, an instance of CalendarText can also access
the UTF-8 text resources in the folder "calendar" relative to
the class path which are not based on JDK-defaults. In this case the
presence of the i18n-module is required. In all ISO-systems the
"iso8601_{locale}.properties"-files will override the
JDK-defaults unless it is the ROOT-locale. Example:
If you wish to use the name "Sonnabend" instead of the standard word "Samstag" in german locale (english: Saturday) then you can copy the existing file "calendar/iso8601_de.properties" from the content of "time4j-i18n-v{version}.jar"-file into a new directory with the same path. Then you can insert these lines extra (all seven entries must be inserted, not just the sixth line):
DAY_OF_WEEK(WIDE)_1=Montag DAY_OF_WEEK(WIDE)_2=Dienstag DAY_OF_WEEK(WIDE)_3=Mittwoch DAY_OF_WEEK(WIDE)_4=Donnerstag DAY_OF_WEEK(WIDE)_5=Freitag DAY_OF_WEEK(WIDE)_6=Sonnabend DAY_OF_WEEK(WIDE)_7=Sonntag
The general format of these lines is:
{element-name}({text-width}[|STANDALONE])_{one-based-integer}={text}
STANDALONE is optional. As element name in the context of ISO-8601 following names are supported:
- MONTH_OF_YEAR
- QUARTER_OF_YEAR
- DAY_OF_WEEK
- ERA
- AM_PM_OF_DAY
- Author:
- Meno Hochschild
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the internal cache.Yields anAccessorfor all era names.static CalendarTextgetInstance(String calendarType, Locale locale)Returns an instance ofCalendarTextfor given calendar type and language.static CalendarTextgetInstance(Chronology<?> chronology, Locale locale)Returns an instance ofCalendarTextfor given chronology and language.static CalendarTextgetIsoInstance(Locale locale)Returns an instance ofCalendarTextfor ISO calendar systems and given language.getLeapMonths(TextWidth textWidth, OutputContext outputContext)Yields anAccessorfor all months if a leap month is relevant.getMeridiems(TextWidth textWidth, OutputContext outputContext)Yields anAccessorfor all am/pm-names.getQuarters(TextWidth textWidth, OutputContext outputContext)Yields anAccessorfor all quarter years.getStdMonths(TextWidth textWidth, OutputContext outputContext)Yields anAccessorfor all standard months.Yields all text forms in raw format.<V extends Enum<V>>
TextAccessorgetTextForms(String name, Class<V> type, String... variants)<V extends Enum<V>>
TextAccessorgetTextForms(ChronoElement<V> element, String... variants)Yields anAccessorfor all text forms of given chronological element.getWeekdays(TextWidth textWidth, OutputContext outputContext)Yields anAccessorfor all weekday names.static booleanDetermines if given language is written in right-to-left direction.static StringpatternForDate(FormatStyle style, Locale locale)Returns the localized date pattern suitable for formatting of objects of typePlainDate.static StringpatternForDate(DisplayMode mode, Locale locale)Deprecated.static StringpatternForInterval(Locale locale)Returns the localized interval pattern.static StringpatternForMoment(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale)Returns the localized date-time pattern suitable for formatting of objects of typeMoment.static StringpatternForMoment(DisplayMode dateMode, DisplayMode timeMode, Locale locale)Deprecated.static StringpatternForTime(FormatStyle style, Locale locale)Returns the localized time pattern suitable for formatting of objects of typePlainTime.static StringpatternForTime(DisplayMode mode, Locale locale)Deprecated.static StringpatternForTimestamp(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale)Yields a format pattern without any timezone symbols for plain timestamps.static StringpatternForTimestamp(DisplayMode dateMode, DisplayMode timeMode, Locale locale)Deprecated.toString()Yields the name of the internalTextProviderin conjunction with the configuring locale.
-
Field Details
-
ISO_CALENDAR_TYPE
Default calendar type for all ISO systems.
- See Also:
- Constant Field Values
-
-
Method Details
-
getIsoInstance
Returns an instance of
CalendarTextfor ISO calendar systems and given language.- Parameters:
locale- language- Returns:
CalendarTextobject maybe cached- Since:
- 3.13/4.10
-
getInstance
Returns an instance of
CalendarTextfor given chronology and language.- Parameters:
chronology- chronology (with calendar system)locale- language- Returns:
CalendarTextobject maybe cached
-
getInstance
Returns an instance of
CalendarTextfor given calendar type and language.- Parameters:
calendarType- name of calendar systemlocale- language- Returns:
CalendarTextobject maybe cached- See Also:
CalendarType
-
getStdMonths
Yields an
Accessorfor all standard months.The underlying list is sorted such that it will obey to the typical order of months in given calendar system. ISO-systems define January as first month and at whole 12 months. Other calendar systems can also define for example 13 months. The order of element value enums must be in agreement with the order of the text forms contained here.
The default implementation handles SHORT as synonym for ABBREVIATED in the context of ISO-8601.
- Parameters:
textWidth- text width of displayed month nameoutputContext- output context (stand-alone?)- Returns:
- accessor for standard month names
- See Also:
Month
-
getLeapMonths
Yields an
Accessorfor all months if a leap month is relevant.Note: Leap months are defined in some calendar systems like the hebrew calendar ("Adar II") else there is no difference between standard and leap months escpecially not in ISO-8601.
- Parameters:
textWidth- text width of displayed month nameoutputContext- output context (stand-alone?)- Returns:
- accessor for month names
- See Also:
Month,getStdMonths(TextWidth, OutputContext)
-
getQuarters
Yields an
Accessorfor all quarter years.The underlying list of text forms is sorted in the same order as the enum
Quarterand uses its ordinal index as list index. ISO systems define the range January-March as first quarter etc. and at whole four quarters per calendar year.The default implementation handles SHORT as synonym for ABBREVIATED in the context of ISO-8601.
- Parameters:
textWidth- text width of displayed quarter nameoutputContext- output context (stand-alone?)- Returns:
- accessor for quarter names
- See Also:
Quarter
-
getWeekdays
Yields an
Accessorfor all weekday names.The underlying list of text forms is sorted such that the typical order of weekdays is used in given calendar system. ISO systems define Monday as first day of week and at whole 7 weekdays. This order is also valid for US in the context of this class although in US Sunday is considered as start of a week. The order element value enums must be in agreement with the order of text forms contained here.
- Parameters:
textWidth- text width of displayed weekday nameoutputContext- output context (stand-alone?)- Returns:
- accessor for weekday names
- See Also:
Weekday
-
getEras
Yields an
Accessorfor all era names.The underlying list of text forms is sorted such that the typical order of eras is used in given calendar system. ISO systems define era names based on their historical extensions (eras of gregorian/historic calendar) because they themselves have no internal concept of eras. The order of element value enums must be in agreement with the text forms contained here. If an era is not defined on enum basis then the format API will not evaluate this class but the
CalendarSystemto get the right text forms.- Parameters:
textWidth- text width of displayed era name- Returns:
- accessor for era names
- See Also:
CalendarSystem.getEras()
-
getMeridiems
Yields an
Accessorfor all am/pm-names.The underlying list of text forms is sorted in AM-PM-order. The order of element value enums must be the same.
- Parameters:
textWidth- text width of displayed AM/PM nameoutputContext- output context (stand-alone?)- Returns:
- accessor for AM/PM names
- See Also:
Meridiem
-
getTextForms
Yields all text forms in raw format.
- Returns:
- unmodifiable map of all text forms
- Since:
- 3.12/4.9
-
getTextForms
Yields an
Accessorfor all text forms of given chronological element.Text forms might exist in different variations. In case of enum-based variants the name of the enum (example "WIDE" in the variant
TextWidth) is to be used, in case of boolean-based variants the literals "true" and "false" are to be used.While the methods
getStdMonths(),getWeekdays()etc. are mainly based on JDK-defaults, this method is escpecially designed for querying chronological texts which are not contained in JDK. Text forms will be stored internally in the resource folder "calendar" relative to class path in properties-files using UTF-8 encoding. The basic name of these resources is the calendar type. The combination of element name and optionally variants in the form "(variant1|variant2|...|variantN)" and the underscore and finally a numerical suffix with base 1 (for era elements base 0) serves as resource text key. If there is no entry for given key in the resources then this method will simply yield the name of enum value associated with given element value.As example, the search for abbreviated historic era
HistoricEra.ADof alternative form looks up keys in this order (using E if there is an entry "useShortKeys=true"):- value of "E(a|alt)_1"
- value of "E(a)_1"
- value of "E_1"
- fallback=>AD
- Type Parameters:
V- generic type of element values based on enums- Parameters:
element- element text forms are searched forvariants- text form variants (optional)- Returns:
- accessor for any text forms
- Throws:
MissingResourceException- if for given calendar type there are no text resource files
-
getTextForms
public <V extends Enum<V>> TextAccessor getTextForms(String name, Class<V> type, String... variants)- Type Parameters:
V- generic type of element values based on enums- Parameters:
name- name of text entries in resource filetype- type of enum valuesvariants- text form variants (optional)- Returns:
- accessor for any text forms
- Throws:
MissingResourceException- if for given calendar type there are no text resource files- Since:
- 3.11/4.8
-
patternForDate
Deprecated.Returns the localized date pattern suitable for formatting of objects of type
PlainDate.- Parameters:
mode- display modelocale- language and country setting- Returns:
- localized date pattern
- Since:
- 3.13/4.10
- See Also:
PlainDate
-
patternForTime
Deprecated.Returns the localized time pattern suitable for formatting of objects of type
PlainTime.- Parameters:
mode- display modelocale- language and country setting- Returns:
- localized time pattern
- Since:
- 3.13/4.10
- See Also:
PlainTime
-
patternForTimestamp
@Deprecated public static String patternForTimestamp(DisplayMode dateMode, DisplayMode timeMode, Locale locale)Deprecated.Yields a format pattern without any timezone symbols for plain timestamps.
- Parameters:
dateMode- display mode of date parttimeMode- display mode of time partlocale- language and country setting- Returns:
- format pattern for plain timestamps without timezone symbols
- Since:
- 3.13/4.10
- See Also:
PlainTimestamp
-
patternForMoment
@Deprecated public static String patternForMoment(DisplayMode dateMode, DisplayMode timeMode, Locale locale)Deprecated.Returns the localized date-time pattern suitable for formatting of objects of type
Moment.- Parameters:
dateMode- display mode of date parttimeMode- display mode of time partlocale- language and country setting- Returns:
- localized date-time pattern including timezone symbols
- Since:
- 3.13/4.10
- See Also:
Moment
-
patternForDate
Returns the localized date pattern suitable for formatting of objects of type
PlainDate.- Parameters:
style- format stylelocale- language and country setting- Returns:
- localized date pattern
- Since:
- 5.8
- See Also:
PlainDate
-
patternForTime
Returns the localized time pattern suitable for formatting of objects of type
PlainTime.- Parameters:
style- format stylelocale- language and country setting- Returns:
- localized time pattern
- Since:
- 5.8
- See Also:
PlainTime
-
patternForTimestamp
public static String patternForTimestamp(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale)Yields a format pattern without any timezone symbols for plain timestamps.
- Parameters:
dateStyle- format style of date parttimeStyle- format style of time partlocale- language and country setting- Returns:
- format pattern for plain timestamps without timezone symbols
- Since:
- 5.8
- See Also:
PlainTimestamp
-
patternForMoment
Returns the localized date-time pattern suitable for formatting of objects of type
Moment.- Parameters:
dateStyle- format style of date parttimeStyle- format style of time partlocale- language and country setting- Returns:
- localized date-time pattern including timezone symbols
- Since:
- 5.8
- See Also:
Moment
-
patternForInterval
Returns the localized interval pattern.
Expressions of the form "{0}" will be interpreted as the start boundary format and expressions of the form "{1}" will be interpreted as the end boundary format. All other chars of the pattern will be treated as literals.
- Parameters:
locale- language and country setting- Returns:
- localized interval pattern
- Since:
- 3.13/4.10
-
toString
Yields the name of the internal
TextProviderin conjunction with the configuring locale. -
clearCache
public static void clearCache()Clears the internal cache.
This method should be called if the internal text resources have changed and must be reloaded with a suitable
ClassLoader. -
isRTL
Determines if given language is written in right-to-left direction.
- Parameters:
locale- language to be checked- Returns:
trueif right-to-left elsefalse- Since:
- 3.25/4.21
-
patternForDate(FormatStyle, Locale)