@thi.ng/date 2.7.17 → 2.7.19

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-04-26T13:32:20Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
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.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.7.19](https://github.com/thi-ng/umbrella/tree/@thi.ng/date@2.7.19) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
17
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
18
+
12
19
  ### [2.7.9](https://github.com/thi-ng/umbrella/tree/@thi.ng/date@2.7.9) (2024-03-18)
13
20
 
14
21
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -68,7 +68,7 @@ For Node.js REPL:
68
68
  const date = await import("@thi.ng/date");
69
69
  ```
70
70
 
71
- Package sizes (brotli'd, pre-treeshake): ESM: 5.43 KB
71
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.42 KB
72
72
 
73
73
  ## Dependencies
74
74
 
package/datetime.d.ts CHANGED
@@ -118,5 +118,5 @@ export declare const ensureDateTime: (x: MaybeDate, prec?: Precision) => DateTim
118
118
  *
119
119
  * @param x -
120
120
  */
121
- export declare const maybeIsDate: (x: any) => boolean;
121
+ export declare const maybeIsDate: (x: any) => x is string | number | DateTime | Date;
122
122
  //# sourceMappingURL=datetime.d.ts.map
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
- return this.add(x * 7, "d");
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/i18n.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isString } from "@thi.ng/checks/is-string";
2
2
  import { EN_SHORT } from "./i18n/en.js";
3
- const prepLocale = (spec) => {
3
+ const __prepLocale = (spec) => {
4
4
  const locale = {
5
5
  sepED: " ",
6
6
  sepDM: "/",
@@ -13,7 +13,7 @@ const prepLocale = (spec) => {
13
13
  !locale.dateTime && (locale.dateTime = [...locale.date, ", ", ...locale.time]);
14
14
  return locale;
15
15
  };
16
- const setLocale = (locale) => LOCALE = prepLocale(locale);
16
+ const setLocale = (locale) => LOCALE = __prepLocale(locale);
17
17
  const withLocale = (locale, fn) => {
18
18
  const old = LOCALE;
19
19
  setLocale(locale);
@@ -26,7 +26,7 @@ const withLocale = (locale, fn) => {
26
26
  throw e;
27
27
  }
28
28
  };
29
- let LOCALE = prepLocale(EN_SHORT);
29
+ let LOCALE = __prepLocale(EN_SHORT);
30
30
  const weekdayNames = () => LOCALE.days.slice();
31
31
  const monthNames = () => LOCALE.months.slice();
32
32
  const units = (x, unit, isDativ = false, unitsOnly = false) => {
package/iterators.js CHANGED
@@ -2,16 +2,15 @@ import { isString } from "@thi.ng/checks/is-string";
2
2
  import { DateTime } from "./datetime.js";
3
3
  import { floorQuarter, floorWeek } from "./round.js";
4
4
  const defIterator = (prec, tick) => {
5
- return function* (...xs) {
6
- let [from, to] = (xs.length > 1 ? xs : xs[0]).map(
5
+ return function* (...args) {
6
+ let [from, to] = (args.length > 1 ? args : args[0]).map(
7
7
  (x) => new DateTime(x).getTime()
8
8
  );
9
9
  let state = isString(prec) ? new DateTime(from, prec) : prec(from);
10
10
  let epoch = from;
11
11
  while (epoch < to) {
12
12
  epoch = state.getTime();
13
- if (epoch >= from && epoch < to)
14
- yield epoch;
13
+ if (epoch >= from && epoch < to) yield epoch;
15
14
  tick(state);
16
15
  }
17
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/date",
3
- "version": "2.7.17",
3
+ "version": "2.7.19",
4
4
  "description": "Datetime types, relative dates, math, iterators, composable formatters, locales",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/date#readme",
13
+ "homepage": "https://thi.ng/date",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -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.1",
40
- "@thi.ng/checks": "^3.6.3",
41
- "@thi.ng/strings": "^3.7.32"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/checks": "^3.6.5",
41
+ "@thi.ng/strings": "^3.7.34"
42
42
  },
43
43
  "devDependencies": {
44
- "@microsoft/api-extractor": "^7.43.0",
45
- "esbuild": "^0.20.2",
46
- "typedoc": "^0.25.12",
47
- "typescript": "^5.4.3"
44
+ "@microsoft/api-extractor": "^7.47.0",
45
+ "esbuild": "^0.21.5",
46
+ "typedoc": "^0.25.13",
47
+ "typescript": "^5.5.2"
48
48
  },
49
49
  "keywords": [
50
50
  "datastructure",
@@ -132,5 +132,5 @@
132
132
  "thi.ng": {
133
133
  "year": 2020
134
134
  },
135
- "gitHead": "0bec55821066c18eb977a7eabd42c0bb2b096d98\n"
135
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
136
136
  }
package/relative.js CHANGED
@@ -20,9 +20,9 @@ const parseRelative = (offset, base) => {
20
20
  epoch.decDay();
21
21
  return epoch;
22
22
  default: {
23
- let idx = findIndex(EN_SHORT.days, offset);
23
+ let idx = __findIndex(EN_SHORT.days, offset);
24
24
  if (idx < 0) {
25
- idx = findIndex(EN_LONG.days, offset);
25
+ idx = __findIndex(EN_LONG.days, offset);
26
26
  }
27
27
  if (idx >= 0) {
28
28
  do {
@@ -34,16 +34,16 @@ const parseRelative = (offset, base) => {
34
34
  offset
35
35
  );
36
36
  return match ? relative(
37
- parseNum(match[1], !!match[7]),
38
- parsePeriod(match[2]),
37
+ __parseNum(match[1], !!match[7]),
38
+ __parsePeriod(match[2]),
39
39
  base
40
40
  ) : void 0;
41
41
  }
42
42
  }
43
43
  };
44
- const findIndex = (items, x) => items.findIndex((y) => y.toLowerCase() === x);
45
- const parseNum = (x, past) => (x === "next " || x === "a " || x === "an " ? 1 : Number(x)) * (past ? -1 : 1);
46
- const parsePeriod = (x) => {
44
+ const __findIndex = (items, x) => items.findIndex((y) => y.toLowerCase() === x);
45
+ const __parseNum = (x, past) => (x === "next " || x === "a " || x === "an " ? 1 : Number(x)) * (past ? -1 : 1);
46
+ const __parsePeriod = (x) => {
47
47
  x = x !== "s" && x !== "ms" && x.endsWith("s") ? x.substring(0, x.length - 1) : x;
48
48
  return {
49
49
  ms: "t",
@@ -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
- return 53;
13
- if (start === 6 && d < 3)
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);