@beabee/beabee-common 1.8.2 → 1.8.3

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.
@@ -7,6 +7,12 @@ exports.isValidDate = exports.getMinDateUnit = exports.parseDate = void 0;
7
7
  const add_1 = __importDefault(require("date-fns/add"));
8
8
  const isValid_1 = __importDefault(require("date-fns/isValid"));
9
9
  const parseISO_1 = __importDefault(require("date-fns/parseISO"));
10
+ const startOfDay_1 = __importDefault(require("date-fns/startOfDay"));
11
+ const startOfHour_1 = __importDefault(require("date-fns/startOfHour"));
12
+ const startOfMinute_1 = __importDefault(require("date-fns/startOfMinute"));
13
+ const startOfMonth_1 = __importDefault(require("date-fns/startOfMonth"));
14
+ const startOfSecond_1 = __importDefault(require("date-fns/startOfSecond"));
15
+ const startOfYear_1 = __importDefault(require("date-fns/startOfYear"));
10
16
  // Must be ordered from highest resolution to lowest (seconds to years)
11
17
  const dateUnits = ["s", "m", "h", "d", "M", "y"];
12
18
  const dateUnitMap = {
@@ -17,6 +23,14 @@ const dateUnitMap = {
17
23
  m: "minutes",
18
24
  s: "seconds",
19
25
  };
26
+ const startOf = {
27
+ y: startOfYear_1.default,
28
+ M: startOfMonth_1.default,
29
+ d: startOfDay_1.default,
30
+ h: startOfHour_1.default,
31
+ m: startOfMinute_1.default,
32
+ s: startOfSecond_1.default,
33
+ };
20
34
  const relativeDate = /\$now(?<units>\(((y|M|d|h|m|s):(-?\d+),?)+\))?/;
21
35
  const relativeUnit = /(y|M|d|h|m|s):(-?\d+)/g;
22
36
  // Matches the different parts of an ISO 8601 date. Note we don't validate the
@@ -49,7 +63,8 @@ function parseDate(value, now) {
49
63
  .filter(([_, n]) => !!n)
50
64
  .map(([unit]) => unit);
51
65
  }
52
- return [date, getMinDateUnit(units) || "s"];
66
+ const minUnit = getMinDateUnit(units) || "s";
67
+ return [startOf[minUnit](date), minUnit];
53
68
  }
54
69
  exports.parseDate = parseDate;
55
70
  function getMinDateUnit(units) {
@@ -1,6 +1,12 @@
1
1
  import add from "date-fns/add";
2
2
  import isValid from "date-fns/isValid";
3
3
  import parseISO from "date-fns/parseISO";
4
+ import startOfDay from "date-fns/startOfDay";
5
+ import startOfHour from "date-fns/startOfHour";
6
+ import startOfMinute from "date-fns/startOfMinute";
7
+ import startOfMonth from "date-fns/startOfMonth";
8
+ import startOfSecond from "date-fns/startOfSecond";
9
+ import startOfYear from "date-fns/startOfYear";
4
10
  // Must be ordered from highest resolution to lowest (seconds to years)
5
11
  const dateUnits = ["s", "m", "h", "d", "M", "y"];
6
12
  const dateUnitMap = {
@@ -11,6 +17,14 @@ const dateUnitMap = {
11
17
  m: "minutes",
12
18
  s: "seconds",
13
19
  };
20
+ const startOf = {
21
+ y: startOfYear,
22
+ M: startOfMonth,
23
+ d: startOfDay,
24
+ h: startOfHour,
25
+ m: startOfMinute,
26
+ s: startOfSecond,
27
+ };
14
28
  const relativeDate = /\$now(?<units>\(((y|M|d|h|m|s):(-?\d+),?)+\))?/;
15
29
  const relativeUnit = /(y|M|d|h|m|s):(-?\d+)/g;
16
30
  // Matches the different parts of an ISO 8601 date. Note we don't validate the
@@ -43,7 +57,8 @@ export function parseDate(value, now) {
43
57
  .filter(([_, n]) => !!n)
44
58
  .map(([unit]) => unit);
45
59
  }
46
- return [date, getMinDateUnit(units) || "s"];
60
+ const minUnit = getMinDateUnit(units) || "s";
61
+ return [startOf[minUnit](date), minUnit];
47
62
  }
48
63
  export function getMinDateUnit(units) {
49
64
  return dateUnits.find((unit) => units.includes(unit));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beabee/beabee-common",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",