@thi.ng/date 2.7.17 → 2.7.18
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/datetime.js +3 -6
- package/format.js +3 -6
- package/iterators.js +1 -2
- package/package.json +9 -9
- package/relative.js +1 -2
- package/units.js +3 -6
package/CHANGELOG.md
CHANGED
package/datetime.js
CHANGED
|
@@ -262,10 +262,8 @@ class DateTime {
|
|
|
262
262
|
* @param prec -
|
|
263
263
|
*/
|
|
264
264
|
add(x, prec) {
|
|
265
|
-
if (prec === "w")
|
|
266
|
-
|
|
267
|
-
if (prec === "q")
|
|
268
|
-
return this.add(x * 3, "M");
|
|
265
|
+
if (prec === "w") return this.add(x * 7, "d");
|
|
266
|
+
if (prec === "q") return this.add(x * 3, "M");
|
|
269
267
|
const res = this.copy();
|
|
270
268
|
const precID = __precisionToID(prec);
|
|
271
269
|
if (precID >= 2) {
|
|
@@ -280,8 +278,7 @@ class DateTime {
|
|
|
280
278
|
m > 11 && res.y++;
|
|
281
279
|
m < 0 && res.y--;
|
|
282
280
|
res.M = m % 12;
|
|
283
|
-
if (res.M < 0)
|
|
284
|
-
res.M += 12;
|
|
281
|
+
if (res.M < 0) res.M += 12;
|
|
285
282
|
res.d = Math.min(res.d, res.daysInMonth());
|
|
286
283
|
} else if (prec === "y") {
|
|
287
284
|
res.y += x;
|
package/format.js
CHANGED
|
@@ -187,8 +187,7 @@ const FMT_mm = defFormat(["mm"]);
|
|
|
187
187
|
const FMT_ss = defFormat(["ss"]);
|
|
188
188
|
const formatRelative = (date, base = /* @__PURE__ */ new Date(), prec = 0, eps = 100) => {
|
|
189
189
|
const delta = difference(date, base);
|
|
190
|
-
if (Math.abs(delta) < eps)
|
|
191
|
-
return LOCALE.now;
|
|
190
|
+
if (Math.abs(delta) < eps) return LOCALE.now;
|
|
192
191
|
let abs = Math.abs(delta);
|
|
193
192
|
let unit;
|
|
194
193
|
if (abs < SECOND) {
|
|
@@ -219,8 +218,7 @@ const formatRelative = (date, base = /* @__PURE__ */ new Date(), prec = 0, eps =
|
|
|
219
218
|
const formatRelativeParts = (date, base = Date.now(), prec = "s", eps = 1e3) => {
|
|
220
219
|
date = ensureEpoch(date);
|
|
221
220
|
base = ensureEpoch(base);
|
|
222
|
-
if (Math.abs(date - base) < eps)
|
|
223
|
-
return LOCALE.now;
|
|
221
|
+
if (Math.abs(date - base) < eps) return LOCALE.now;
|
|
224
222
|
const [sign, ...parts] = decomposeDifference(date, base);
|
|
225
223
|
return tense(sign, formatDurationParts(parts, prec));
|
|
226
224
|
};
|
|
@@ -228,8 +226,7 @@ const formatDuration = (dur, prec = "s") => formatDurationParts(decomposeDuratio
|
|
|
228
226
|
const formatDurationParts = (parts, prec = "s") => {
|
|
229
227
|
const precID = __precisionToID(prec);
|
|
230
228
|
let maxID = precID;
|
|
231
|
-
while (!parts[maxID] && maxID > 0)
|
|
232
|
-
maxID--;
|
|
229
|
+
while (!parts[maxID] && maxID > 0) maxID--;
|
|
233
230
|
let minID = parts.findIndex((x) => x > 0);
|
|
234
231
|
minID < 0 && (minID = maxID);
|
|
235
232
|
maxID = Math.min(Math.max(maxID, minID), precID);
|
package/iterators.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/date",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.18",
|
|
4
4
|
"description": "Datetime types, relative dates, math, iterators, composable formatters, locales",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
41
|
-
"@thi.ng/strings": "^3.7.
|
|
39
|
+
"@thi.ng/api": "^8.11.2",
|
|
40
|
+
"@thi.ng/checks": "^3.6.4",
|
|
41
|
+
"@thi.ng/strings": "^3.7.33"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@microsoft/api-extractor": "^7.43.
|
|
45
|
-
"esbuild": "^0.
|
|
46
|
-
"typedoc": "^0.25.
|
|
47
|
-
"typescript": "^5.4.
|
|
44
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
45
|
+
"esbuild": "^0.21.1",
|
|
46
|
+
"typedoc": "^0.25.13",
|
|
47
|
+
"typescript": "^5.4.5"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"datastructure",
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
"thi.ng": {
|
|
133
133
|
"year": 2020
|
|
134
134
|
},
|
|
135
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
136
136
|
}
|
package/relative.js
CHANGED
|
@@ -89,8 +89,7 @@ const decomposeDifference = (a, b = /* @__PURE__ */ new Date()) => {
|
|
|
89
89
|
sec / SECOND,
|
|
90
90
|
milli
|
|
91
91
|
];
|
|
92
|
-
if (!abs)
|
|
93
|
-
return parts;
|
|
92
|
+
if (!abs) return parts;
|
|
94
93
|
const diff = (a2, b2) => {
|
|
95
94
|
const months2 = (b2.y - a2.y) * 12 + (b2.M - a2.M);
|
|
96
95
|
const bstart = +a2.add(months2, "M");
|
package/units.js
CHANGED
|
@@ -8,12 +8,9 @@ const dayInYear = (y, m, d) => DAYS_IN_MONTH_OFFSET[m] + d + ~~(m > 1 && isLeapY
|
|
|
8
8
|
const weekInYear = (y, m, d) => {
|
|
9
9
|
const start = new Date(Date.UTC(y, 0, 1)).getDay() || 7;
|
|
10
10
|
if (!m) {
|
|
11
|
-
if (start === 5 && d < 4)
|
|
12
|
-
|
|
13
|
-
if (start ===
|
|
14
|
-
return 52 + ~~isLeapYear(y - 1);
|
|
15
|
-
if (start === 7 && d < 2)
|
|
16
|
-
return 52;
|
|
11
|
+
if (start === 5 && d < 4) return 53;
|
|
12
|
+
if (start === 6 && d < 3) return 52 + ~~isLeapYear(y - 1);
|
|
13
|
+
if (start === 7 && d < 2) return 52;
|
|
17
14
|
}
|
|
18
15
|
const offset = (start < 5 ? 8 : 15) - start;
|
|
19
16
|
return Math.ceil((dayInYear(y, m, d) - offset) / 7 + 1);
|