@thi.ng/date 2.7.0 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-02-22T23:15:26Z
3
+ - **Last updated**: 2024-02-28T14:23:30Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -73,7 +73,7 @@ For Node.js REPL:
73
73
  const date = await import("@thi.ng/date");
74
74
  ```
75
75
 
76
- Package sizes (brotli'd, pre-treeshake): ESM: 5.38 KB
76
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.43 KB
77
77
 
78
78
  ## Dependencies
79
79
 
@@ -280,8 +280,8 @@ Dates can be formatted as relative descriptions using
280
280
  [`formatRelative()`](https://docs.thi.ng/umbrella/date/functions/formatRelative.html)
281
281
  and
282
282
  [`formatRelativeParts()`](https://docs.thi.ng/umbrella/date/functions/formatRelativeParts.html).
283
- Both functions use the currently active [locale](#locales) and accept an optional
284
- reference date (default: now).
283
+ Both functions use the currently active [locale](#locales) and accept an
284
+ optional reference date (default: `now()`).
285
285
 
286
286
  ```ts
287
287
  setLocale(EN_LONG);
@@ -374,8 +374,10 @@ string literal, prefix the term with `\\`.
374
374
 
375
375
  The following preset formatters are available:
376
376
 
377
+ - `FMT_ISO` - `"2020-09-13T21:42:07.123Z"`
377
378
  - `FMT_ISO_SHORT` - `"2020-09-13T21:42:07Z"`
378
379
  - `FMT_yyyyMMdd` - `"2020-09-13"`
380
+ - `FMT_yyyyMMdd_ALT` - `"20200913"`
379
381
  - `FMT_Mdyyyy` - `"9/13/2020"`
380
382
  - `FMT_MMMdyyyy` - `"Sep 13 2020"`
381
383
  - `FMT_dMyyyy` - `"13/9/2020"`
@@ -384,7 +386,25 @@ The following preset formatters are available:
384
386
  - `FMT_HHmm` - `"21:42"`
385
387
  - `FMT_hm` - `"9:42 PM"`
386
388
  - `FMT_HHmmss` - `"21:42:07"`
389
+ - `FMT_HHmmss_ALT` - `"214207"`
387
390
  - `FMT_hms` - `"9:42:07 PM"`
391
+ - `FMT_yyyy` - `"2020"` (4 digit year)
392
+ - `FMT_MM` - `"12"` (2 digit month)
393
+ - `FMT_ww` - `"52"` (2 digit week)
394
+ - `FMT_dd` - `"28"` (2 digit day in month)
395
+ - `FMT_HH` - `"23"` (2 digit hour, 24h system)
396
+ - `FMT_mm` - `"59"` (2 digit minute)
397
+ - `FMT_ss` - `"01"` (2 digit second)
398
+
399
+ All formatters are fully composable/nestable, i.e. new formats can be created
400
+ using existing formats like so:
401
+
402
+ ```ts
403
+ import { defFormat, FMT_HHmmss, FMT_yyyyMMdd } from "@thi.ng/date";
404
+
405
+ defFormat([FMT_yyyyMMdd, " @ ", FMT_HHmmss])();
406
+ // "2024-02-28 @ 12:05:47"
407
+ ```
388
408
 
389
409
  ### Timecodes
390
410
 
package/duration.d.ts CHANGED
@@ -12,6 +12,8 @@ export declare const decomposeDuration: (dur: number) => number[];
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import { composeDuration } from "@thi.ng/date";
16
+ *
15
17
  * composeDuration({ h: 12, m: 34, s: 56 })
16
18
  * // 45296000
17
19
  * ```
@@ -24,6 +26,7 @@ export declare const composeDuration: (parts: Partial<Record<Precision, number>>
24
26
  *
25
27
  * @example
26
28
  * ```ts
29
+ * import { durationAs } from "@thi.ng/date";
27
30
  * durationAs("d", difference("2023-02-01T12:00:00Z", "2023-01-01"))
28
31
  * // 31.5
29
32
  * ```
package/format.d.ts CHANGED
@@ -15,6 +15,8 @@ export declare const FORMATTERS: Record<string, FormatFn>;
15
15
  *
16
16
  * @example
17
17
  * ```ts
18
+ * import { defFormat } from "@thi.ng/date";
19
+ *
18
20
  * const fmt = defFormat(["yyyy", "-", "MM", "-", "dd"]);
19
21
  *
20
22
  * fmt(new Date(2015, 3, 23))
@@ -128,6 +130,8 @@ export declare const FMT_ss: (x?: MaybeDate, utc?: boolean) => string;
128
130
  *
129
131
  * @example
130
132
  * ```ts
133
+ * import { formatRelative } from "@thi.ng/date";
134
+ *
131
135
  * formatRelative("2020-06-01", "2021-07-01")
132
136
  * // "1 year ago"
133
137
  *
@@ -160,6 +164,8 @@ export declare const formatRelative: (date: MaybeDate, base?: MaybeDate, prec?:
160
164
  *
161
165
  * @example
162
166
  * ```ts
167
+ * import { formatRelativeParts } from "@thi.ng/date";
168
+ *
163
169
  * // with default precision (seconds)
164
170
  * formatRelativeParts("2022-09-01 12:23:24", "2021-07-01 12:05")
165
171
  * // "in 1 year, 2 months, 21 hours, 18 minutes, 24 seconds"
@@ -184,6 +190,8 @@ export declare const formatRelativeParts: (date: MaybeDate, base?: MaybeDate, pr
184
190
  *
185
191
  * @example
186
192
  * ```ts
193
+ * import { formatDuration } from "@thi.ng/date";
194
+ *
187
195
  * formatDuration(45296000)
188
196
  * // "12 h, 34 min, 56 s"
189
197
  *
package/i18n.d.ts CHANGED
@@ -38,6 +38,8 @@ export declare const monthNames: () => string[];
38
38
  *
39
39
  * @example
40
40
  * ```ts
41
+ * import { withLocale } from "@thi.ng/date";
42
+ *
41
43
  * withLocale(FR_LONG, () => units(1, "y"));
42
44
  * // "1 année"
43
45
  *
@@ -69,6 +71,8 @@ export declare const units: (x: number, unit: Precision | LocaleUnit, isDativ?:
69
71
  *
70
72
  * @example
71
73
  * ```ts
74
+ * import { withLocale } from "@thi.ng/date";
75
+ *
72
76
  * withLocale(DE_LONG, () => unitsLessThan(1, "y"));
73
77
  * // "weniger als 1 Jahr"
74
78
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/date",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "Datetime types, relative dates, math, iterators, composable formatters, locales",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,9 +35,9 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.9.25",
38
+ "@thi.ng/api": "^8.9.26",
39
39
  "@thi.ng/checks": "^3.5.0",
40
- "@thi.ng/strings": "^3.7.16"
40
+ "@thi.ng/strings": "^3.7.18"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.40.1",
@@ -132,5 +132,5 @@
132
132
  "thi.ng": {
133
133
  "year": 2020
134
134
  },
135
- "gitHead": "16f2b92b5410bd35dcde6c2971c8e62783ebc472\n"
135
+ "gitHead": "190d68e7f7524631b333cfdbf32c6a23be27c166\n"
136
136
  }
package/timecode.d.ts CHANGED
@@ -10,6 +10,8 @@
10
10
  *
11
11
  * @example
12
12
  * ```ts
13
+ * import { defTimecode } from "@thi.ng/date";
14
+ *
13
15
  * a = defTimecode(30);
14
16
  * a(HOUR + 2*MINUTE + 3*SECOND + 4*1000/30)
15
17
  * // "01:02:03:04"