@nocobase/database 1.5.0-beta.6 → 1.5.0-beta.8
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.
|
@@ -8,6 +8,29 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { BaseInterface } from './base-interface';
|
|
10
10
|
export declare class DatetimeInterface extends BaseInterface {
|
|
11
|
+
protected parseDateString(value: string): {
|
|
12
|
+
year: string;
|
|
13
|
+
month: string;
|
|
14
|
+
day: string;
|
|
15
|
+
hour: string;
|
|
16
|
+
minute: string;
|
|
17
|
+
second: string;
|
|
18
|
+
} | {
|
|
19
|
+
year: string;
|
|
20
|
+
month: string;
|
|
21
|
+
day: string;
|
|
22
|
+
hour?: undefined;
|
|
23
|
+
minute?: undefined;
|
|
24
|
+
second?: undefined;
|
|
25
|
+
};
|
|
26
|
+
protected formatDateTimeToISO(dateInfo: {
|
|
27
|
+
year: string;
|
|
28
|
+
month: string;
|
|
29
|
+
day: string;
|
|
30
|
+
hour?: string;
|
|
31
|
+
minute?: string;
|
|
32
|
+
second?: string;
|
|
33
|
+
}): string;
|
|
11
34
|
toValue(value: any, ctx?: any): Promise<any>;
|
|
12
35
|
toString(value: any, ctx?: any): any;
|
|
13
36
|
}
|
|
@@ -62,15 +62,32 @@ function resolveTimeZoneFromCtx(ctx) {
|
|
|
62
62
|
}
|
|
63
63
|
__name(resolveTimeZoneFromCtx, "resolveTimeZoneFromCtx");
|
|
64
64
|
const _DatetimeInterface = class _DatetimeInterface extends import_base_interface.BaseInterface {
|
|
65
|
+
parseDateString(value) {
|
|
66
|
+
const dateOnlyMatch = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(value);
|
|
67
|
+
const dateTimeMatch = /^(\d{4})(\d{2})(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/.exec(value);
|
|
68
|
+
if (dateTimeMatch) {
|
|
69
|
+
const [_, year, month, day, hour, minute, second] = dateTimeMatch;
|
|
70
|
+
return { year, month, day, hour, minute, second };
|
|
71
|
+
}
|
|
72
|
+
if (dateOnlyMatch) {
|
|
73
|
+
const [_, year, month, day] = dateOnlyMatch;
|
|
74
|
+
return { year, month, day };
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
formatDateTimeToISO(dateInfo) {
|
|
79
|
+
const { year, month, day, hour = "00", minute = "00", second = "00" } = dateInfo;
|
|
80
|
+
const m = (0, import_dayjs.default)(`${year}-${month}-${day} ${hour}:${minute}:${second}.000`);
|
|
81
|
+
return m.toISOString();
|
|
82
|
+
}
|
|
65
83
|
async toValue(value, ctx = {}) {
|
|
66
84
|
if (!value) {
|
|
67
85
|
return null;
|
|
68
86
|
}
|
|
69
87
|
if (typeof value === "string") {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
return m.toISOString();
|
|
88
|
+
const dateInfo = this.parseDateString(value);
|
|
89
|
+
if (dateInfo) {
|
|
90
|
+
return this.formatDateTimeToISO(dateInfo);
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
if (import_dayjs.default.isDayjs(value)) {
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { DatetimeInterface } from './datetime-interface';
|
|
2
2
|
export declare class DatetimeNoTzInterface extends DatetimeInterface {
|
|
3
|
+
protected formatDateTimeToString(dateInfo: {
|
|
4
|
+
year: string;
|
|
5
|
+
month: string;
|
|
6
|
+
day: string;
|
|
7
|
+
hour?: string;
|
|
8
|
+
minute?: string;
|
|
9
|
+
second?: string;
|
|
10
|
+
}): string;
|
|
3
11
|
toValue(value: any, ctx?: any): Promise<any>;
|
|
4
12
|
toString(value: any, ctx?: any): any;
|
|
5
13
|
}
|
|
@@ -55,14 +55,21 @@ function isNumeric(str) {
|
|
|
55
55
|
}
|
|
56
56
|
__name(isNumeric, "isNumeric");
|
|
57
57
|
const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datetime_interface.DatetimeInterface {
|
|
58
|
+
formatDateTimeToString(dateInfo) {
|
|
59
|
+
const { year, month, day, hour, minute, second } = dateInfo;
|
|
60
|
+
if (hour !== void 0 && minute !== void 0 && second !== void 0) {
|
|
61
|
+
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
62
|
+
}
|
|
63
|
+
return `${year}-${month}-${day}`;
|
|
64
|
+
}
|
|
58
65
|
async toValue(value, ctx = {}) {
|
|
59
66
|
if (!value) {
|
|
60
67
|
return null;
|
|
61
68
|
}
|
|
62
69
|
if (typeof value === "string") {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
70
|
+
const dateInfo = this.parseDateString(value);
|
|
71
|
+
if (dateInfo) {
|
|
72
|
+
return this.formatDateTimeToString(dateInfo);
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
if (import_dayjs.default.isDayjs(value)) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "1.5.0-beta.
|
|
10
|
-
"@nocobase/utils": "1.5.0-beta.
|
|
9
|
+
"@nocobase/logger": "1.5.0-beta.8",
|
|
10
|
+
"@nocobase/utils": "1.5.0-beta.8",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "eb7db7301ac5eed305e73540884611832bc761f6"
|
|
42
42
|
}
|