Home Reference Source
public class | source

CldrDateTimeFormatterBuilder

Extends:

@js-joda/core~DateTimeFormatterBuilder → CldrDateTimeFormatterBuilder

DateTimeFormatterBuilder extension functions implementing locale handling using cldr data (http://cldr.unicode.org/)

Method Summary

Public Methods
public

Appends the localized zone offset, such as 'GMT+01:00', to the formatter.

public

appendText(field: ChronoField, styleOrMap: TextStyle | Object): DateTimeFormatterBuilder

function overloading for CldrDateTimeFormatterBuilder#appendText

public

Appends the text of a date-time field to the formatter using the full text style.

public

Appends the text of a date-time field to the formatter using the specified map to supply the text.

public

Appends the text of a date-time field to the formatter.

public

appendWeekField(field: *, count: *): *

public

appendZoneText(textStyle: TextStyle): *

Appends the time-zone name, such as 'British Summer Time', to the formatter.

Public Methods

public appendLocalizedOffset(textStyle: TextStyle): * source

Appends the localized zone offset, such as 'GMT+01:00', to the formatter.

This appends a localized zone offset to the builder, the format of the localized offset is controlled by the specified {@link FormatStyle style} to this method:

  • {@link TextStyle#FULL full} - formats with localized offset text, such as 'GMT, 2-digit hour and minute field, optional second field if non-zero, and colon.
  • {@link TextStyle#SHORT short} - formats with localized offset text, such as 'GMT, hour without leading zero, optional 2-digit minute and second if non-zero, and colon.

During formatting, the offset is obtained using a mechanism equivalent to querying the temporal with {@link TemporalQueries#offset()}. If the offset cannot be obtained then an exception is thrown unless the section of the formatter is optional.

During parsing, the offset is parsed using the format defined above. If the offset cannot be parsed then an exception is thrown unless the section of the formatter is optional.

Params:

NameTypeAttributeDescription
textStyle TextStyle

the format style to use, not null

Return:

*

this, for chaining, not null

Throw:

*

IllegalArgumentException if style is neither {@link TextStyle#FULL full} nor {@link TextStyle#SHORT short}

public appendText(field: ChronoField, styleOrMap: TextStyle | Object): DateTimeFormatterBuilder source

function overloading for CldrDateTimeFormatterBuilder#appendText

if called with 1 arguments and first argument is an instance of ChronoField, then CldrDateTimeFormatterBuilder.appendTextField is executed. if called with 2 arguments and second argument is an instance of TextStyle, then CldrDateTimeFormatterBuilder.appendTextFieldStyle is executed.

Otherwise CldrDateTimeFormatterBuilder.appendTextFieldMap is executed.

Params:

NameTypeAttributeDescription
field ChronoField
  • nullable: false
styleOrMap TextStyle | Object
  • nullable: false

Return:

DateTimeFormatterBuilder

this for chaining

public appendTextField(field: TemporalField): DateTimeFormatterBuilder source

Appends the text of a date-time field to the formatter using the full text style.

The text of the field will be output during a print. The value must be within the valid range of the field. If the value cannot be obtained then an exception will be thrown. If the field has no textual representation, then the numeric value will be used.

The value will be printed as per the normal print of an integer value. Only negative numbers will be signed. No padding will be added.

Params:

NameTypeAttributeDescription
field TemporalField
  • nullable: false

the field to append, not null

Return:

DateTimeFormatterBuilder

this, for chaining, not null

public appendTextFieldMap(field: ChronoField, textLookup: Object): DateTimeFormatterBuilder source

Appends the text of a date-time field to the formatter using the specified map to supply the text.

The standard text outputting methods use the localized text in the JDK. This method allows that text to be specified directly. The supplied map is not validated by the builder to ensure that printing or parsing is possible, thus an invalid map may throw an error during later use.

Supplying the map of text provides considerable flexibility in printing and parsing. For example, a legacy application might require or supply the months of the year as "JNY", "FBY", "MCH" etc. These do not match the standard set of text for localized month names. Using this method, a map can be created which defines the connection between each value and the text:

Map<Long, String> map = new HashMap<>();
map.put(1, "JNY");
map.put(2, "FBY");
map.put(3, "MCH");
...
builder.appendText(MONTH_OF_YEAR, map);

Other uses might be to output the value with a suffix, such as "1st", "2nd", "3rd", or as Roman numerals "I", "II", "III", "IV".

During printing, the value is obtained and checked that it is in the valid range. If text is not available for the value then it is output as a number. During parsing, the parser will match against the map of text and numeric values.

Params:

NameTypeAttributeDescription
field ChronoField
  • nullable: false

the field to append, not null

textLookup Object
  • nullable: false

the map from the value to the text

Return:

DateTimeFormatterBuilder

this, for chaining, not null

public appendTextFieldStyle(field: TemporalField, textStyle: TextStyle): DateTimeFormatterBuilder source

Appends the text of a date-time field to the formatter.

The text of the field will be output during a print. The value must be within the valid range of the field. If the value cannot be obtained then an exception will be thrown. If the field has no textual representation, then the numeric value will be used.

The value will be printed as per the normal print of an integer value. Only negative numbers will be signed. No padding will be added.

Params:

NameTypeAttributeDescription
field TemporalField
  • nullable: false

the field to append, not null

textStyle TextStyle
  • nullable: false

the text style to use, not null

Return:

DateTimeFormatterBuilder

this, for chaining, not null

public appendWeekField(field: *, count: *): * source

Params:

NameTypeAttributeDescription
field *
count *

Return:

*

public appendZoneText(textStyle: TextStyle): * source

Appends the time-zone name, such as 'British Summer Time', to the formatter.

This appends an instruction to print the textual name of the zone to the builder.

During printing, the zone is obtained using a mechanism equivalent to querying the temporal with {@link TemporalQueries#zoneId()}. If the zone is a {@code ZoneOffset} it will be printed using the result of {@link ZoneOffset#getId()}. If the zone is not an offset, the textual name will be looked up for the locale set in the DateTimeFormatter. If the temporal object being printed represents an instant, then the text will be the summer or winter time text as appropriate. If the lookup for text does not find any suitable reuslt, then the {@link ZoneId#getId() ID} will be printed instead. If the zone cannot be obtained then an exception is thrown unless the section of the formatter is optional.

Parsing is not currently supported.

Params:

NameTypeAttributeDescription
textStyle TextStyle
  • nullable: false

the text style to use, not null

Return:

*

this, for chaining, not null