@nocobase/utils 1.7.0-alpha.14 → 1.7.0-alpha.15
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/lib/client.d.ts +2 -1
- package/lib/client.js +5 -0
- package/lib/dateRangeUtils.d.ts +22 -0
- package/lib/dateRangeUtils.js +101 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/parse-date.js +6 -1
- package/lib/parse-filter.js +4 -0
- package/package.json +2 -2
package/lib/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import lodash from 'lodash';
|
|
10
10
|
import { dayjs } from './dayjs';
|
|
11
|
+
import { getDayRangeByParams, getOffsetRangeByParams } from './dateRangeUtils';
|
|
11
12
|
export * from './collections-graph';
|
|
12
13
|
export * from './common';
|
|
13
14
|
export * from './date';
|
|
@@ -28,4 +29,4 @@ export * from './parseHTML';
|
|
|
28
29
|
export * from './uid';
|
|
29
30
|
export * from './url';
|
|
30
31
|
export * from './transformMultiColumnToSingleColumn';
|
|
31
|
-
export { dayjs, lodash };
|
|
32
|
+
export { dayjs, lodash, getDayRangeByParams, getOffsetRangeByParams };
|
package/lib/client.js
CHANGED
|
@@ -38,11 +38,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
var client_exports = {};
|
|
39
39
|
__export(client_exports, {
|
|
40
40
|
dayjs: () => import_dayjs.dayjs,
|
|
41
|
+
getDayRangeByParams: () => import_dateRangeUtils.getDayRangeByParams,
|
|
42
|
+
getOffsetRangeByParams: () => import_dateRangeUtils.getOffsetRangeByParams,
|
|
41
43
|
lodash: () => import_lodash.default
|
|
42
44
|
});
|
|
43
45
|
module.exports = __toCommonJS(client_exports);
|
|
44
46
|
var import_lodash = __toESM(require("lodash"));
|
|
45
47
|
var import_dayjs = require("./dayjs");
|
|
48
|
+
var import_dateRangeUtils = require("./dateRangeUtils");
|
|
46
49
|
__reExport(client_exports, require("./collections-graph"), module.exports);
|
|
47
50
|
__reExport(client_exports, require("./common"), module.exports);
|
|
48
51
|
__reExport(client_exports, require("./date"), module.exports);
|
|
@@ -66,6 +69,8 @@ __reExport(client_exports, require("./transformMultiColumnToSingleColumn"), modu
|
|
|
66
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
70
|
0 && (module.exports = {
|
|
68
71
|
dayjs,
|
|
72
|
+
getDayRangeByParams,
|
|
73
|
+
getOffsetRangeByParams,
|
|
69
74
|
lodash,
|
|
70
75
|
...require("./collections-graph"),
|
|
71
76
|
...require("./common"),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
type DateUnit = 'day' | 'week' | 'isoWeek' | 'month' | 'quarter' | 'year';
|
|
10
|
+
type RangeType = 'today' | 'yesterday' | 'tomorrow' | 'thisWeek' | 'lastWeek' | 'nextWeek' | 'thisMonth' | 'lastMonth' | 'nextMonth' | 'thisQuarter' | 'lastQuarter' | 'nextQuarter' | 'thisYear' | 'lastYear' | 'nextYear' | 'past' | 'next';
|
|
11
|
+
interface RangeParams {
|
|
12
|
+
type: RangeType;
|
|
13
|
+
unit?: DateUnit;
|
|
14
|
+
number?: number;
|
|
15
|
+
timezone?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const getOffsetRangeByParams: (params: RangeParams) => [string, string];
|
|
18
|
+
/**
|
|
19
|
+
* 获取某个时间范围的起止时间(字符串格式)
|
|
20
|
+
*/
|
|
21
|
+
export declare const getDayRangeByParams: (params: RangeParams) => [string, string];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var dateRangeUtils_exports = {};
|
|
29
|
+
__export(dateRangeUtils_exports, {
|
|
30
|
+
getDayRangeByParams: () => getDayRangeByParams,
|
|
31
|
+
getOffsetRangeByParams: () => getOffsetRangeByParams
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(dateRangeUtils_exports);
|
|
34
|
+
var import_dayjs2 = require("./dayjs");
|
|
35
|
+
const getNow = /* @__PURE__ */ __name((tz) => {
|
|
36
|
+
if (!tz) return (0, import_dayjs2.dayjs)();
|
|
37
|
+
if (/^[+-]\d{2}:\d{2}$/.test(tz)) {
|
|
38
|
+
const [sign, hour, minute] = tz.match(/([+-])(\d{2}):(\d{2})/).slice(1);
|
|
39
|
+
const offset = (parseInt(hour) * 60 + parseInt(minute)) * (sign === "+" ? 1 : -1);
|
|
40
|
+
return (0, import_dayjs2.dayjs)().utcOffset(offset);
|
|
41
|
+
}
|
|
42
|
+
return (0, import_dayjs2.dayjs)().tz(tz);
|
|
43
|
+
}, "getNow");
|
|
44
|
+
const getOffsetRangeByParams = /* @__PURE__ */ __name((params) => {
|
|
45
|
+
const { type, unit = "day", number = 1, timezone } = params;
|
|
46
|
+
const now = getNow(timezone);
|
|
47
|
+
const actualUnit = unit === "week" ? "isoWeek" : unit;
|
|
48
|
+
let start;
|
|
49
|
+
let end;
|
|
50
|
+
if (type === "past") {
|
|
51
|
+
const base = now.startOf(actualUnit);
|
|
52
|
+
start = base.subtract(number, unit).startOf(actualUnit);
|
|
53
|
+
end = base.subtract(1, unit).endOf(actualUnit);
|
|
54
|
+
} else if (type === "next") {
|
|
55
|
+
const base = now.startOf(actualUnit);
|
|
56
|
+
start = base.add(1, unit).startOf(actualUnit);
|
|
57
|
+
end = start.add(number - 1, unit).endOf(actualUnit);
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error(`Unsupported type: ${type}`);
|
|
60
|
+
}
|
|
61
|
+
return [start.format("YYYY-MM-DD HH:mm:ss"), end.format("YYYY-MM-DD HH:mm:ss")];
|
|
62
|
+
}, "getOffsetRangeByParams");
|
|
63
|
+
const getStart = /* @__PURE__ */ __name((offset, unit, tz) => {
|
|
64
|
+
const actualUnit = unit === "isoWeek" ? "week" : unit;
|
|
65
|
+
return getNow(tz).add(offset, actualUnit).startOf(unit);
|
|
66
|
+
}, "getStart");
|
|
67
|
+
const getEnd = /* @__PURE__ */ __name((offset, unit, tz) => {
|
|
68
|
+
const actualUnit = unit === "isoWeek" ? "week" : unit;
|
|
69
|
+
return getNow(tz).add(offset, actualUnit).endOf(unit);
|
|
70
|
+
}, "getEnd");
|
|
71
|
+
const strategies = {
|
|
72
|
+
today: /* @__PURE__ */ __name((params) => [getStart(0, "day", params == null ? void 0 : params.timezone), getEnd(0, "day", params == null ? void 0 : params.timezone)], "today"),
|
|
73
|
+
yesterday: /* @__PURE__ */ __name((params) => [getStart(-1, "day", params == null ? void 0 : params.timezone), getEnd(-1, "day", params == null ? void 0 : params.timezone)], "yesterday"),
|
|
74
|
+
tomorrow: /* @__PURE__ */ __name((params) => [getStart(1, "day", params == null ? void 0 : params.timezone), getEnd(1, "day", params == null ? void 0 : params.timezone)], "tomorrow"),
|
|
75
|
+
thisWeek: /* @__PURE__ */ __name((params) => [getStart(0, "isoWeek", params == null ? void 0 : params.timezone), getEnd(0, "isoWeek", params == null ? void 0 : params.timezone)], "thisWeek"),
|
|
76
|
+
lastWeek: /* @__PURE__ */ __name((params) => [getStart(-1, "isoWeek", params == null ? void 0 : params.timezone), getEnd(-1, "isoWeek", params == null ? void 0 : params.timezone)], "lastWeek"),
|
|
77
|
+
nextWeek: /* @__PURE__ */ __name((params) => [getStart(1, "isoWeek", params == null ? void 0 : params.timezone), getEnd(1, "isoWeek", params == null ? void 0 : params.timezone)], "nextWeek"),
|
|
78
|
+
thisMonth: /* @__PURE__ */ __name((params) => [getStart(0, "month", params == null ? void 0 : params.timezone), getEnd(0, "month", params == null ? void 0 : params.timezone)], "thisMonth"),
|
|
79
|
+
lastMonth: /* @__PURE__ */ __name((params) => [getStart(-1, "month", params == null ? void 0 : params.timezone), getEnd(-1, "month", params == null ? void 0 : params.timezone)], "lastMonth"),
|
|
80
|
+
nextMonth: /* @__PURE__ */ __name((params) => [getStart(1, "month", params == null ? void 0 : params.timezone), getEnd(1, "month", params == null ? void 0 : params.timezone)], "nextMonth"),
|
|
81
|
+
thisQuarter: /* @__PURE__ */ __name((params) => [getStart(0, "quarter", params == null ? void 0 : params.timezone), getEnd(0, "quarter", params == null ? void 0 : params.timezone)], "thisQuarter"),
|
|
82
|
+
lastQuarter: /* @__PURE__ */ __name((params) => [getStart(-1, "quarter", params == null ? void 0 : params.timezone), getEnd(-1, "quarter", params == null ? void 0 : params.timezone)], "lastQuarter"),
|
|
83
|
+
nextQuarter: /* @__PURE__ */ __name((params) => [getStart(1, "quarter", params == null ? void 0 : params.timezone), getEnd(1, "quarter", params == null ? void 0 : params.timezone)], "nextQuarter"),
|
|
84
|
+
thisYear: /* @__PURE__ */ __name((params) => [getStart(0, "year", params == null ? void 0 : params.timezone), getEnd(0, "year", params == null ? void 0 : params.timezone)], "thisYear"),
|
|
85
|
+
lastYear: /* @__PURE__ */ __name((params) => [getStart(-1, "year", params == null ? void 0 : params.timezone), getEnd(-1, "year", params == null ? void 0 : params.timezone)], "lastYear"),
|
|
86
|
+
nextYear: /* @__PURE__ */ __name((params) => [getStart(1, "year", params == null ? void 0 : params.timezone), getEnd(1, "year", params == null ? void 0 : params.timezone)], "nextYear")
|
|
87
|
+
};
|
|
88
|
+
const getDayRangeByParams = /* @__PURE__ */ __name((params) => {
|
|
89
|
+
if (params.type === "past" || params.type === "next") {
|
|
90
|
+
return getOffsetRangeByParams(params);
|
|
91
|
+
}
|
|
92
|
+
const fn = strategies[params.type];
|
|
93
|
+
if (!fn) throw new Error(`Unsupported type: ${params.type}`);
|
|
94
|
+
const [start, end] = fn(params);
|
|
95
|
+
return [start.format("YYYY-MM-DD HH:mm:ss"), end.format("YYYY-MM-DD HH:mm:ss")];
|
|
96
|
+
}, "getDayRangeByParams");
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
getDayRangeByParams,
|
|
100
|
+
getOffsetRangeByParams
|
|
101
|
+
});
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -73,6 +73,7 @@ __reExport(src_exports, require("./i18n"), module.exports);
|
|
|
73
73
|
__reExport(src_exports, require("./wrap-middleware"), module.exports);
|
|
74
74
|
__reExport(src_exports, require("./object-to-cli-args"), module.exports);
|
|
75
75
|
__reExport(src_exports, require("./parsedValue"), module.exports);
|
|
76
|
+
__reExport(src_exports, require("./dateRangeUtils"), module.exports);
|
|
76
77
|
var import_json_schema = require("@formily/json-schema");
|
|
77
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
79
|
0 && (module.exports = {
|
|
@@ -107,5 +108,6 @@ var import_json_schema = require("@formily/json-schema");
|
|
|
107
108
|
...require("./i18n"),
|
|
108
109
|
...require("./wrap-middleware"),
|
|
109
110
|
...require("./object-to-cli-args"),
|
|
110
|
-
...require("./parsedValue")
|
|
111
|
+
...require("./parsedValue"),
|
|
112
|
+
...require("./dateRangeUtils")
|
|
111
113
|
});
|
package/lib/parse-date.js
CHANGED
|
@@ -33,14 +33,16 @@ __export(parse_date_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(parse_date_exports);
|
|
34
34
|
var import_date = require("./date");
|
|
35
35
|
var import_dayjs = require("./dayjs");
|
|
36
|
+
var import_dateRangeUtils = require("./dateRangeUtils");
|
|
36
37
|
function parseUTC(value) {
|
|
38
|
+
var _a;
|
|
37
39
|
if (value instanceof Date || import_dayjs.dayjs.isDayjs(value)) {
|
|
38
40
|
return {
|
|
39
41
|
unit: "utc",
|
|
40
42
|
start: value.toISOString()
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
|
-
if (value.endsWith("Z")) {
|
|
45
|
+
if ((_a = value == null ? void 0 : value.endsWith) == null ? void 0 : _a.call(value, "Z")) {
|
|
44
46
|
return {
|
|
45
47
|
unit: "utc",
|
|
46
48
|
start: value
|
|
@@ -186,6 +188,9 @@ function parseDate(value, options = {}) {
|
|
|
186
188
|
if (!value) {
|
|
187
189
|
return;
|
|
188
190
|
}
|
|
191
|
+
if (value.type) {
|
|
192
|
+
value = (0, import_dateRangeUtils.getDayRangeByParams)({ ...value, ...options });
|
|
193
|
+
}
|
|
189
194
|
if (Array.isArray(value)) {
|
|
190
195
|
return parseDateBetween(value, options);
|
|
191
196
|
}
|
package/lib/parse-filter.js
CHANGED
|
@@ -53,6 +53,7 @@ var import_moment = __toESM(require("moment"));
|
|
|
53
53
|
var import_date = require("./date");
|
|
54
54
|
var import_dayjs = require("./dayjs");
|
|
55
55
|
var import_getValuesByPath = require("./getValuesByPath");
|
|
56
|
+
var import_dateRangeUtils = require("./dateRangeUtils");
|
|
56
57
|
const re = /^\s*\{\{([\s\S]*)\}\}\s*$/;
|
|
57
58
|
function isBuffer(obj) {
|
|
58
59
|
return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
@@ -131,6 +132,9 @@ const dateValueWrapper = /* @__PURE__ */ __name((value, timezone) => {
|
|
|
131
132
|
if (!value) {
|
|
132
133
|
return null;
|
|
133
134
|
}
|
|
135
|
+
if (value.type) {
|
|
136
|
+
value = (0, import_dateRangeUtils.getDayRangeByParams)({ ...value, timezone });
|
|
137
|
+
}
|
|
134
138
|
if (Array.isArray(value)) {
|
|
135
139
|
if (value.length === 2) {
|
|
136
140
|
value.push("[]", timezone);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/utils",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.15",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"multer": "^1.4.5-lts.2",
|
|
17
17
|
"object-path": "^0.11.8"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "abedb555b92d597b96d55663a9f8109e7ab85fa9"
|
|
20
20
|
}
|