@thi.ng/date 2.7.2 → 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 +28 -16
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
2
|
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
|
|
3
|
-
> [!IMPORTANT]
|
|
4
|
-
> ‼️ Announcing the thi.ng user survey 2024 📋
|
|
5
|
-
>
|
|
6
|
-
> [Please participate in the survey here!](https://forms.gle/XacbSDEmQMPZg8197)\
|
|
7
|
-
> (open until end of February)
|
|
8
|
-
>
|
|
9
|
-
> **To achieve a better sample size, I'd highly appreciate if you could
|
|
10
|
-
> circulate the link to this survey in your own networks.**
|
|
11
|
-
>
|
|
12
|
-
> [Discussion](https://github.com/thi-ng/umbrella/discussions/447)
|
|
13
|
-
|
|
14
3
|
# 
|
|
15
4
|
|
|
16
5
|
[](https://www.npmjs.com/package/@thi.ng/date)
|
|
@@ -22,7 +11,7 @@
|
|
|
22
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
23
12
|
> and anti-framework.
|
|
24
13
|
>
|
|
25
|
-
> 🚀
|
|
14
|
+
> 🚀 Please help me to work full-time on these projects by [sponsoring me on
|
|
26
15
|
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
27
16
|
|
|
28
17
|
- [About](#about)
|
|
@@ -120,6 +109,8 @@ Note: `DateTime` instances also define the above keys as properties, plus
|
|
|
120
109
|
getters for week-in-year (`.w`) and quarter (`.q`).
|
|
121
110
|
|
|
122
111
|
```ts
|
|
112
|
+
import { dateTime } from "@thi.ng/date";
|
|
113
|
+
|
|
123
114
|
// create w/ current date (or pass epoch, string, Date or DateTime instances)
|
|
124
115
|
const a = dateTime();
|
|
125
116
|
// DateTime { y: 2020, M: 8, d: 19, h: 12, m: 17, s: 16, t: 884 }
|
|
@@ -164,6 +155,8 @@ offset period. Period identifiers are any `Precision` ID (see above) or `w`
|
|
|
164
155
|
(week, aka 7 days) or `q` (quarter, aka 3 months):
|
|
165
156
|
|
|
166
157
|
```ts
|
|
158
|
+
import { dateTime, difference, absDifference, asDays } from "@thi.ng/date";
|
|
159
|
+
|
|
167
160
|
const a = dateTime();
|
|
168
161
|
// DateTime { y: 2020, M: 8, d: 19, h: 12, m: 17, s: 16, t: 884 }
|
|
169
162
|
|
|
@@ -226,6 +219,8 @@ purposes (i.e. as axis tick label generators for
|
|
|
226
219
|
- `milliseconds()`
|
|
227
220
|
|
|
228
221
|
```ts
|
|
222
|
+
import { months, FMT_yyyyMMdd } from "@thi.ng/date";
|
|
223
|
+
|
|
229
224
|
[...months("2021-01-03", "2021-07-16")]
|
|
230
225
|
// [
|
|
231
226
|
// 1609459200000,
|
|
@@ -257,6 +252,8 @@ Relative dates can be obtained via
|
|
|
257
252
|
or [`relative()`](https://docs.thi.ng/umbrella/date/functions/relative.html).
|
|
258
253
|
|
|
259
254
|
```ts
|
|
255
|
+
import { dateTime, parseRelative } from "@thi.ng/date";
|
|
256
|
+
|
|
260
257
|
const now = dateTime();
|
|
261
258
|
// DateTime { y: 2021, M: 2, d: 21, h: 14, m: 26, s: 0, t: 661 }
|
|
262
259
|
|
|
@@ -284,6 +281,12 @@ Both functions use the currently active [locale](#locales) and accept an
|
|
|
284
281
|
optional reference date (default: `now()`).
|
|
285
282
|
|
|
286
283
|
```ts
|
|
284
|
+
import {
|
|
285
|
+
setLocale, withLocale, DE_LONG, EN_LONG,
|
|
286
|
+
formatRelative, formatRelativeParts, formatDuration,
|
|
287
|
+
decomposeDifference
|
|
288
|
+
} from "@thi.ng/date";
|
|
289
|
+
|
|
287
290
|
setLocale(EN_LONG);
|
|
288
291
|
|
|
289
292
|
formatRelative("2020-06-01", "2021-07-01")
|
|
@@ -418,15 +421,17 @@ part is non-zero. The 4 separators between each field can be customized via 2nd
|
|
|
418
421
|
arg (default: all `:`).
|
|
419
422
|
|
|
420
423
|
```ts
|
|
421
|
-
|
|
424
|
+
import { defTimecode, DAY, HOUR, MINUTE, SECOND } from "@thi.ng/date";
|
|
425
|
+
|
|
426
|
+
const a = defTimecode(30);
|
|
422
427
|
a(1*HOUR + 2*MINUTE + 3*SECOND + 4*1000/30)
|
|
423
428
|
// "01:02:03:04"
|
|
424
429
|
|
|
425
430
|
a(DAY);
|
|
426
431
|
// "01:00:00:00:00"
|
|
427
432
|
|
|
428
|
-
b = defTimecode(30, ["d ", "h ", "' ", '" ']);
|
|
429
|
-
b(
|
|
433
|
+
const b = defTimecode(30, ["d ", "h ", "' ", '" ']);
|
|
434
|
+
b(DAY + HOUR + 2*MINUTE + 3*SECOND + 999)
|
|
430
435
|
// "01d 01h 02' 03" 29"
|
|
431
436
|
```
|
|
432
437
|
|
|
@@ -449,9 +454,14 @@ by the current `LOCALE` (default: `EN_SHORT`) and can be set/changed via the
|
|
|
449
454
|
`setLocale()` function:
|
|
450
455
|
|
|
451
456
|
```ts
|
|
457
|
+
import {
|
|
458
|
+
dateTime, defFormat, setLocale,
|
|
459
|
+
EN_SHORT, EN_LONG
|
|
460
|
+
} from "@thi.ng/date";
|
|
461
|
+
|
|
452
462
|
const fmt = defFormat(["E", " ", "d", " ", "MMM", " ", "yyyy"]);
|
|
453
463
|
|
|
454
|
-
setLocale(EN_SHORT); // default
|
|
464
|
+
setLocale(EN_SHORT); // also the default
|
|
455
465
|
// {
|
|
456
466
|
// months: [
|
|
457
467
|
// 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
@@ -474,6 +484,8 @@ to only temporarily set a locale and execute a function with it, then
|
|
|
474
484
|
automatically restoring the currently active locale.
|
|
475
485
|
|
|
476
486
|
```ts
|
|
487
|
+
import { dateTime, withLocale, FR_LONG } from "@thi.ng/date";
|
|
488
|
+
|
|
477
489
|
fmt(dateTime());
|
|
478
490
|
// 'Fri 16 Jul 2021'
|
|
479
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",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"test": "bun test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.9.
|
|
39
|
-
"@thi.ng/checks": "^3.5.
|
|
40
|
-
"@thi.ng/strings": "^3.7.
|
|
38
|
+
"@thi.ng/api": "^8.9.27",
|
|
39
|
+
"@thi.ng/checks": "^3.5.1",
|
|
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
|
}
|