@thi.ng/date 2.7.3 → 2.7.4
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 +1 -1
- package/README.md +27 -4
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -109,6 +109,8 @@ Note: `DateTime` instances also define the above keys as properties, plus
|
|
|
109
109
|
getters for week-in-year (`.w`) and quarter (`.q`).
|
|
110
110
|
|
|
111
111
|
```ts
|
|
112
|
+
import { dateTime } from "@thi.ng/date";
|
|
113
|
+
|
|
112
114
|
// create w/ current date (or pass epoch, string, Date or DateTime instances)
|
|
113
115
|
const a = dateTime();
|
|
114
116
|
// DateTime { y: 2020, M: 8, d: 19, h: 12, m: 17, s: 16, t: 884 }
|
|
@@ -153,6 +155,8 @@ offset period. Period identifiers are any `Precision` ID (see above) or `w`
|
|
|
153
155
|
(week, aka 7 days) or `q` (quarter, aka 3 months):
|
|
154
156
|
|
|
155
157
|
```ts
|
|
158
|
+
import { dateTime, difference, absDifference, asDays } from "@thi.ng/date";
|
|
159
|
+
|
|
156
160
|
const a = dateTime();
|
|
157
161
|
// DateTime { y: 2020, M: 8, d: 19, h: 12, m: 17, s: 16, t: 884 }
|
|
158
162
|
|
|
@@ -215,6 +219,8 @@ purposes (i.e. as axis tick label generators for
|
|
|
215
219
|
- `milliseconds()`
|
|
216
220
|
|
|
217
221
|
```ts
|
|
222
|
+
import { months, FMT_yyyyMMdd } from "@thi.ng/date";
|
|
223
|
+
|
|
218
224
|
[...months("2021-01-03", "2021-07-16")]
|
|
219
225
|
// [
|
|
220
226
|
// 1609459200000,
|
|
@@ -246,6 +252,8 @@ Relative dates can be obtained via
|
|
|
246
252
|
or [`relative()`](https://docs.thi.ng/umbrella/date/functions/relative.html).
|
|
247
253
|
|
|
248
254
|
```ts
|
|
255
|
+
import { dateTime, parseRelative } from "@thi.ng/date";
|
|
256
|
+
|
|
249
257
|
const now = dateTime();
|
|
250
258
|
// DateTime { y: 2021, M: 2, d: 21, h: 14, m: 26, s: 0, t: 661 }
|
|
251
259
|
|
|
@@ -273,6 +281,12 @@ Both functions use the currently active [locale](#locales) and accept an
|
|
|
273
281
|
optional reference date (default: `now()`).
|
|
274
282
|
|
|
275
283
|
```ts
|
|
284
|
+
import {
|
|
285
|
+
setLocale, withLocale, DE_LONG, EN_LONG,
|
|
286
|
+
formatRelative, formatRelativeParts, formatDuration,
|
|
287
|
+
decomposeDifference
|
|
288
|
+
} from "@thi.ng/date";
|
|
289
|
+
|
|
276
290
|
setLocale(EN_LONG);
|
|
277
291
|
|
|
278
292
|
formatRelative("2020-06-01", "2021-07-01")
|
|
@@ -407,15 +421,17 @@ part is non-zero. The 4 separators between each field can be customized via 2nd
|
|
|
407
421
|
arg (default: all `:`).
|
|
408
422
|
|
|
409
423
|
```ts
|
|
410
|
-
|
|
424
|
+
import { defTimecode, DAY, HOUR, MINUTE, SECOND } from "@thi.ng/date";
|
|
425
|
+
|
|
426
|
+
const a = defTimecode(30);
|
|
411
427
|
a(1*HOUR + 2*MINUTE + 3*SECOND + 4*1000/30)
|
|
412
428
|
// "01:02:03:04"
|
|
413
429
|
|
|
414
430
|
a(DAY);
|
|
415
431
|
// "01:00:00:00:00"
|
|
416
432
|
|
|
417
|
-
b = defTimecode(30, ["d ", "h ", "' ", '" ']);
|
|
418
|
-
b(
|
|
433
|
+
const b = defTimecode(30, ["d ", "h ", "' ", '" ']);
|
|
434
|
+
b(DAY + HOUR + 2*MINUTE + 3*SECOND + 999)
|
|
419
435
|
// "01d 01h 02' 03" 29"
|
|
420
436
|
```
|
|
421
437
|
|
|
@@ -438,9 +454,14 @@ by the current `LOCALE` (default: `EN_SHORT`) and can be set/changed via the
|
|
|
438
454
|
`setLocale()` function:
|
|
439
455
|
|
|
440
456
|
```ts
|
|
457
|
+
import {
|
|
458
|
+
dateTime, defFormat, setLocale,
|
|
459
|
+
EN_SHORT, EN_LONG
|
|
460
|
+
} from "@thi.ng/date";
|
|
461
|
+
|
|
441
462
|
const fmt = defFormat(["E", " ", "d", " ", "MMM", " ", "yyyy"]);
|
|
442
463
|
|
|
443
|
-
setLocale(EN_SHORT); // default
|
|
464
|
+
setLocale(EN_SHORT); // also the default
|
|
444
465
|
// {
|
|
445
466
|
// months: [
|
|
446
467
|
// 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
@@ -463,6 +484,8 @@ to only temporarily set a locale and execute a function with it, then
|
|
|
463
484
|
automatically restoring the currently active locale.
|
|
464
485
|
|
|
465
486
|
```ts
|
|
487
|
+
import { dateTime, withLocale, FR_LONG } from "@thi.ng/date";
|
|
488
|
+
|
|
466
489
|
fmt(dateTime());
|
|
467
490
|
// 'Fri 16 Jul 2021'
|
|
468
491
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/date",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.4",
|
|
4
4
|
"description": "Datetime types, relative dates, math, iterators, composable formatters, locales",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@thi.ng/api": "^8.9.27",
|
|
39
39
|
"@thi.ng/checks": "^3.5.1",
|
|
40
|
-
"@thi.ng/strings": "^3.7.
|
|
40
|
+
"@thi.ng/strings": "^3.7.20"
|
|
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": "
|
|
135
|
+
"gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
|
|
136
136
|
}
|