@gez/date-time-kit 2.0.0-alpha.15 → 2.0.0-alpha.17
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/dist/components/quick-selector/index.d.ts +3 -2
- package/dist/components/quick-selector/index.mjs +32 -30
- package/dist/components/quick-selector/quick-key.d.ts +194 -0
- package/dist/components/quick-selector/quick-key.mjs +20 -0
- package/package.json +2 -2
- package/src/components/quick-selector/index.ts +32 -30
- package/src/components/quick-selector/quick-key.ts +22 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Weeks } from '../calendar';
|
|
2
2
|
import { type reExportPopoverAttrs } from '../popover/attr-sync-helper';
|
|
3
3
|
import { type BaseAttrs, type BaseEmits, type Emit2EventMap, UiBase } from '../web-component-base';
|
|
4
|
-
import { type DataLimit, type GenPeriodTimesOptions, type PeriodTimeInfo, type QuickGenPeriodTimesOptions, type QuickKey, genPeriodTimes, quickGenPeriodTime, quickGenPeriodTimeInfo, quickGenPeriodTimes } from './quick-key';
|
|
5
|
-
export { type QuickKey, type DataLimit, type GenPeriodTimesOptions, type QuickGenPeriodTimesOptions, type PeriodTimeInfo, type Weeks, genPeriodTimes, quickGenPeriodTime, quickGenPeriodTimes, quickGenPeriodTimeInfo };
|
|
4
|
+
import { type DataLimit, type GenPeriodTimesOptions, type PeriodTimeInfo, type QuickGenPeriodTimesOptions, type QuickKey, UTCInfo2LocaleInfo, genPeriodTimes, localeInfo2UTCInfo, quickGenPeriodTime, quickGenPeriodTimeInfo, quickGenPeriodTimes } from './quick-key';
|
|
5
|
+
export { type QuickKey, type DataLimit, type GenPeriodTimesOptions, type QuickGenPeriodTimesOptions, type PeriodTimeInfo, type Weeks, genPeriodTimes, quickGenPeriodTime, quickGenPeriodTimes, quickGenPeriodTimeInfo, localeInfo2UTCInfo, UTCInfo2LocaleInfo };
|
|
6
6
|
export type Attrs = BaseAttrs & reExportPopoverAttrs & {
|
|
7
7
|
/**
|
|
8
8
|
* Timezone in minutes. For example: UTC+05:45 => `-345`, UTC-01:00 => `60`.
|
|
@@ -80,6 +80,7 @@ export declare class Ele extends UiBase<Attrs, Emits> {
|
|
|
80
80
|
private _onTzTriggerClick;
|
|
81
81
|
private _onCustomTriggerClick;
|
|
82
82
|
private _onBackBtnClick;
|
|
83
|
+
private _dispatchTimeChangeEvent;
|
|
83
84
|
private _onRadioChange;
|
|
84
85
|
private _onDoneBtnClick;
|
|
85
86
|
readonly genPeriodTimes: (options: GenPeriodTimesOptions) => {
|
|
@@ -16,7 +16,9 @@ import {
|
|
|
16
16
|
import styleStr from "./index.css.mjs";
|
|
17
17
|
import html, { utcText } from "./index.html.mjs";
|
|
18
18
|
import {
|
|
19
|
+
UTCInfo2LocaleInfo,
|
|
19
20
|
genPeriodTimes,
|
|
21
|
+
localeInfo2UTCInfo,
|
|
20
22
|
quickGenPeriodTime,
|
|
21
23
|
quickGenPeriodTimeInfo,
|
|
22
24
|
quickGenPeriodTimes,
|
|
@@ -26,7 +28,9 @@ export {
|
|
|
26
28
|
genPeriodTimes,
|
|
27
29
|
quickGenPeriodTime,
|
|
28
30
|
quickGenPeriodTimes,
|
|
29
|
-
quickGenPeriodTimeInfo
|
|
31
|
+
quickGenPeriodTimeInfo,
|
|
32
|
+
localeInfo2UTCInfo,
|
|
33
|
+
UTCInfo2LocaleInfo
|
|
30
34
|
};
|
|
31
35
|
export class Ele extends UiBase {
|
|
32
36
|
constructor() {
|
|
@@ -81,6 +85,24 @@ export class Ele extends UiBase {
|
|
|
81
85
|
this._showMenu("custom");
|
|
82
86
|
});
|
|
83
87
|
__publicField(this, "_onBackBtnClick", () => this._showMenu("top"));
|
|
88
|
+
__publicField(this, "_dispatchTimeChangeEvent", debounce(() => {
|
|
89
|
+
const quickKey = this.quickKey;
|
|
90
|
+
if (quickKey !== "custom") {
|
|
91
|
+
const t = this.quickGenPeriodTimeInfo(quickKey);
|
|
92
|
+
this.dispatchEvent("time-changed", t, true);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.dispatchEvent(
|
|
96
|
+
"time-changed",
|
|
97
|
+
{
|
|
98
|
+
tzOffset: this.tzOffset,
|
|
99
|
+
start: this.startTime,
|
|
100
|
+
end: this.endTime,
|
|
101
|
+
type: "custom"
|
|
102
|
+
},
|
|
103
|
+
true
|
|
104
|
+
);
|
|
105
|
+
}));
|
|
84
106
|
__publicField(this, "_onRadioChange", (e) => {
|
|
85
107
|
if (!(e.target instanceof HTMLInputElement)) return;
|
|
86
108
|
if (e.target.type !== "radio") return;
|
|
@@ -88,43 +110,21 @@ export class Ele extends UiBase {
|
|
|
88
110
|
if (name === "radio") {
|
|
89
111
|
const v = value;
|
|
90
112
|
if (v === "custom") return;
|
|
91
|
-
|
|
92
|
-
this.dispatchEvent("time-changed", t, true);
|
|
113
|
+
this.quickKey = v;
|
|
93
114
|
} else if (name === "tz") {
|
|
94
115
|
this.tzOffset = +value;
|
|
95
|
-
const quickKey = this.quickKey;
|
|
96
|
-
if (quickKey === "custom") {
|
|
97
|
-
this.dispatchEvent(
|
|
98
|
-
"time-changed",
|
|
99
|
-
{
|
|
100
|
-
tzOffset: this.tzOffset,
|
|
101
|
-
start: this.startTime,
|
|
102
|
-
end: this.endTime,
|
|
103
|
-
type: "custom"
|
|
104
|
-
},
|
|
105
|
-
true
|
|
106
|
-
);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const t = this.quickGenPeriodTimeInfo(quickKey);
|
|
110
|
-
this.dispatchEvent("time-changed", t, true);
|
|
111
116
|
}
|
|
112
117
|
});
|
|
113
118
|
__publicField(this, "_onDoneBtnClick", (_e) => {
|
|
114
119
|
const selector = this._periodSelector;
|
|
115
120
|
selector.abortSelecting();
|
|
116
121
|
this._showMenu("top");
|
|
122
|
+
let { timeStart, timeEnd } = this._periodSelector;
|
|
123
|
+
if (timeStart > timeEnd) [timeStart, timeEnd] = [timeEnd, timeStart];
|
|
124
|
+
this.startTime = timeStart;
|
|
125
|
+
this.endTime = timeEnd;
|
|
117
126
|
this.quickKey = "custom";
|
|
118
|
-
this.
|
|
119
|
-
"time-changed",
|
|
120
|
-
{
|
|
121
|
-
tzOffset: this.tzOffset,
|
|
122
|
-
start: selector.timeStart,
|
|
123
|
-
end: selector.timeEnd,
|
|
124
|
-
type: "custom"
|
|
125
|
-
},
|
|
126
|
-
true
|
|
127
|
-
);
|
|
127
|
+
this._dispatchTimeChangeEvent();
|
|
128
128
|
});
|
|
129
129
|
__publicField(this, "genPeriodTimes", (options) => genPeriodTimes({ weekStartAt: this.weekStartAt, ...options }));
|
|
130
130
|
__publicField(this, "quickGenPeriodTimes", (periods) => quickGenPeriodTimes({ weekStartAt: this.weekStartAt, periods }));
|
|
@@ -195,7 +195,7 @@ export class Ele extends UiBase {
|
|
|
195
195
|
}
|
|
196
196
|
const v = new Date(val);
|
|
197
197
|
if (Number.isNaN(+v)) return;
|
|
198
|
-
this.setAttribute("time
|
|
198
|
+
this.setAttribute("end-time", +v + "");
|
|
199
199
|
}
|
|
200
200
|
get excludeField() {
|
|
201
201
|
const v = this._getAttr("exclude-field", "") || "";
|
|
@@ -296,9 +296,11 @@ export class Ele extends UiBase {
|
|
|
296
296
|
}
|
|
297
297
|
if (name === "tz-offset") {
|
|
298
298
|
this._renderTz();
|
|
299
|
+
this._dispatchTimeChangeEvent();
|
|
299
300
|
}
|
|
300
301
|
if (name === "quick-key") {
|
|
301
302
|
this._updateRadio();
|
|
303
|
+
this._dispatchTimeChangeEvent();
|
|
302
304
|
}
|
|
303
305
|
if (name === "week-start-at") {
|
|
304
306
|
this._updatePeriodSelector();
|
|
@@ -46,3 +46,197 @@ export type PeriodTimeInfo<T extends QuickKey = QuickKey, RT = Date> = T extends
|
|
|
46
46
|
tzOffset: number;
|
|
47
47
|
};
|
|
48
48
|
export declare const quickGenPeriodTimeInfo: <T extends DataLimit = DataLimit>(type: T, options?: QuickGenPeriodTimesOptions, tzOffset?: number) => PeriodTimeInfo<T>;
|
|
49
|
+
export declare const localeInfo2UTCInfo: (info: PeriodTimeInfo) => {
|
|
50
|
+
type: "all";
|
|
51
|
+
/** Locale time */
|
|
52
|
+
start?: null;
|
|
53
|
+
/** Locale time */
|
|
54
|
+
end?: null;
|
|
55
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
56
|
+
tzOffset: number;
|
|
57
|
+
} | {
|
|
58
|
+
type: "today";
|
|
59
|
+
/** Locale time */
|
|
60
|
+
start: Date;
|
|
61
|
+
/** Locale time */
|
|
62
|
+
end: Date;
|
|
63
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
64
|
+
tzOffset: number;
|
|
65
|
+
} | {
|
|
66
|
+
type: "yesterday";
|
|
67
|
+
/** Locale time */
|
|
68
|
+
start: Date;
|
|
69
|
+
/** Locale time */
|
|
70
|
+
end: Date;
|
|
71
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
72
|
+
tzOffset: number;
|
|
73
|
+
} | {
|
|
74
|
+
type: "week";
|
|
75
|
+
/** Locale time */
|
|
76
|
+
start: Date;
|
|
77
|
+
/** Locale time */
|
|
78
|
+
end: Date;
|
|
79
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
80
|
+
tzOffset: number;
|
|
81
|
+
} | {
|
|
82
|
+
type: "lastWeek";
|
|
83
|
+
/** Locale time */
|
|
84
|
+
start: Date;
|
|
85
|
+
/** Locale time */
|
|
86
|
+
end: Date;
|
|
87
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
88
|
+
tzOffset: number;
|
|
89
|
+
} | {
|
|
90
|
+
type: "last7Days";
|
|
91
|
+
/** Locale time */
|
|
92
|
+
start: Date;
|
|
93
|
+
/** Locale time */
|
|
94
|
+
end: Date;
|
|
95
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
96
|
+
tzOffset: number;
|
|
97
|
+
} | {
|
|
98
|
+
type: "month";
|
|
99
|
+
/** Locale time */
|
|
100
|
+
start: Date;
|
|
101
|
+
/** Locale time */
|
|
102
|
+
end: Date;
|
|
103
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
104
|
+
tzOffset: number;
|
|
105
|
+
} | {
|
|
106
|
+
type: "last30Days";
|
|
107
|
+
/** Locale time */
|
|
108
|
+
start: Date;
|
|
109
|
+
/** Locale time */
|
|
110
|
+
end: Date;
|
|
111
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
112
|
+
tzOffset: number;
|
|
113
|
+
} | {
|
|
114
|
+
type: "last180Days";
|
|
115
|
+
/** Locale time */
|
|
116
|
+
start: Date;
|
|
117
|
+
/** Locale time */
|
|
118
|
+
end: Date;
|
|
119
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
120
|
+
tzOffset: number;
|
|
121
|
+
} | {
|
|
122
|
+
type: "last6Month";
|
|
123
|
+
/** Locale time */
|
|
124
|
+
start: Date;
|
|
125
|
+
/** Locale time */
|
|
126
|
+
end: Date;
|
|
127
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
128
|
+
tzOffset: number;
|
|
129
|
+
} | {
|
|
130
|
+
type: "year";
|
|
131
|
+
/** Locale time */
|
|
132
|
+
start: Date;
|
|
133
|
+
/** Locale time */
|
|
134
|
+
end: Date;
|
|
135
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
136
|
+
tzOffset: number;
|
|
137
|
+
} | {
|
|
138
|
+
type: "custom";
|
|
139
|
+
/** Locale time */
|
|
140
|
+
start: Date;
|
|
141
|
+
/** Locale time */
|
|
142
|
+
end: Date;
|
|
143
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
144
|
+
tzOffset: number;
|
|
145
|
+
};
|
|
146
|
+
export declare const UTCInfo2LocaleInfo: (info: PeriodTimeInfo) => {
|
|
147
|
+
type: "all";
|
|
148
|
+
/** Locale time */
|
|
149
|
+
start?: null;
|
|
150
|
+
/** Locale time */
|
|
151
|
+
end?: null;
|
|
152
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
153
|
+
tzOffset: number;
|
|
154
|
+
} | {
|
|
155
|
+
type: "today";
|
|
156
|
+
/** Locale time */
|
|
157
|
+
start: Date;
|
|
158
|
+
/** Locale time */
|
|
159
|
+
end: Date;
|
|
160
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
161
|
+
tzOffset: number;
|
|
162
|
+
} | {
|
|
163
|
+
type: "yesterday";
|
|
164
|
+
/** Locale time */
|
|
165
|
+
start: Date;
|
|
166
|
+
/** Locale time */
|
|
167
|
+
end: Date;
|
|
168
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
169
|
+
tzOffset: number;
|
|
170
|
+
} | {
|
|
171
|
+
type: "week";
|
|
172
|
+
/** Locale time */
|
|
173
|
+
start: Date;
|
|
174
|
+
/** Locale time */
|
|
175
|
+
end: Date;
|
|
176
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
177
|
+
tzOffset: number;
|
|
178
|
+
} | {
|
|
179
|
+
type: "lastWeek";
|
|
180
|
+
/** Locale time */
|
|
181
|
+
start: Date;
|
|
182
|
+
/** Locale time */
|
|
183
|
+
end: Date;
|
|
184
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
185
|
+
tzOffset: number;
|
|
186
|
+
} | {
|
|
187
|
+
type: "last7Days";
|
|
188
|
+
/** Locale time */
|
|
189
|
+
start: Date;
|
|
190
|
+
/** Locale time */
|
|
191
|
+
end: Date;
|
|
192
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
193
|
+
tzOffset: number;
|
|
194
|
+
} | {
|
|
195
|
+
type: "month";
|
|
196
|
+
/** Locale time */
|
|
197
|
+
start: Date;
|
|
198
|
+
/** Locale time */
|
|
199
|
+
end: Date;
|
|
200
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
201
|
+
tzOffset: number;
|
|
202
|
+
} | {
|
|
203
|
+
type: "last30Days";
|
|
204
|
+
/** Locale time */
|
|
205
|
+
start: Date;
|
|
206
|
+
/** Locale time */
|
|
207
|
+
end: Date;
|
|
208
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
209
|
+
tzOffset: number;
|
|
210
|
+
} | {
|
|
211
|
+
type: "last180Days";
|
|
212
|
+
/** Locale time */
|
|
213
|
+
start: Date;
|
|
214
|
+
/** Locale time */
|
|
215
|
+
end: Date;
|
|
216
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
217
|
+
tzOffset: number;
|
|
218
|
+
} | {
|
|
219
|
+
type: "last6Month";
|
|
220
|
+
/** Locale time */
|
|
221
|
+
start: Date;
|
|
222
|
+
/** Locale time */
|
|
223
|
+
end: Date;
|
|
224
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
225
|
+
tzOffset: number;
|
|
226
|
+
} | {
|
|
227
|
+
type: "year";
|
|
228
|
+
/** Locale time */
|
|
229
|
+
start: Date;
|
|
230
|
+
/** Locale time */
|
|
231
|
+
end: Date;
|
|
232
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
233
|
+
tzOffset: number;
|
|
234
|
+
} | {
|
|
235
|
+
type: "custom";
|
|
236
|
+
/** Locale time */
|
|
237
|
+
start: Date;
|
|
238
|
+
/** Locale time */
|
|
239
|
+
end: Date;
|
|
240
|
+
/** Timezone offset in minutes. e.g. UTC+05:45 => `-345`, UTC-01:00 => `60` */
|
|
241
|
+
tzOffset: number;
|
|
242
|
+
};
|
|
@@ -104,3 +104,23 @@ export const quickGenPeriodTimeInfo = (type, options = {}, tzOffset = getCurrent
|
|
|
104
104
|
const t = quickGenPeriodTime(type, options);
|
|
105
105
|
return !t ? { type, tzOffset } : { type, ...t, tzOffset };
|
|
106
106
|
};
|
|
107
|
+
export const localeInfo2UTCInfo = (info) => {
|
|
108
|
+
info = { ...info };
|
|
109
|
+
if (info.type === "all") return info;
|
|
110
|
+
const { tzOffset, start, end } = info;
|
|
111
|
+
info.start = new Date(
|
|
112
|
+
+start - (getCurrentTzOffset() - tzOffset) * 60 * 1e3
|
|
113
|
+
);
|
|
114
|
+
info.end = new Date(+end - (getCurrentTzOffset() - tzOffset) * 60 * 1e3);
|
|
115
|
+
return info;
|
|
116
|
+
};
|
|
117
|
+
export const UTCInfo2LocaleInfo = (info) => {
|
|
118
|
+
info = { ...info };
|
|
119
|
+
if (info.type === "all") return info;
|
|
120
|
+
const { tzOffset, start, end } = info;
|
|
121
|
+
info.start = new Date(
|
|
122
|
+
+start + (getCurrentTzOffset() - tzOffset) * 60 * 1e3
|
|
123
|
+
);
|
|
124
|
+
info.end = new Date(+end + (getCurrentTzOffset() - tzOffset) * 60 * 1e3);
|
|
125
|
+
return info;
|
|
126
|
+
};
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"unbuild": "3.6.0",
|
|
21
21
|
"vitest": "3.2.4"
|
|
22
22
|
},
|
|
23
|
-
"version": "2.0.0-alpha.
|
|
23
|
+
"version": "2.0.0-alpha.17",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"private": false,
|
|
26
26
|
"exports": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"template",
|
|
40
40
|
"public"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "ec728ac1725741632fa71cc8c05a2427d117c522"
|
|
43
43
|
}
|
|
@@ -23,7 +23,9 @@ import {
|
|
|
23
23
|
type PeriodTimeInfo,
|
|
24
24
|
type QuickGenPeriodTimesOptions,
|
|
25
25
|
type QuickKey,
|
|
26
|
+
UTCInfo2LocaleInfo,
|
|
26
27
|
genPeriodTimes,
|
|
28
|
+
localeInfo2UTCInfo,
|
|
27
29
|
quickGenPeriodTime,
|
|
28
30
|
quickGenPeriodTimeInfo,
|
|
29
31
|
quickGenPeriodTimes,
|
|
@@ -40,7 +42,9 @@ export {
|
|
|
40
42
|
genPeriodTimes,
|
|
41
43
|
quickGenPeriodTime,
|
|
42
44
|
quickGenPeriodTimes,
|
|
43
|
-
quickGenPeriodTimeInfo
|
|
45
|
+
quickGenPeriodTimeInfo,
|
|
46
|
+
localeInfo2UTCInfo,
|
|
47
|
+
UTCInfo2LocaleInfo
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
export type Attrs = BaseAttrs &
|
|
@@ -154,7 +158,7 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
154
158
|
}
|
|
155
159
|
const v = new Date(val);
|
|
156
160
|
if (Number.isNaN(+v)) return;
|
|
157
|
-
this.setAttribute('time
|
|
161
|
+
this.setAttribute('end-time', +v + '');
|
|
158
162
|
}
|
|
159
163
|
public get excludeField() {
|
|
160
164
|
const v = this._getAttr('exclude-field', '') || '';
|
|
@@ -273,9 +277,11 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
273
277
|
}
|
|
274
278
|
if (name === 'tz-offset') {
|
|
275
279
|
this._renderTz();
|
|
280
|
+
this._dispatchTimeChangeEvent();
|
|
276
281
|
}
|
|
277
282
|
if (name === 'quick-key') {
|
|
278
283
|
this._updateRadio();
|
|
284
|
+
this._dispatchTimeChangeEvent();
|
|
279
285
|
}
|
|
280
286
|
if (name === 'week-start-at') {
|
|
281
287
|
this._updatePeriodSelector();
|
|
@@ -352,6 +358,24 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
352
358
|
};
|
|
353
359
|
private _onBackBtnClick = () => this._showMenu('top');
|
|
354
360
|
|
|
361
|
+
private _dispatchTimeChangeEvent = debounce(() => {
|
|
362
|
+
const quickKey = this.quickKey;
|
|
363
|
+
if (quickKey !== 'custom') {
|
|
364
|
+
const t = this.quickGenPeriodTimeInfo(quickKey);
|
|
365
|
+
this.dispatchEvent('time-changed', t, true);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
this.dispatchEvent(
|
|
369
|
+
'time-changed',
|
|
370
|
+
{
|
|
371
|
+
tzOffset: this.tzOffset,
|
|
372
|
+
start: this.startTime as Date,
|
|
373
|
+
end: this.endTime as Date,
|
|
374
|
+
type: 'custom'
|
|
375
|
+
},
|
|
376
|
+
true
|
|
377
|
+
);
|
|
378
|
+
});
|
|
355
379
|
private _onRadioChange = (e: Event) => {
|
|
356
380
|
if (!(e.target instanceof HTMLInputElement)) return;
|
|
357
381
|
if (e.target.type !== 'radio') return;
|
|
@@ -359,43 +383,21 @@ export class Ele extends UiBase<Attrs, Emits> {
|
|
|
359
383
|
if (name === 'radio') {
|
|
360
384
|
const v = value as QuickKey;
|
|
361
385
|
if (v === 'custom') return;
|
|
362
|
-
|
|
363
|
-
this.dispatchEvent('time-changed', t, true);
|
|
386
|
+
this.quickKey = v;
|
|
364
387
|
} else if (name === 'tz') {
|
|
365
388
|
this.tzOffset = +value;
|
|
366
|
-
const quickKey = this.quickKey;
|
|
367
|
-
if (quickKey === 'custom') {
|
|
368
|
-
this.dispatchEvent(
|
|
369
|
-
'time-changed',
|
|
370
|
-
{
|
|
371
|
-
tzOffset: this.tzOffset,
|
|
372
|
-
start: this.startTime as Date,
|
|
373
|
-
end: this.endTime as Date,
|
|
374
|
-
type: 'custom'
|
|
375
|
-
},
|
|
376
|
-
true
|
|
377
|
-
);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
const t = this.quickGenPeriodTimeInfo(quickKey);
|
|
381
|
-
this.dispatchEvent('time-changed', t, true);
|
|
382
389
|
}
|
|
383
390
|
};
|
|
384
391
|
private _onDoneBtnClick = (_e: Event) => {
|
|
385
392
|
const selector = this._periodSelector;
|
|
386
393
|
selector.abortSelecting();
|
|
387
394
|
this._showMenu('top');
|
|
395
|
+
let { timeStart, timeEnd } = this._periodSelector;
|
|
396
|
+
if (timeStart > timeEnd) [timeStart, timeEnd] = [timeEnd, timeStart];
|
|
397
|
+
this.startTime = timeStart;
|
|
398
|
+
this.endTime = timeEnd;
|
|
388
399
|
this.quickKey = 'custom';
|
|
389
|
-
this.
|
|
390
|
-
'time-changed',
|
|
391
|
-
{
|
|
392
|
-
tzOffset: this.tzOffset,
|
|
393
|
-
start: selector.timeStart as Date,
|
|
394
|
-
end: selector.timeEnd as Date,
|
|
395
|
-
type: 'custom'
|
|
396
|
-
},
|
|
397
|
-
true
|
|
398
|
-
);
|
|
400
|
+
this._dispatchTimeChangeEvent();
|
|
399
401
|
};
|
|
400
402
|
|
|
401
403
|
public readonly genPeriodTimes = (options: GenPeriodTimesOptions) =>
|
|
@@ -181,3 +181,25 @@ export const quickGenPeriodTimeInfo = <T extends DataLimit = DataLimit>(
|
|
|
181
181
|
!t ? { type, tzOffset } : { type, ...t, tzOffset }
|
|
182
182
|
) as PeriodTimeInfo<T>;
|
|
183
183
|
};
|
|
184
|
+
|
|
185
|
+
export const localeInfo2UTCInfo = (info: PeriodTimeInfo) => {
|
|
186
|
+
info = { ...info };
|
|
187
|
+
if (info.type === 'all') return info;
|
|
188
|
+
const { tzOffset, start, end } = info;
|
|
189
|
+
info.start = new Date(
|
|
190
|
+
+start - (getCurrentTzOffset() - tzOffset) * 60 * 1000
|
|
191
|
+
);
|
|
192
|
+
info.end = new Date(+end - (getCurrentTzOffset() - tzOffset) * 60 * 1000);
|
|
193
|
+
return info;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const UTCInfo2LocaleInfo = (info: PeriodTimeInfo) => {
|
|
197
|
+
info = { ...info };
|
|
198
|
+
if (info.type === 'all') return info;
|
|
199
|
+
const { tzOffset, start, end } = info;
|
|
200
|
+
info.start = new Date(
|
|
201
|
+
+start + (getCurrentTzOffset() - tzOffset) * 60 * 1000
|
|
202
|
+
);
|
|
203
|
+
info.end = new Date(+end + (getCurrentTzOffset() - tzOffset) * 60 * 1000);
|
|
204
|
+
return info;
|
|
205
|
+
};
|