Class ChronoFieldFormatter

Class to parse locale-specific chronological field names of the Gregorian calendar.

Hierarchy

  • ChronoFieldFormatter

Constructors

Properties

#locale: string
#monthFormat: DateTimeFormat
#values: Map<ChronoField, Map<string, ChronoFieldValue>>
#weekdayFormat: DateTimeFormat

Accessors

Methods

  • Format a minutes-of-day value into a HH:MM style string.

    Parameters

    • mins: number

      the minutes of day to format

    Returns string

    the formatted value

  • Parse a day-of-month value in string number form.

    Parameters

    • value: string

      the value to parse as a day-of-month number

    • ubv: string

      the unbounded value to use

    Returns undefined | ChronoFieldValue

    the field value, or undefined if not parsable

  • Parse a minute-of-day value in HH:MM or HH form.

    Parameters

    • value: string

      the value to parse as a minute-of-day number

    • ubv: string

      the unbounded value to use

    Returns undefined | ChronoFieldValue

    the field value, or undefined if not parsable

  • Parse a year value in string number form.

    Parameters

    • value: string

      the value to parse as a year number

    • ubv: string

      the unbounded value to use

    Returns undefined | ChronoFieldValue

    the field value, or undefined if not parsable

  • Format a field value into a locale-specific string.

    Parameters

    Returns string

    the formatted field value

  • Parse a chronological field range string.

    A "range string" is a string formatted like VALUE - VALUE. Whitespace is ignored, and the - VALUE portion can be omitted for a singleton range. For example, in the en-US locale, Jan-Dec would be parsed as [1..12].

    Parameters

    • field: ChronoField

      the field to parse the range values as

    • value: undefined | string

      the range string to parse

    • Optional options: IntRangeFormatOptions

      the options

    Returns undefined | IntRange

    the parsed range, or undefined if not parsable as a range

    Remarks

    If value is * then a range of "all possible values" is returned, in other words the bounding range for that field. If a field has no implicit bounds (such as YEAR) then an unbounded range is returned.

    Example

    Here are some basic examples:

    const p = ChronoFieldFormatter.forLocale("en-US");
    p.parseRange(ChronoField.MONTH_OF_YEAR, "Jan-Dec"); // [1..12]
    p.parseRange(ChronoField.MONTH_OF_YEAR, "4-6"); // [4..6]
    p.parseRange(ChronoField.DAY_OF_MONTH, "1-31"); // [1..31]
    p.parseRange(ChronoField.DAY_OF_WEEK, "Wednesday"); // [3..3]
    p.parseRange(ChronoField.MINUTE_OF_DAY, "00:00-08:30"); // [0..510]

    See

    splitRange() for more details on range delimiter handling

Generated using TypeDoc