UNPKG

@tubular/time

Version:

Date/time, IANA timezones, leap seconds, TAI/UTC conversions, calendar with settable Julian/Gregorian switchover

351 lines (278 loc) 122 kB
# @tubular/time Not all days are 24 hours. Some are 23 hours, or 25, or even 23.5 or 24.5 or 47 hours. Some minutes are 61 seconds long. How about a Thursday followed directly by a Saturday, giving Friday the slip? Or a September only 19 days long? This is a date/time library for handling both day-to-day situations (so to speak) and some weird ones too. [![npm](https://img.shields.io/npm/v/@tubular/time.svg)](https://www.npmjs.com/package/@tubular/time/) [![Coverage Status](https://coveralls.io/repos/github/kshetline/tubular_time/badge.svg?branch=master)](https://coveralls.io/github/kshetline/tubular_time) [![npm downloads](https://img.shields.io/npm/dm/@tubular/time.svg)](https://npmjs.org/package/@tubular/time/) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@tubular/time) ![license](https://img.shields.io/badge/licence-mit-informational) ## Key features<!-- omit in toc --> * Mutable and immutable DateTime objects supporting the Gregorian and Julian calendar systems, with settable crossover. * IANA timezone support, with features beyond formatting using timezones, such as parsing, accessible listings of all available timezones (single-array list, grouped by UTC offset, or grouped by region), and live updates of timezone definitions. * Supports leap seconds and conversions between TAI (International Atomic Time) and UTC (Universal Coordinated Time). * Supports and recognizes negative Daylight Saving Time. * Extensive date/time manipulation and calculation capabilities. * Many features available using a familiar Moment.js-style API. * Astronomical time conversions among TDT (Terrestrial Dynamic Time), UT1, UTC and TAI. * Local mean time, by geographic longitude, to one minute (of time) resolution. * Astronomical time conversions among TDT (Terrestrial Dynamic Time), UT1, UTC and TAI, as well as local mean time, by geographic longitude, to one minute (of time) resolution. * Internationalization via JavaScript’s `Intl` Internationalization API, with additional built-in i18n support for issues not covered by `Intl`, and US-English fallback for environments without `Intl` support. * Package suitable for tree shaking and Angular optimization. * Full TypeScript typing support. <img src="https://shetline.com/readme/tubular-time/2.4.0/montage.jpg" alt="October 1582"> **@tubular/time** is a collection of date and time classes and functions, providing extensive internationalized date/time parsing and formatting capabilities, date/time manipulations such as field-specific add/subtract, set, and roll; calendar computations; support for live-updatable IANA time zones; and a settable Julian/Gregorian calendar switchover date. This library was originally developed for an astronomy website, <https://skyviewcafe.com>, and has some features of particular interest for astronomy and historical events, but has been expanded to provide many features similar to the now-legacy-status Moment.js. Unlike Moment.js, IANA timezone handling is built in, not a separate module, with a compact set of timezone definitions that reach roughly five years into the past and five years into the future, expanded into the past and future using Daylight Saving Time rules and/or values extracted from `Intl.DateTimeFormat`. Unlike the `Intl` API, the full list of available timezones is exposed, facilitating the creation of timezone selection interfaces. Two alternate large timezone definition sets, of approximately 280K each, are available, each serving slightly different purposes. These definitions can be bundled at compile time, or loaded dynamically at run time. You can also download live updates when the IANA Time Zone Database is updated. - [Installation](#installation) - [Via npm](#via-npm) - [Via `<script>` tag](#via-script-tag) - [Basic usage](#basic-usage) - [Creating immutable `DateTime` instances with `ttime()`](#creating-immutable-datetime-instances-with-ttime) - [Formatting output](#formatting-output) - [Special CJK date formatting options](#special-cjk-date-formatting-options) - [Format string tokens](#format-string-tokens) - [Moment.js-style localized formats](#momentjs-style-localized-formats) - [@tubular/time `Intl.DateTimeFormat` shorthand string formats](#tubulartime-intldatetimeformat-shorthand-string-formats) - [Examples](#examples) - [Pre-defined formats](#pre-defined-formats) - [Parsing with a format string, and optionally a locale](#parsing-with-a-format-string-and-optionally-a-locale) - [Converting timezones](#converting-timezones) - [Converting locales](#converting-locales) - [Defining and updating timezones](#defining-and-updating-timezones) - [Live timezone updates](#live-timezone-updates) - [The `YMDDate` and `DateAndTime` objects](#the-ymddate-and-dateandtime-objects) - [Reading individual `DateTime` fields](#reading-individual-datetime-fields) - [Modifying `DateTime` values](#modifying-datetime-values) - [Using `add` (and `subtract`)](#using-add-and-subtract) - [Using `roll()`](#using-roll) - [Using `set()`](#using-set) - [Using `startOf()` and `endOf()`](#using-startof-and-endof) - [Time value](#time-value) - [Timezone offsets from UTC](#timezone-offsets-from-utc) - [Validation](#validation) - [Comparison and sorting](#comparison-and-sorting) - [Sorting an array of dates](#sorting-an-array-of-dates) - [min/max functions](#minmax-functions) - [Monthly calendar generation](#monthly-calendar-generation) - [Dealing with weird months](#dealing-with-weird-months) - [Methods](#methods) - [Another way to drop a day](#another-way-to-drop-a-day) - [Dealing with weird days](#dealing-with-weird-days) - [Typical Daylight Saving Time examples](#typical-daylight-saving-time-examples) - [Examples of big UTC offset shifts due to moving the International Dateline](#examples-of-big-utc-offset-shifts-due-to-moving-the-international-dateline) - [Leap Seconds, TAI, and Julian Dates](#leap-seconds-tai-and-julian-dates) - [Leap second time values](#leap-second-time-values) - [TAI field values](#tai-field-values) - [Converting from UT/UTC to TAI, and back again](#converting-from-ututc-to-tai-and-back-again) - [Astronomical `DateAndTime` fields](#astronomical-dateandtime-fields) - [`epochMillis`, `utcMillis`, and `taiMillis` getters/setters](#epochmillis-utcmillis-and-taimillis-getterssetters) - [Sorting and comparison with TAI and non-TAI `DateTime` instances](#sorting-and-comparison-with-tai-and-non-tai-datetime-instances) - [Global default settings](#global-default-settings) - [The `DateTime` class](#the-datetime-class) - [Constructor](#constructor) - [Locking and cloning](#locking-and-cloning) - [`DateTime` astronomical time functions](#datetime-astronomical-time-functions) - [`DateTime` static constant](#datetime-static-constant) - [`DateTime` static methods](#datetime-static-methods) - [`DateTime` getters](#datetime-getters) - [`DateTime` getter/setters](#datetime-gettersetters) - [Other `DateTime` methods](#other-datetime-methods) - [The `Calendar` class](#the-calendar-class) - [The `Timezone` class](#the-timezone-class) - [Static `Timezone` constants](#static-timezone-constants) - [Static `Timezone` getter](#static-timezone-getter) - [`LeapSecondInfo` interface](#leapsecondinfo-interface) - [Static `Timezone` methods](#static-timezone-methods) - [`Timezone` getters](#timezone-getters) - [`Timezone` methods](#timezone-methods) - [Other functions available on `ttime`](#other-functions-available-on-ttime) - [Constants available on `ttime`](#constants-available-on-ttime) ## Installation ### Via npm `npm install @tubular/time` `import { ttime, DateTime, Timezone`...`} from '@tubular/time'; // ESM` ...or... `const { ttime, DateTime, Timezone`...`} = require('@tubular/time/cjs'); // CommonJS` Documentation examples will assume **@tubular/time** has been imported as above. ### Via `<script>` tag To remotely download the full code as an ES module: ```html <script type="module"> import('https://unpkg.com/@tubular/time/dist/fesm2015/index.mjs').then(pkg => { const { ttime, DateTime, Timezone} = pkg; // ... }); </script> ``` For the old-fashioned UMD approach (which can save you from about 560K of extra data): ```html <script src="https://unpkg.com/@tubular/time/dist/data/timezone-large-alt.js"></script> <script src="https://unpkg.com/@tubular/time/dist/umd/index.js"></script> ``` _(Or ...`/data/timezone-large.js"`)_ The script element just above the `index.js` URL is an example of _optionally_ loading extended timezone definitions. Such a script element, if used, should precede the `index.js` script. The **@tubular/time** package will be available via the global variable `tbTime`. `tbTime.ttime` is the default function, and other functions, classes, and constants will also be available on this variable, such as `tbTime.DateTime`, `tbTime.julianDay`, `tbTime.TIME_MS`, etc. ## Basic usage While there are a wide range of functions and classes available from **@tubular/time**, the workhorse is the `ttime()` function, which produces immutable instances of the `DateTime` class. `function ttime(initialTime?: number | string | DateAndTime | Date | number[] | null, format?: string, locale?: string | string[]): DateTime` ### Creating immutable `DateTime` instances with `ttime()` `DateTime` instances can be created in many ways. The simplest way is to create a current-time instance, done by passing no arguments at all. Dates and times can also be expressed as strings, objects, and arrays of numbers. | | | .toString() | |---------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `ttime()` | Current time. | `DateTime<2021‑01‑28T03:29:12.040 ‑05:00>` | | `ttime('1969‑07‑12T20:17')`<br>`ttime('1969‑07‑12T20:17Z')`<br>`ttime('20210704T0945-03')`<br>`ttime('2021‑W04‑4')` | DateTime from an ISO-8601 date/time string.<br>A trailing `Z` causes the time to be parsed as UTC. Without it, your default timezone is assumed. | `DateTime<1969‑07‑12T20:17:00.000 ‑04:00§>`<br>`DateTime<1969-07-12T20:17:00.000 +00:00>`<br>`DateTime<2021-07-04T09:45:00.000 -03:00>`<br>`DateTime<2021-01-28T00:00:00.000 -05:00>` | | `ttime('2021-w05-5')` | DateTime from an ISO-8601-like date/time variant (lowercase `w` instead of uppercase `W`) for locale-based week numbering. | `DateTime<2021-01-28T00:00:00.000 -05:00>` | | `ttime('2017‑03‑02 14:45 Europe/Paris')` | From an ISO-8601 date/time (variant with space instead of `T`) and IANA timezone. | `DateTime<2017-03-02T14:45:00.000 +01:00>` | | `ttime('20:17:15')` | Dateless time from an ISO-8601 time string. | `DateTime<20:17:15.000>` | | `ttime(1200848400000)` | From a millisecond timestamp. | `DateTime<2008-01-20T12:00:00.000 -05:00>` | | `ttime({ tai: 1200848400000 })` | From a TAI millisecond timestamp. | `DateTime<2008-01-20T12:00:00.000 -05:00>` | | `ttime({ y: 2008, m: 1, d: 20, hrs: 12, min: 0 })` | From a `DateAndTime` object, short-style field names. | `DateTime<2008-01-20T12:00:00.000 -05:00>` | | `ttime({ year: 2008, month: 1, day: 20, hour: 12, minute: 0 })` | From a `DateAndTime` object, long-style field names. | `DateTime<2008-01-20T12:00:00.000 -05:00>` | | `ttime([2013, 12, 11, 10, 9, 8, 765])` | From a numeric array: year, month, day, (hour (0-23), minute, second, millisecond), in that order. | `DateTime<2013-12-11T10:09:08.765 -05:00>` | | `ttime(new Date(2008, 0, 20, 12, 0))` | From a JavaScript `Date` object. | `DateTime<2008-01-20T12:00:00.000 -05:00>` | | `ttime('Feb 26 2021 11:00:00 GMT‑0500')` | From an ECMA-262 string<br>(Parsing performed by JavaScript `Date('`*time_string*`')`). | `DateTime<2021-02-26T11:00:00.000 ‑05:00>` | | `ttime.unix(1318781876.721)` | From a Unix timestamp. | `DateTime<2011-10-16T12:17:56.721 -04:00§>` | | `ttime.unix(1318781876.721, 'UTC')` | From a Unix timestamp, with timezone. | `DateTime<2011-10-16T16:17:56.721 +00:00>` | When dealing with Daylight Saving Time, and days when clocks are turned backward, some hour/minute combinations are repeated. The time might be 1:59, go back to 1:00, then forward again to 1:59, and only after hitting 1:59 for this second time during the day, move forward to 2:00. By default, any ambiguous time is treated as the earlier time, the first occurrence of that time during a day. You can, however, use either an explicit UTC offset, or a subscript 2 (₂), to indicate the later time. `ttime('11/7/2021 1:25 AM America/Denver', 'MM/DD/YYYY h:m a z').toString()` →<br>`DateTime<2021-11-07T01:25:00.000 -06:00§>` `ttime('11/7/2021 1:25₂ AM America/Denver', 'MM/DD/YYYY h:m a z').toString()` →<br>`DateTime<2021-11-07T01:25:00.000₂-07:00>` `ttime('2021-11-07 01:25 -07:00 America/Denver').toString()` →<br>`DateTime<2021-11-07T01:25:00.000₂-07:00>` ## Formatting output Dates and times can be formatted in many ways, using a broad selection of format tokens, described in the table below. For the greatest adherence to localized formats for dates and times, you can use the I*XX* format strings, which call directly upon `Intl.DateTimeFormat` (if available) to create localized dates, times, and combined date/times. You can also produce more customized, flexible formatting, specifying the order, positioning, and style (text vs. number, fully spelled out or abbreviated, with or without leading zeros) of each date/time field, with embedded punctuation and text as desired. For example: `ttime().format('ddd MMM D, y N [at] h:mm A z')` →<br>`Wed Feb 3, 2021 AD at 8:59 PM EST` `ttime().toLocale('de').format('ddd MMM D, y N [at] h:mm A z')` →<br>`Mi 02 3, 2021 n. Chr. at 9:43 PM GMT-5` Please note that most unaccented Latin letters (a-z, A-Z) are interpreted as special formatting characters, as well as the tilde (`~`), so when using those characters as literal text they should be surrounded with square brackets, as with the word “at” in the example above. ### Special CJK date formatting options A few of the formatting tokens below can have an optional trailing tilde (`~`) added. This is for special handling of Chinese, Japanese, and Korean (CJK) date notation. The `~` is replaced, where appropriate, with `年`, `月`, or `日` for Chinese and Japanese, and with `년`, `월`, or `일` for Korean. Korean formatting also adds a space character when the following character is a letter or digit, but not when punctuation or the end of the format string comes next. For all other languages, `~` is replaced with a space character when the following character is a letter or digit, or simply removed when followed by punctuation or the end of the format string. For example: `ttime().toLocale('zh').format('MMM~YYYY~')` →<br>`8月2021年` `ttime().toLocale('es').format('MMM~YYYY~')` →<br>`ago 2021` ## Format string tokens | | Token | Output | |-----------------------------------|------------------------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Era | NNNNN<br>NNN,&nbsp;NN,&nbsp;N | BC AD<br><br>Abbreviated era (no distinction between narrow and abbreviated, as in Moment.js). | | | NNNN | Before Christ, Anno Domini<br><br>Long-form era. | | | n | BC<br><br>Abbreviated era, only shows for BC, not AD. When year is AD, leading space before `n` token is removed. | | Year | YYYYYY | -001970 -001971 ... +001907 +001971<br><br>Always-signed years, padded to six digits. | | | YYYY&nbsp;&nbsp;<br>YYYY~ | 1970 1971 ... 2029 2030<br><br>Padded to at least four digits. With `~`, `年` or `년` is added when needed for CJK locales, otherwise replaced by a space character or empty string. | | | YY | 70 71 ... 29 30<br><br>Padded to two digits with leading zero if necessary. | | | Y&nbsp;&nbsp;<br>Y~ | 1970 1971 ... 9999 +10000 +10001<br><br>Padded to at least four digits, `+` sign shown when over 9999. With `~`, `年` or `년` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | | y&nbsp;&nbsp;<br>y~ | 1 2 ... 2020 ...<br><br>Era year, for use with BC/AD, never 0 or negative. With `~`, `年` or `년` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | Week year (ISO) | GGGG | 1970 1971 ... 2029 2030, `+` sign shown when over 9999. | | | GG | 70 71 ... 29 30<br><br>Padded to two digits with leading zero if necessary. | | Week year (locale) | gggg | 1970 1971 ... 2029 2030, `+` sign shown when over 9999. | | | gg | 70 71 ... 29 30<br><br>Padded to two digits with leading zero if necessary. | | Quarter | Qo | 1st 2nd 3rd 4th | | | Q | 1 2 3 4 | | Month | MMMM&nbsp;&nbsp;<br>MMMM~ | January February ... November December<br>1月 2月 ... 11月 12月 • 一月 二月 ... 十一月 十二月 • 1월 2월 ... 11월 12월<br><br>For CJK locales, `月` or `월` is added when using either the `MMMM` and `MMMM~` token, but using `MMMM~` allows the position of the `~` to be replaced with a blank, when appropriate, for other languages. | | | MMM&nbsp;&nbsp;<br>MMM~ | Jan Feb ... Nov Dec<br>1月 2月 ... 11月 12月 • 1월 2월 ... 11월 12월<br><br>With `~`, `月` or `월` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | | MM&nbsp;&nbsp;<br>MM~ | 01 02 ... 11 12<br>01月 02月 ... 11月 12月 • 01월 02월 ... 11월 12월<br><br>With `~`, `月` or `월` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | | M&nbsp;&nbsp;<br>M~ | 1 2 ... 11 12<br>1月 2月 ... 11月 12月 • 1월 2월 ... 11월 12월<br><br>With `~`, `月` or `월` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | | Mo | 1st 2nd ... 11th 12th | | Week (ISO) | WW | 01 02 ... 52 53 | | | W | 1 2 ... 52 53 | | Week (locale) | ww | 01 02 ... 52 53 | | | w | 1 2 ... 52 53 | | Day of month | DD&nbsp;&nbsp;<br>DD~ | 01 02 ... 30 31<br><br>With `~`, `日` or `일` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | | D&nbsp;&nbsp;<br>D~ | 1 2 ... 30 31<br><br>With `~`, `日` or `일` is added when needed for CJK locales, otherwise `~` is replaced by a space character or empty string. | | | Do | 1st 2nd ... 30th 31st | | Day of year | DDDD | 001 002 ... 364 365 366 | | | DDD | 1 2 ... 364 365 366 | | Day of week | dddd | Sunday Monday ... Friday Saturday | | | ddd | Sun Mon ... Fri Sat | | | dd | Su Mo ... Fr Sa | | | d | 0 1 ... 5 6 | | | do | 0th 1st ... 5th 6th | | Day of Week (ISO) | E | 1 2 ... 6 7 | | Day of Week (locale) | e | 1 2 ... 6 7<br><br>Note: this is 1-based, not 0-based, as in Moment.js. | | Hour | HH | 00-23 | | | H | 0-23 | | | hh | 01-12, for use with AM/PM | | | h | 1-12, for use with AM/PM | | | KK | 00-11, for use with AM/PM | | | K | 0-11, for use with AM/PM | | | kk | 01-24 | | | k | 1-24 | | Day period | A | AM PM | | | a | am pm | | Minute | mm | 00-59 | | | m | 0-59 | | Second | ss | 00-59 | | | s | 0-59 | | Fractional seconds | S | 0-9 (tenths of a second) | | | SS | 00-99 (hundredths of a second) | | | SSS | 000-999 (milliseconds) | | | SSSS... | Additional zeros after milliseconds. | | Timezone | ZZZ | America/New_York, Europe/Paris, etc.<br><br>IANA timezone, if available. | | | zzz | Australian Central Standard Time, Pacific Daylight Time, etc.<br><br>_Long form names are only for output &mdash; cannot be parsed._ | | | ZZ | -0700 -0600 ... +0600 +0700<br><br>If used with a TAI time, the displayed offset will be the difference between TAI and UTC at a given moment in time. Outside of the well-defined span of officially-declared leap seconds, this offset might be displayed with millisecond precision. | | | zz,&nbsp;z | EST, CDT, MST, PDT, AEST, etc.<br><br>Please note that timezones in this format are not internationalized, and are not unambiguous when parsed. | | | Z | -07:00 -06:00 ... +06:00 +07:00 | | Unix timestamp, UTC | X | 1360013296 | | Unix millisecond timestamp, UTC | x | 1360013296123 | | Unix timestamp, epoch | XX | 1360013296 | | Unix millisecond timestamp, epoch | xx | 1360013296123 | | Unix timestamp, TAI | XT | 1360013331 | | Unix millisecond timestamp, TAI | xt | 1360013331123 | | Daylight Saving Time indicator | V | § # ^ ~ ❄<br><br>Symbol indicating DST is in effect.<br>This is typically §, meaning the clock has been turned forward one hour.<br># means two hours forward, ^ means half an hour, ~ is any other forward amount.<br>❄ is negative DST, i.e. “Winter Time”.<br>Renders one blank space when DST is not in effect. | | | v | Same as above, but no blank space when DST is not in effect. | | Occurrence indicator | R | 1:00 , 1:01 ... 1:58 , 1:59 , 1:00₂, 1:01₂ ... 1:58₂, 1:59₂, 2:00 , 2:01<br><br>A subscript 2 (₂) that denotes the second occurrence of the same clock time during a day when clocks are turned back for Daylight Saving Time. | | | r | Same as above, but no blank space when subscript isn’t needed. | **Moment.js formats not supported by @tubular/time:** DDDo, Wo, wo, yo **@tubular/time formats not supported by Moment.js:** KK, K, kk, k, ZZZ, V, v, R, r, n, I*XX* (IFF, IFL, IFM... IxM, IxS) ## Moment.js-style localized formats | | Token | Output | | -------|------:|-----------------------------------------| | Month name, day of month, day of week, year, time | LLLL | Thursday, September 4, 1986 at 8:30 PM | | | llll | Thu, Sep 4, 1986 8:30 PM | | Month name, day of month, year, time | LLL | September 4, 1986 8:30 PM | | | lll | Sep 4, 1986 8:30 PM | | Month name, day of month, year | LL | September 4, 1986 | | | ll | Sep 4, 1986 | | Month numeral, day of month, year | L | 09/04/1986 | | | l | 9/4/1986 | | Time with seconds | LTS | 8:30:25 PM | | Time | LT | 8:30 PM | ## @tubular/time `Intl.DateTimeFormat` shorthand string formats These start with a capital letter `I`, followed by one letter for the date format, which corresponds to the `dateStyle` option of `Intl.DateTimeFormat`, and one letter for the time format, corresponding to the `timeStyle` option. The capital letters `F`, `L`, `M`, and `S` correspond to the option values `'full'`, `'long'`, `'medium'`, and `'short'`. `ILS` thus specifies a long style date and a short style time. `IL` is a long style date alone, without time. `IxS` is a short style time without a date. ### Examples | Format | Output | |---|---| | IFF | `Thursday, September 4, 1986 at 8:30:00 PM Eastern Daylight Time` | | ILM | `September 4, 1986 at 8:30:00 PM` | | IS | `9/4/86` | | IxL | `8:30:00 PM EDT` | You can also augment these formats with brace-enclosed `Intl.DateTimeFormatOptions`, such as: `IMM{hourCycle:23h}` ...which will start with whatever the localized time formatting is and force it into 24-hour time, whether the standard localized form is a 12- or 24-hour format. Note that no quotes are placed around the option values, as they would be in JavaScript/TypeScript code. ## Pre-defined formats ```javascript ttime.DATETIME_LOCAL = 'Y-MM-DD[T]HH:mm'; ttime.DATETIME_LOCAL_SECONDS = 'Y-MM-DD[T]HH:mm:ss'; ttime.DATETIME_LOCAL_MS = 'Y-MM-DD[T]HH:mm:ss.SSS'; ttime.DATE = 'Y-MM-DD'; ttime.TIME = 'HH:mm'; ttime.TIME_SECONDS = 'HH:mm:ss'; ttime.TIME_MS = 'HH:mm:ss.SSS'; ttime.WEEK = 'GGGG-[W]WW'; ttime.WEEK_AND_DAY = 'GGGG-[W]WW-E'; ttime.WEEK_LOCALE = 'gggg-[w]ww'; ttime.WEEK_AND_DAY_LOCALE = 'gggg-[w]ww-e'; ttime.MONTH = 'Y-MM'; ``` ## Parsing with a format string, and optionally a locale (_As viewed via formatted output_) | | .format('IMM') | |---|---| | `ttime('02/03/32', 'MM-DD-YY')` | `Feb 3, 2032, 12:00:00 AM` | | `ttime('02/03/32', 'DD-MM-YY')` | `Mar 2, 2032, 12:00:00 AM` | | `ttime('02/03/32 4:30 pm', 'DD-MM-YY hh:mm a', 'fr')` | `2 mars 2032 à 16:30:00` | | `ttime('02/03/32', 'DD-MM-YYYY')` | `Mar 2, 0032, 12:00:00 AM` | | `ttime('2032-03-02T16:30', null, 'ru')` | `2 мар. 2032 г., 16:30:00` | | `ttime('2032-03-02T16:30', null, 'ar-sa')` | `٠٢‏/٠٣‏/٢٠٣٢ ٤:٣٠:٠٠ م` | | `ttime('2032-03-02T16:30', null, 'zh-cn')` | `2032年3月2日 下午4:30:00` | ## Converting timezones `ttime('2005-10-10 16:30 America/Los_Angeles').tz('Europe/Warsaw').toString()` →<br>`DateTime<2005-10-11T01:30:00.000 +02:00>` Please note that if you pass a second argument of `true`, the timezone is changed, _but the wall time stays the same