Overview
The Advanced Format plugin extends the.format() method with additional tokens for ordinal formatting and timezone names. It builds on top of the core formatting functionality with intelligent caching for optimal performance.
Installation
Load the plugin using eitherextend or lazyLoad:
Additional Format Tokens
This plugin adds four new format tokens:| Token | Description | Example Output |
|---|---|---|
Do | Day of month with ordinal | 1st, 2nd, 3rd, 21st |
Qo | Quarter of year with ordinal | 1st, 2nd, 3rd, 4th |
zzz | Short timezone name | PST, EST, GMT |
zzzz | Full timezone name | Pacific Standard Time |
Methods
.format(templateString, locale?)
The existing .format() method is extended to support the new tokens. All core format tokens remain available.
Signature:
Ordinal Formatting
Day of Month (Do)
Formats the day of the month with the appropriate ordinal suffix.
Examples:
Quarter (Qo)
Formats the quarter of the year with ordinal suffix.
Examples:
Localized Ordinals
Ordinals are automatically localized based on the locale setting:English (en)
Spanish (es)
French (fr)
German (de)
Japanese (ja)
Chinese (zh)
Supported Ordinal Locales
The plugin includes built-in ordinal support for:- English (
en) - Spanish (
es) - French (
fr) - German (
de) - Italian (
it) - Portuguese (
pt) - Russian (
ru) - Japanese (
ja) - Korean (
ko) - Chinese (
zh)
Timezone Name Formatting
Short Timezone Name (zzz)
Displays the abbreviated timezone name.
Examples:
Full Timezone Name (zzzz)
Displays the full timezone name.
Examples:
Localized Timezone Names
Timezone names are localized based on the locale parameter:Daylight Saving Time (DST)
Timezone names automatically adjust for DST:Complex Format Examples
Date with Ordinals
Time with Timezone
Combined Formats
Performance
The plugin includes two separate LRU caches:- Ordinal Cache: Stores up to 200 ordinal formatting results
- Timezone Cache: Stores up to 100 timezone name formatting results
Cache Management
Error Handling
The plugin includes comprehensive error handling:- Invalid tokens return the original token string
- Timezone formatting errors fall back to the timezone ID
- Unsupported locales return numbers without ordinals
- All errors are logged to console with
console.warn()
Best Practices
- Use locale-specific ordinals: Set the appropriate locale for correct ordinal formatting
- Include timezone context: When displaying times, include timezone information for clarity
- Test DST transitions: Be aware that timezone names change during DST transitions
- Cache benefits: Reuse format strings to benefit from caching
- Combine with core tokens: All core format tokens work alongside advanced tokens