@nocobase/utils 1.9.53 → 1.9.55

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.
@@ -6,12 +6,13 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- type DateUnit = 'day' | 'week' | 'isoWeek' | 'month' | 'quarter' | 'year';
9
+ type DateUnit = 'minute' | 'hour' | 'day' | 'week' | 'isoWeek' | 'month' | 'quarter' | 'year';
10
10
  type RangeType = 'today' | 'yesterday' | 'tomorrow' | 'thisWeek' | 'lastWeek' | 'nextWeek' | 'thisMonth' | 'lastMonth' | 'nextMonth' | 'thisQuarter' | 'lastQuarter' | 'nextQuarter' | 'thisYear' | 'lastYear' | 'nextYear' | 'past' | 'next';
11
11
  interface RangeParams {
12
12
  type: RangeType;
13
13
  unit?: DateUnit;
14
14
  number?: number;
15
+ includeCurrent?: boolean;
15
16
  timezone?: string;
16
17
  }
17
18
  export declare const getOffsetRangeByParams: (params: RangeParams) => [string, string];
@@ -42,19 +42,31 @@ const getNow = /* @__PURE__ */ __name((tz) => {
42
42
  return (0, import_dayjs2.dayjs)().tz(tz);
43
43
  }, "getNow");
44
44
  const getOffsetRangeByParams = /* @__PURE__ */ __name((params) => {
45
- const { type, unit = "day", number = 1, timezone } = params;
45
+ const { type, unit = "day", number = 1, includeCurrent, timezone } = params;
46
46
  const now = getNow(timezone);
47
47
  const actualUnit = unit === "week" ? "isoWeek" : unit;
48
+ const shouldIncludeCurrent = includeCurrent && ["minute", "hour", "day", "week", "isoWeek", "month", "quarter", "year"].includes(unit);
49
+ const safeNumber = typeof number === "number" && Number.isFinite(number) ? Math.max(number, 1) : 1;
48
50
  let start;
49
51
  let end;
50
52
  if (type === "past") {
51
53
  const base = now.startOf(actualUnit);
52
- start = base.subtract(number, unit).startOf(actualUnit);
53
- end = base.subtract(1, unit).endOf(actualUnit);
54
+ if (shouldIncludeCurrent) {
55
+ start = base.subtract(safeNumber, unit).startOf(actualUnit);
56
+ end = base.endOf(actualUnit);
57
+ } else {
58
+ start = base.subtract(safeNumber, unit).startOf(actualUnit);
59
+ end = base.subtract(1, unit).endOf(actualUnit);
60
+ }
54
61
  } else if (type === "next") {
55
62
  const base = now.startOf(actualUnit);
56
- start = base.add(1, unit).startOf(actualUnit);
57
- end = start.add(number - 1, unit).endOf(actualUnit);
63
+ if (shouldIncludeCurrent) {
64
+ start = base.startOf(actualUnit);
65
+ end = start.add(safeNumber, unit).endOf(actualUnit);
66
+ } else {
67
+ start = base.add(1, unit).startOf(actualUnit);
68
+ end = start.add(safeNumber - 1, unit).endOf(actualUnit);
69
+ }
58
70
  } else {
59
71
  throw new Error(`Unsupported type: ${type}`);
60
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "1.9.53",
3
+ "version": "1.9.55",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -18,5 +18,5 @@
18
18
  "object-path": "^0.11.8",
19
19
  "ses": "^1.14.0"
20
20
  },
21
- "gitHead": "ab201568dfb1845ac984b15dd4432b448738d097"
21
+ "gitHead": "d711c7711a473bebc182d80e40e920059e31235e"
22
22
  }