@thi.ng/date 2.5.4 → 2.5.6

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**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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
@@ -58,7 +58,7 @@ For Node.js REPL:
58
58
  const date = await import("@thi.ng/date");
59
59
  ```
60
60
 
61
- Package sizes (brotli'd, pre-treeshake): ESM: 5.34 KB
61
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.36 KB
62
62
 
63
63
  ## Dependencies
64
64
 
package/api.js CHANGED
@@ -1,57 +1,47 @@
1
- /**
2
- * Days per month LUT (non-leap year)
3
- */
4
- export const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
5
- /**
6
- * LUT of day-in-year values for 1st of each month (non-leap year)
7
- */
8
- export const DAYS_IN_MONTH_OFFSET = [
9
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
1
+ const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2
+ const DAYS_IN_MONTH_OFFSET = [
3
+ 0,
4
+ 31,
5
+ 59,
6
+ 90,
7
+ 120,
8
+ 151,
9
+ 181,
10
+ 212,
11
+ 243,
12
+ 273,
13
+ 304,
14
+ 334
10
15
  ];
11
- /**
12
- * There're 97 leap years and 303 normal years per 400 years
13
- */
14
- export const DAYS_IN_400YEARS = 97 * 366 + 303 * 365;
15
- /**
16
- * Second duration in milliseconds
17
- */
18
- export const SECOND = 1000;
19
- /**
20
- * Minute duration in milliseconds
21
- */
22
- export const MINUTE = 60 * SECOND;
23
- /**
24
- * Hour duration in milliseconds
25
- */
26
- export const HOUR = 60 * MINUTE;
27
- /**
28
- * Day duration in milliseconds
29
- */
30
- export const DAY = 24 * HOUR;
31
- /**
32
- * Week duration in milliseconds
33
- */
34
- export const WEEK = 7 * DAY;
35
- /**
36
- * Mean year duration (365.2425 days) in milliseconds
37
- */
38
- export const YEAR = (DAYS_IN_400YEARS / 400) * DAY;
39
- /**
40
- * Mean month duration (30.436875 days) in milliseconds
41
- */
42
- export const MONTH = YEAR / 12;
43
- /**
44
- * Object which maps {@link Period} IDs to their respective values (in
45
- * milliseconds).
46
- */
47
- export const PERIODS = {
48
- y: YEAR,
49
- M: MONTH,
50
- d: DAY,
51
- h: HOUR,
52
- m: MINUTE,
53
- s: SECOND,
54
- t: 1,
55
- w: WEEK,
56
- q: 3 * MONTH,
16
+ const DAYS_IN_400YEARS = 97 * 366 + 303 * 365;
17
+ const SECOND = 1e3;
18
+ const MINUTE = 60 * SECOND;
19
+ const HOUR = 60 * MINUTE;
20
+ const DAY = 24 * HOUR;
21
+ const WEEK = 7 * DAY;
22
+ const YEAR = DAYS_IN_400YEARS / 400 * DAY;
23
+ const MONTH = YEAR / 12;
24
+ const PERIODS = {
25
+ y: YEAR,
26
+ M: MONTH,
27
+ d: DAY,
28
+ h: HOUR,
29
+ m: MINUTE,
30
+ s: SECOND,
31
+ t: 1,
32
+ w: WEEK,
33
+ q: 3 * MONTH
34
+ };
35
+ export {
36
+ DAY,
37
+ DAYS_IN_400YEARS,
38
+ DAYS_IN_MONTH,
39
+ DAYS_IN_MONTH_OFFSET,
40
+ HOUR,
41
+ MINUTE,
42
+ MONTH,
43
+ PERIODS,
44
+ SECOND,
45
+ WEEK,
46
+ YEAR
57
47
  };
package/checks.js CHANGED
@@ -1,20 +1,11 @@
1
1
  import { implementsFunction } from "@thi.ng/checks/implements-function";
2
2
  import { isNumber } from "@thi.ng/checks/is-number";
3
3
  import { isString } from "@thi.ng/checks/is-string";
4
- /**
5
- * Coerces `x` to a native JS `Date` instance.
6
- *
7
- * @param x -
8
- */
9
- export const ensureDate = (x) => isString(x) || isNumber(x)
10
- ? new Date(x)
11
- : implementsFunction(x, "toDate")
12
- ? x.toDate()
13
- : x;
14
- /**
15
- * Coerces `x` to a timestamp.
16
- *
17
- * @param x -
18
- */
19
- export const ensureEpoch = (x) => (implementsFunction(x, "getTime") ? x : ensureDate(x)).getTime();
20
- export const isLeapYear = (year) => !(year % 4) && (!!(year % 100) || !(year % 400));
4
+ const ensureDate = (x) => isString(x) || isNumber(x) ? new Date(x) : implementsFunction(x, "toDate") ? x.toDate() : x;
5
+ const ensureEpoch = (x) => (implementsFunction(x, "getTime") ? x : ensureDate(x)).getTime();
6
+ const isLeapYear = (year) => !(year % 4) && (!!(year % 100) || !(year % 400));
7
+ export {
8
+ ensureDate,
9
+ ensureEpoch,
10
+ isLeapYear
11
+ };