ts-time-format/OffsetFormatter

Consumption

import OffsetFormatter, {OffsetCompiler, OFFSET_COMPILERS, OFFSET_COMPILER, OFFSET_NZ_COMPILER} from "ts-time-format/OffsetFormatter";

Default export#

Hierarchy#

Description#

Formatter of ZoneOffset to a string. You may initialize a formatter explicitly by using of method, or implicitly by using ofPattern method. See OFFSET_COMPILERS for supported pattern characters. See parsePattern for general pattern writing guidelines.

Methods#

format (inherited from TemporalFormatter)#

(value: ZoneOffset, context?: any): string

value
Value to format.
context
Context object (see TemporalCompiler).
returns
Formatted string.
Formats value to a string as concatenation of write method call results on all components.

Static methods#

of#

(components: TemporalFormatComponent<ZoneOffset>[]): OffsetFormatter

components
Ordered array of format components.
returns
Formatter.
Constructs a formatter explicitly by components.
ofPattern#

(pattern: string, compilers: Dictionary<OffsetCompiler> = OFFSET_COMPILERS): OffsetFormatter

pattern
Pattern string.
compilers
Dictionary from supported pattern characters to the respective compilers.
returns
Formatter.
Constructs a formatter implicitly by pattern. See parsePattern for details.

OffsetCompiler#

Hierarchy#

Description#

TemporalCompiler for ZoneOffset.

Fields#

maxLength (inherited from TemporalCompiler)#

readonly maxLength: number

Maximum number of sequential characters supported in a pattern.

Methods#

compile (inherited from TemporalCompiler)#

(value: ZoneOffset, length: number, context: any = DEFAULT_TEMPORAL_CONTEXT): string

value
Value to compile.
length
Number of sequential characters used in a pattern.
context
Context object.
returns
Compiled string.
Compiles value to a string based on number of sequential characters specified in length and compiler-dependent context object which can be used, in particular, to specify language-specific textual strings.

OFFSET_COMPILERS#

OFFSET_COMPILERS: Dictionary<OffsetCompiler>

Default dictionary from pattern character to the respective compiler:

CharacterCompilerExamples per length
12345
XOFFSET_COMPILER+05+0500+05:00+050030+05:00:30
xOFFSET_NZ_COMPILER+05+0500+05:00+050030+05:00:30

OFFSET_COMPILER#

OFFSET_COMPILER: OffsetCompiler

For zero offset, writes "Z". Else same as OFFSET_NZ_COMPILER.

Default pattern character is "X".

OFFSET_NZ_COMPILER#

OFFSET_NZ_COMPILER: OffsetCompiler

Depending on length:

  1. Writes just the hour, such as "+01", unless the minute is non-zero in which case writes also the minute, such as "+0130".
  2. Writes the hour and minute, without a colon, such as "+0130".
  3. Writes the hour and minute, with a colon, such as "+01:30".
  4. Writes the hour and minute and optional second, without a colon, such as "+013015".
  5. Writes the hour and minute and optional second, with a colon, such as "+01:30:15".

Default pattern character is "x".