$time / %24time
This namespace provides features for date/time. Mainly, there are utilities using Date class and feature Date.prototype.toLocaleString.
version 1.5.0
see https://github.com/jaandrle/dollar_time
- ArrayOfOperation
- ArrayOfOperations
- DateArray
- Intl_UnicodeBCP47LocaleIdentifier
- Measures
- OperationTypes
- RelativeTimeFormatLocaleMatcher
- RelativeTimeFormatNumeric
- RelativeTimeFormatStyle
- Values
- ary_ianna_time_offsets
- ary_ianna_time_offsets_keyed
- ary_ianna_time_zones
- format_object
- modifications
- ordinal_numbers
- fromDate
- fromDateArguments
- fromNow
- fromString
- getCETOffset
- getCurrentTimeZone
- getDiff
- getRelative
- getTimeZone
- getTimeZoneOffset
- getTimeZoneOffsetString
- getTimeZones
- isTimeZone
- modify
- setInternalLocale
- setInternalZone
- toDate
- toLocaleString
- toRelative
- toString
Ƭ Private ArrayOfOperation<O>: [O, O extends keyof Intl.DateTimeFormatOptions ? Intl.DateTimeFormatOptions[O] : string, undefined | "ordinal_number" | "two_letters"]
First two items represents key/value of Date.prototype.toLocaleString (i. e. "weekday", "month") or "text".
Last item reprezents internal manipulations:
- "ordinal_number": Include suffix – only English supported
- "two_letters": 1→01, …
| Name | Type |
|---|---|
O |
extends OperationTypes |
Ƭ Private ArrayOfOperations: ArrayOfOperation<OperationTypes>[]
Ƭ Private DateArray: [string, string, keyof ary_ianna_time_offsets | keyof ary_ianna_time_offsets_keyed | ""]
Array<string> reprezentation of date/time:
[
date: is always in form of "YYYY-MM-DD" or "",
time: is always in form of "HH:mm:SS" or "HH:mm:00" or "",
zone: is always in form of "[+-]\d\d:\d\d" or "CET" or ""
]
Valid examples:
[ "2019-06-02", "12:35:45", "CET" ]
[ "2019-06-02", "12:35:45", "" ]
[ "2019-06-02", "", "" ]
[ "", "12:35:45", "" ]Ƭ Intl_UnicodeBCP47LocaleIdentifier: string
See {@link Intl.UnicodeBCP47LocaleIdentifier} or Intl - Locale identification and negotiation | MDN.
Ƭ Private Measures: Object
| Name | Type |
|---|---|
days |
86400000 |
hours |
3600000 |
minutes |
60000 |
months |
2419200000 |
seconds |
1000 |
weeks |
604800000 |
years |
29030400000 |
Ƭ Private OperationTypes: keyof Intl.DateTimeFormatOptions | "text"
Ƭ Private RelativeTimeFormatLocaleMatcher: "lookup" | "best fit"
The locale matching algorithm to use.
MDN.
Ƭ Private RelativeTimeFormatNumeric: "always" | "auto"
The format of output message.
MDN.
Ƭ Private RelativeTimeFormatStyle: "long" | "short" | "narrow"
The length of the internationalized message.
MDN.
Ƭ Private Values<T>: T[keyof T]
| Name |
|---|
T |
Ƭ Private ary_ianna_time_offsets: Object
This object stores offsets in ary_ianna_time_zones (time offsets as keys) and one corresponding index.
So for exmple, ary_ianna_time_offsets["-01:00"] is equal to 238 which is index of ary_ianna_time_zones[238]==='Atlantic/Cape_Verde' (always "-01:00").
| Name | Type |
|---|---|
+01:00 |
15 |
+02:00 |
8 |
+03:00 |
270 |
+04:00 |
306 |
+04:30 |
191 |
+05:00 |
221 |
+05:30 |
173 |
+05:45 |
194 |
+06:00 |
207 |
+06:30 |
232 |
+07:00 |
182 |
+08:00 |
220 |
+08:30 |
210 |
+08:45 |
249 |
+09:00 |
176 |
+09:30 |
248 |
+10:00 |
229 |
+11:00 |
314 |
+12:00 |
345 |
+13:00 |
316 |
+14:00 |
326 |
-01:00 |
238 |
-02:00 |
242 |
-03:00 |
107 |
-04:00 |
49 |
-05:00 |
92 |
-06:00 |
62 |
-07:00 |
120 |
-08:00 |
337 |
-09:00 |
320 |
-09:30 |
330 |
-10:00 |
323 |
-11:00 |
332 |
Ƭ Private ary_ianna_time_offsets_keyed: Object
This object stores offsets in ary_ianna_time_zones (timezone id as keys) and one corresponding index.
So for exmple, ary_ianna_time_offsets["CET"] is equal to 284 which is index of ary_ianna_time_zones[284]==='Europe/Prague' (in winter "+01:00" and in summer "+02:00").
IMPORTANT NOTE: BST, EET, WET hasn't been validated! … idea is to behave the same way like CET
| Name | Type |
|---|---|
BST |
275 |
CEST |
284 |
CET |
284 |
EEST |
264 |
EET |
264 |
WEST |
274 |
WET |
274 |
Ƭ Private ary_ianna_time_zones: "Africa/Abidjan" | "Africa/Accra" | "Africa/Algiers" | "Africa/Bissau" | "Africa/Cairo" | "Africa/Casablanca" | "Africa/Ceuta" | "Africa/El_Aaiun" | "Africa/Johannesburg" | "Africa/Juba" | "Africa/Khartoum" | "Africa/Lagos" | "Africa/Maputo" | "Africa/Monrovia" | "Africa/Nairobi" | "Africa/Ndjamena" | "Africa/Sao_Tome" | "Africa/Tripoli" | "Africa/Tunis" | "Africa/Windhoek" | "America/Adak" | "America/Anchorage" | "America/Araguaina" | "America/Argentina/Buenos_Aires" | "America/Argentina/Catamarca" | "America/Argentina/Cordoba" | "America/Argentina/Jujuy" | "America/Argentina/La_Rioja" | "America/Argentina/Mendoza" | "America/Argentina/Rio_Gallegos" | "America/Argentina/Salta" | "America/Argentina/San_Juan" | "America/Argentina/San_Luis" | "America/Argentina/Tucuman" | "America/Argentina/Ushuaia" | "America/Asuncion" | "America/Atikokan" | "America/Bahia_Banderas" | "America/Bahia" | "America/Barbados" | "America/Belem" | "America/Belize" | "America/Blanc-Sablon" | "America/Boa_Vista" | "America/Bogota" | "America/Boise" | "America/Cambridge_Bay" | "America/Campo_Grande" | "America/Cancun" | "America/Caracas" | "America/Cayenne" | "America/Costa_Rica" | "America/Creston" | "America/Cuiaba" | "America/Curacao" | "America/Danmarkshavn" | "America/Dawson_Creek" | "America/Dawson" | "America/Denver" | "America/Detroit" | "America/Edmonton" | "America/Eirunepe" | "America/El_Salvador" | "America/Fort_Nelson" | "America/Fortaleza" | "America/Glace_Bay" | "America/Godthab" | "America/Goose_Bay" | "America/Grand_Turk" | "America/Guatemala" | "America/Guayaquil" | "America/Guyana" | "America/Halifax" | "America/Havana" | "America/Hermosillo" | "America/Chicago" | "America/Chihuahua" | "America/Indiana/Indianapolis" | "America/Indiana/Knox" | "America/Indiana/Marengo" | "America/Indiana/Petersburg" | "America/Indiana/Tell_City" | "America/Indiana/Vevay" | "America/Indiana/Vincennes" | "America/Indiana/Winamac" | "America/Inuvik" | "America/Iqaluit" | "America/Jamaica" | "America/Juneau" | "America/Kentucky/Louisville" | "America/Kentucky/Monticello" | "America/La_Paz" | "America/Lima" | "America/Los_Angeles" | "America/Maceio" | "America/Managua" | "America/Manaus" | "America/Martinique" | "America/Matamoros" | "America/Mazatlan" | "America/Menominee" | "America/Merida" | "America/Metlakatla" | "America/Mexico_City" | "America/Miquelon" | "America/Moncton" | "America/Monterrey" | "America/Montevideo" | "America/Nassau" | "America/New_York" | "America/Nipigon" | "America/Nome" | "America/Noronha" | "America/North_Dakota/Beulah" | "America/North_Dakota/Center" | "America/North_Dakota/New_Salem" | "America/Ojinaga" | "America/Panama" | "America/Pangnirtung" | "America/Paramaribo" | "America/Phoenix" | "America/Port_of_Spain" | "America/Port-au-Prince" | "America/Porto_Velho" | "America/Puerto_Rico" | "America/Punta_Arenas" | "America/Rainy_River" | "America/Rankin_Inlet" | "America/Recife" | "America/Regina" | "America/Resolute" | "America/Rio_Branco" | "America/Santarem" | "America/Santiago" | "America/Santo_Domingo" | "America/Sao_Paulo" | "America/Scoresbysund" | "America/Sitka" | "America/St_Johns" | "America/Swift_Current" | "America/Tegucigalpa" | "America/Thule" | "America/Thunder_Bay" | "America/Tijuana" | "America/Toronto" | "America/Vancouver" | "America/Whitehorse" | "America/Winnipeg" | "America/Yakutat" | "America/Yellowknife" | "Antarctica/Casey" | "Antarctica/Davis" | "Antarctica/Macquarie" | "Antarctica/Mawson" | "Antarctica/Palmer" | "Antarctica/Rothera" | "Antarctica/Syowa" | "Antarctica/Troll" | "Antarctica/Vostok" | "Asia/Almaty" | "Asia/Amman" | "Asia/Anadyr" | "Asia/Aqtau" | "Asia/Aqtobe" | "Asia/Ashgabat" | "Asia/Atyrau" | "Asia/Baghdad" | "Asia/Baku" | "Asia/Bangkok" | "Asia/Barnaul" | "Asia/Beirut" | "Asia/Bishkek" | "Asia/Brunei" | "Asia/Colombo" | "Asia/Damascus" | "Asia/Dhaka" | "Asia/Dili" | "Asia/Dubai" | "Asia/Dushanbe" | "Asia/Famagusta" | "Asia/Gaza" | "Asia/Hebron" | "Asia/Ho_Chi_Minh" | "Asia/Hong_Kong" | "Asia/Hovd" | "Asia/Chita" | "Asia/Choibalsan" | "Asia/Irkutsk" | "Asia/Jakarta" | "Asia/Jayapura" | "Asia/Jerusalem" | "Asia/Kabul" | "Asia/Kamchatka" | "Asia/Karachi" | "Asia/Kathmandu" | "Asia/Khandyga" | "Asia/Kolkata" | "Asia/Krasnoyarsk" | "Asia/Kuala_Lumpur" | "Asia/Kuching" | "Asia/Macau" | "Asia/Magadan" | "Asia/Makassar" | "Asia/Manila" | "Asia/Nicosia" | "Asia/Novokuznetsk" | "Asia/Novosibirsk" | "Asia/Omsk" | "Asia/Oral" | "Asia/Pontianak" | "Asia/Pyongyang" | "Asia/Qatar" | "Asia/Qyzylorda" | "Asia/Riyadh" | "Asia/Sakhalin" | "Asia/Samarkand" | "Asia/Seoul" | "Asia/Shanghai" | "Asia/Singapore" | "Asia/Srednekolymsk" | "Asia/Taipei" | "Asia/Tashkent" | "Asia/Tbilisi" | "Asia/Tehran" | "Asia/Thimphu" | "Asia/Tokyo" | "Asia/Tomsk" | "Asia/Ulaanbaatar" | "Asia/Urumqi" | "Asia/Ust-Nera" | "Asia/Vladivostok" | "Asia/Yakutsk" | "Asia/Yangon" | "Asia/Yekaterinburg" | "Asia/Yerevan" | "Atlantic/Azores" | "Atlantic/Bermuda" | "Atlantic/Canary" | "Atlantic/Cape_Verde" | "Atlantic/Faroe" | "Atlantic/Madeira" | "Atlantic/Reykjavik" | "Atlantic/South_Georgia" | "Atlantic/Stanley" | "Australia/Adelaide" | "Australia/Brisbane" | "Australia/Broken_Hill" | "Australia/Currie" | "Australia/Darwin" | "Australia/Eucla" | "Australia/Hobart" | "Australia/Lindeman" | "Australia/Lord_Howe" | "Australia/Melbourne" | "Australia/Perth" | "Australia/Sydney" | "Europe/Amsterdam" | "Europe/Andorra" | "Europe/Astrakhan" | "Europe/Athens" | "Europe/Belgrade" | "Europe/Berlin" | "Europe/Brussels" | "Europe/Budapest" | "Europe/Bucharest" | "Europe/Copenhagen" | "Europe/Dublin" | "Europe/Gibraltar" | "Europe/Helsinki" | "Europe/Chisinau" | "Europe/Istanbul" | "Europe/Kaliningrad" | "Europe/Kiev" | "Europe/Kirov" | "Europe/Lisbon" | "Europe/London" | "Europe/Luxembourg" | "Europe/Madrid" | "Europe/Malta" | "Europe/Minsk" | "Europe/Monaco" | "Europe/Moscow" | "Europe/Oslo" | "Europe/Paris" | "Europe/Prague" | "Europe/Riga" | "Europe/Rome" | "Europe/Samara" | "Europe/Saratov" | "Europe/Simferopol" | "Europe/Sofia" | "Europe/Stockholm" | "Europe/Tallinn" | "Europe/Tirane" | "Europe/Ulyanovsk" | "Europe/Uzhgorod" | "Europe/Vienna" | "Europe/Vilnius" | "Europe/Volgograd" | "Europe/Warsaw" | "Europe/Zaporozhye" | "Europe/Zurich" | "Indian/Cocos" | "Indian/Chagos" | "Indian/Christmas" | "Indian/Kerguelen" | "Indian/Mahe" | "Indian/Maldives" | "Indian/Mauritius" | "Indian/Reunion" | "Pacific/Apia" | "Pacific/Auckland" | "Pacific/Bougainville" | "Pacific/Easter" | "Pacific/Efate" | "Pacific/Enderbury" | "Pacific/Fakaofo" | "Pacific/Fiji" | "Pacific/Funafuti" | "Pacific/Galapagos" | "Pacific/Gambier" | "Pacific/Guadalcanal" | "Pacific/Guam" | "Pacific/Honolulu" | "Pacific/Chatham" | "Pacific/Chuuk" | "Pacific/Kiritimati" | "Pacific/Kosrae" | "Pacific/Kwajalein" | "Pacific/Majuro" | "Pacific/Marquesas" | "Pacific/Nauru" | "Pacific/Niue" | "Pacific/Norfolk" | "Pacific/Noumea" | "Pacific/Pago_Pago" | "Pacific/Palau" | "Pacific/Pitcairn" | "Pacific/Pohnpei" | "Pacific/Port_Moresby" | "Pacific/Rarotonga" | "Pacific/Tahiti" | "Pacific/Tarawa" | "Pacific/Tongatapu" | "Pacific/Wake" | "Pacific/Wallis"
This array stores all time zones names (eg. 'Europe/Andorra') supported by { timeZone: ... } in second argument of Date.prototype.toLocaleString.
Original from stackoverflow.com/a/54500197.
Ƭ Private format_object: { [P in keyof Intl.DateTimeFormatOptions]: Intl.DateTimeFormatOptions[P]}
Ƭ Private modifications: "addDays" | "addDay" | "addMonth" | "addFullYear" | "addHours" | "addMinutes" | "addSeconds" | "setDays" | "setDay" | "setMonth" | "setFullYear" | "setHours" | "setMinutes" | "setSeconds"
Ƭ Private ordinal_numbers: ("th" | "st" | "nd" | "rd")[]
Internal helper array for {@link getOrdinalSuffix}.
• Const _: undefined
Alias for undefined which can be used to trigger default value of argument.
• Const formats: format_arrays
Predefined formats for toString.
▸ fromDate(date_instance): DateArray
Function generates DateArray from instance of Date.
$time.fromDate(new Date());| Name | Type |
|---|---|
date_instance |
Date |
▸ fromDateArguments(): DateArray
In fact, internally uses {@link DateConstructor}. See Date() constructor - JavaScript | MDN.
▸ fromDateArguments(value): DateArray
| Name | Type |
|---|---|
value |
number | string |
▸ fromDateArguments(year, month, date?, hours?, minutes?, seconds?, ms?): DateArray
| Name | Type |
|---|---|
year |
number |
month |
number |
date? |
number |
hours? |
number |
minutes? |
number |
seconds? |
number |
ms? |
number |
▸ fromNow(): DateArray
Function generates DateArray from current date/time.
Warning: Internally uses toISOString method so result is always converted to "+00:00": p($time.fromNow, $time.setTimeZone("+02:00"), $time.toString())() (p is some pipe function) — this returns "2019-07-10T16:48:43+02:00" instead of "2019-07-10T18:48:43+02:00" (current time) … the flow is "2019-07-10T18:48:43+02:00"-fromNow->"2019-07-10T16:48:43Z"-setTimeZone->"2019-07-10T16:48:43+02:00".
▸ fromString(timestamp_string?, timezone?): DateArray
Function generates DateArray from passed string.
$time.fromString("2019-06-02 12:35:45 +01:00");
$time.fromString("2019-06-02");
$time.fromString("12:35:45");
//…
$time.fromString("2019-06-02T12:35:45+01:00");
//…
$time.fromString("12:35:45+01:00 2019-06-02")
//…| Name | Type | Description |
|---|---|---|
timestamp_string? |
string |
If undefined returns result of fromNow. Otherwise, supported forms are combinations of date ("YYYY-MM-DD", "DD/MM/YYYY"), time ("HH:mm:ss", "HH:mm") and timezone ("CET", "+01:00", "-02:00", ...): |
timezone? |
ary_ianna_time_zones |
- |
▸ getCETOffset(date_array): keyof ary_ianna_time_offsets | "Z"
| Name | Type |
|---|---|
date_array |
DateArray |
keyof ary_ianna_time_offsets | "Z"
▸ getCurrentTimeZone(options?): string
Timezone name/identificator (with offset) for current timezone
| Name | Type | Description |
|---|---|---|
options? |
Object |
- |
options.description |
"long" | "none" | "short" | "ianna" | "IANNA" |
Defaults to "long" - "none" skip description - "long" (e.g., British Summer Time) - "short" (e.g., GMT+1) - "ianna"/"IANNA" (e.g. Europe/Prague): locale has no effect for this |
options.locale? |
Intl_UnicodeBCP47LocaleIdentifier |
Defaults to "en-GB" |
options.offset |
boolean |
Defaults to false Show offset part: "UTC+01:00 (…)" or "UTC+01:00" (if description="none") |
string
▸ getDiff(reference_date_array, output_measure_string, full_precision): (target_date_array: DateArray) => number
Returns date/times difference in output_measure_string.
| Name | Type |
|---|---|
reference_date_array |
DateArray |
output_measure_string |
keyof Measures |
full_precision |
boolean |
fn
▸ (target_date_array): number
Returns date/times difference in output_measure_string.
| Name | Type |
|---|---|
target_date_array |
DateArray |
number
▸ getRelative(ms_diff, options?): string
Returns string representation of time difference (fallbacks into simplfy english version – see internal function getRelativeBackup).
| Name | Type |
|---|---|
ms_diff |
number |
options? |
toRelativeOptions |
string
▸ getTimeZone(date_array, options): string
Timezone name/identificator (with offset)
| Name | Type | Description |
|---|---|---|
date_array |
DateArray |
- |
options |
Object |
- |
options.description |
"long" | "none" | "short" |
Defaults to "long" - "none" skip description - "long" (e.g., British Summer Time) - "short" (e.g., GMT+1) |
options.locale? |
Intl_UnicodeBCP47LocaleIdentifier |
Defaults to "en-GB" |
options.offset |
boolean |
Defaults to false Show offset part: "UTC+01:00 (…)" or "UTC+01:00" (if description="none") |
string
▸ getTimeZoneOffset(date_array, timeZone): number
| Name | Type |
|---|---|
date_array |
DateArray |
timeZone |
string |
number
▸ getTimeZoneOffsetString(date_array): string
| Name | Type |
|---|---|
date_array |
DateArray |
string
▸ getTimeZones(): ary_ianna_time_zones[]
▸ isTimeZone(candidate): boolean
| Name | Type |
|---|---|
candidate |
string |
boolean
▸ modify(mod_obj): (date_array: DateArray) => DateArray
Curried method, first invocation sets operations (i. e. { addDay: 1 }) and returns (date_array: DateArray)=> DateArray.
- object literal representing requested operations
- use name convention like setters for Date (only one argument is allowed)
- supports also add* commands with the same notation ("setMonth" => "addMonth")
- IMPORTANT NOTE: There are three behaviour changes
- "setMonth" is indexed from 1 (instead of 0)
- for "setDate" there is alias "setDay"
- for "addDate" there is alias "addDays"
| Name | Type |
|---|---|
mod_obj |
Record<modifications, number> |
fn
▸ (date_array): DateArray
Curried method, first invocation sets operations (i. e. { addDay: 1 }) and returns (date_array: DateArray)=> DateArray.
- object literal representing requested operations
- use name convention like setters for Date (only one argument is allowed)
- supports also add* commands with the same notation ("setMonth" => "addMonth")
- IMPORTANT NOTE: There are three behaviour changes
- "setMonth" is indexed from 1 (instead of 0)
- for "setDate" there is alias "setDay"
- for "addDate" there is alias "addDays"
| Name | Type |
|---|---|
date_array |
DateArray |
▸ setInternalLocale<L>(locale): L
If setted into undefined tries to follow user device configuration.
| Name | Type |
|---|---|
L |
extends string |
| Name | Type |
|---|---|
locale |
L |
L
▸ setInternalZone(zone): string
| Name | Type |
|---|---|
zone |
string |
string
▸ toDate(date_array?): Date
Defaults to new Date(), or if filled partialy defaults to current date/00:00:00/current zone.
| Name | Type |
|---|---|
date_array? |
DateArray |
Date
▸ toLocaleString(format_object_name, options?): (date_array: DateArray) => string
It is wrapper arround Date.prototype.toLocaleString.
| Name | Type |
|---|---|
format_object_name |
keyof format_objects |
options? |
toLocaleStringOptions |
fn
▸ (date_array): string
It is wrapper arround Date.prototype.toLocaleString.
| Name | Type |
|---|---|
date_array |
DateArray |
string
▸ toRelative(reference_date_array, options?): (target_date_array: DateArray) => string
Curried function of getRelative.
| Name | Type |
|---|---|
reference_date_array |
DateArray |
options? |
toRelativeOptions |
fn
▸ (target_date_array): string
Curried function of getRelative.
| Name | Type |
|---|---|
target_date_array |
DateArray |
string
▸ toString(format, options?): (date_array: DateArray) => string
Function generates text based on format, locale and timeZone from DateArray.
$time.toString("DD/MM/YYYY HH:mm:SS",{ locale: "en-GB" })($time.fromNow());//= "05/06/2019 09:32:20"
$time.toString($time.formats.SQL)($time.fromNow());//= "2019-06-05 09:32:20"| Name | Type | Description |
|---|---|---|
format |
string | Values<format_arrays> |
For using string see getFormatObject, else $time.formats. |
options? |
toLocaleStringOptions |
- |
fn
▸ (date_array): string
Function generates text based on format, locale and timeZone from DateArray.
$time.toString("DD/MM/YYYY HH:mm:SS",{ locale: "en-GB" })($time.fromNow());//= "05/06/2019 09:32:20"
$time.toString($time.formats.SQL)($time.fromNow());//= "2019-06-05 09:32:20"| Name | Type |
|---|---|
date_array |
DateArray |
string
▸ Private getFormatObject(format_string?): ArrayOfOperations
Generates multidimensional array for formatting (eg. "YYYY"=> [ [ "year", "numeric" ] ]). Supports:
- "YYYY", "YY",
- "MM", "MMM", "MMMM",
- "dddd" (weekday - Monday), "ddd" (shorter weekday - Mon), "dd" (Mo), "d" (0===Sun <> 6===Sat),
- "DD", "D", "Do",
- "HH", "H",
- "mm", "m",
- "SS", "S",
- "W", "Wo"
| Name | Type |
|---|---|
format_string? |
string |