ts-time-format/DateFormatter
Consumption
import DateFormatter, {DateCompiler, DATE_COMPILERS, ERA_COMPILER, YEAR_COMPILER, YEAR_OF_ERA_COMPILER, DAY_OF_YEAR_COMPILER, MONTH_COMPILER, DAY_OF_MONTH_COMPILER, QUARTER_OF_YEAR_COMPILER, WEEK_BASED_YEAR_COMPILER, WEEK_OF_WEEK_BASED_YEAR_COMPILER, DAY_OF_WEEK_TEXT_COMPILER, DAY_OF_WEEK_COMPILER} from "ts-time-format/DateFormatter";
Default export#
Hierarchy#
Description#
Formatter of
LocalDate to a string. You may initialize a formatter explicitly by using
of method,
or implicitly by using
ofPattern method. See
DATE_COMPILERS for supported pattern characters. See
parsePattern for general pattern writing guidelines.
Methods#
(value: LocalDate, 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#
(components: TemporalFormatComponent<LocalDate>[]): DateFormatter
- components
- Ordered array of format components.
- returns
- Formatter.
Constructs a formatter explicitly by components.
ofPattern#
(pattern: string, compilers: Dictionary<DateCompiler> = DATE_COMPILERS): DateFormatter
- 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.
DateCompiler#
Hierarchy#
Description#
TemporalCompiler for
LocalDate.
Fields#
readonly maxLength: number
Maximum number of sequential characters supported in a pattern.
Methods#
(value: LocalDate, 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.
DATE_COMPILERS#
DATE_COMPILERS: Dictionary<DateCompiler>
Default dictionary from pattern character to the respective compiler:
ERA_COMPILER#
ERA_COMPILER: DateCompiler
Depending on length:
- Writes context.eraShortNames[date.era.value] (default to "BC", "AD")
- Writes context.eraNames[date.era.value] (default to "Before Christ", "Anno Domini")
- Writes context.eraAbbreviations[date.era.value] (default to "B", "A")
Default pattern character is "G".
YEAR_COMPILER#
YEAR_COMPILER: DateCompiler
Depending on length:
- Writes String(date.year).
- Writes two lower-rank digits of date.year. For example, writes "09" for 2009 year. Includes sign for BC, e.g. "-09" for -9 year.
- Same as 1.
- Same as 1.
Default pattern character is "u".
YEAR_OF_ERA_COMPILER#
DAY_OF_YEAR_COMPILER#
DAY_OF_YEAR_COMPILER: DateCompiler
Depending on length:
- Writes String(date.dayOfYear).
- or 3. Writes date.dayOfYear, prepending it with leading zeros if necessary to ensure 2/3 digits.
For example, writes "023" for 23rd of January and length 3.
Default pattern character is "D".
MONTH_COMPILER#
MONTH_COMPILER: DateCompiler
Depending on length:
- Writes String(date.month.value).
- Writes date.month.value, prepending it with a leading zero if necessary to ensure 2 digits.
For example, writes "02" for February.
- Writes context.monthShortNames[date.month.value - 1] (default to "Jan", "Feb"...)
- Writes context.monthNames[date.month.value - 1] (default to "January", "February"...)
- Writes context.monthAbbreviations[date.month.value - 1] (default to "J", "F"...)
Default pattern character is "M" or "L".
DAY_OF_MONTH_COMPILER#
DAY_OF_MONTH_COMPILER: DateCompiler
Depending on length:
- Writes String(date.dayOfMonth).
- Writes date.dayOfMonth, prepending it with a leading zero if necessary to ensure 2 digits.
For example, writes "06" for 6th of February.
Default pattern character is "d".
QUARTER_OF_YEAR_COMPILER#
QUARTER_OF_YEAR_COMPILER: DateCompiler
Depending on length:
- Writes String(date.quarterOfYear).
- Writes date.quarterOfYear, prepending it with a leading zero to ensure 2 digits.
For example, writes "04" for 4th quarter.
- Writes context.quarterShortNames[date.quarterOfYear - 1] (default to "Q1", "Q2"...)
- Writes context.quarterNames[date.quarterOfYear - 1] (default to "1st quarter", "2nd quarter"...)
Default pattern character is "Q" or "q".
WEEK_BASED_YEAR_COMPILER#
WEEK_OF_WEEK_BASED_YEAR_COMPILER#
WEEK_OF_WEEK_BASED_YEAR_COMPILER: DateCompiler
Depending on length:
- Writes String(date.weekOfWeekBasedYear).
- Writes date.weekOfWeekBasedYear, prepending it with a leading zero if necessary to ensure 2 digits.
For example, writes "09" for 9th week of year.
Default pattern character is "w".
DAY_OF_WEEK_TEXT_COMPILER#
DAY_OF_WEEK_TEXT_COMPILER: DateCompiler
Depending on length:
- Writes context.dayOfWeekShortNames[date.dayOfWeek.value - 1] (default to "Mon", "Tue"...)
- Writes context.dayOfWeekNames[date.dayOfWeek.value - 1] (default to "Monday", "Tuesday"...)
- Writes context.dayOfWeekAbbreviations[date.dayOfWeek.value - 1] (default to "M", "T")
Default pattern character is "E".
DAY_OF_WEEK_COMPILER#
DAY_OF_WEEK_COMPILER: DateCompiler
Depending on length:
- Writes String(date.dayOfWeek.value).
- Writes date.dayOfWeek.value, prepending it with a leading zero to ensure 2 digits.
For example, writes "04" for Thursday.
- or 4. or 5. Same as DAY_OF_WEEK_TEXT_COMPILER's 1, 2 and 3 respectively.
Default pattern character is "e" or "c".