@gez/date-time-kit 2.0.0-alpha.21 → 2.0.0-alpha.23

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.
@@ -25,7 +25,7 @@ export type Attrs = BaseAttrs & reExportPopoverAttrs & {
25
25
  'showing-time'?: string | number;
26
26
  /**
27
27
  * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
28
- * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。
28
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。忽略的时间单位将被重置为 0。
29
29
  */
30
30
  'min-granularity'?: Granularity;
31
31
  /**
@@ -48,7 +48,7 @@ export class Ele extends UiBase {
48
48
  }, 0));
49
49
  __publicField(this, "_onCalendarSelect", (e) => {
50
50
  e.stopPropagation();
51
- this.currentTime = +e.detail + this._timeSelector.millisecond;
51
+ this.currentTime = +e.detail + (this.minGranularity === "day" ? 0 : this._timeSelector.millisecond);
52
52
  });
53
53
  __publicField(this, "_onNavChange", (e) => {
54
54
  e.stopPropagation();
@@ -18,7 +18,7 @@ export interface Attrs extends BaseAttrs {
18
18
  'time-end': string | number;
19
19
  /**
20
20
  * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
21
- * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。
21
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。忽略的时间单位视情况重置为 0 或 23 或 59 或 999。
22
22
  */
23
23
  'min-granularity'?: Granularity;
24
24
  /**
@@ -68,6 +68,7 @@ export declare class Ele extends UiBase<Attrs, Emits> {
68
68
  private _updateNavCtrlBtn;
69
69
  private _render;
70
70
  private _updateDateEcho;
71
+ private _getTimeSelectorMs;
71
72
  private _updateDatePoint;
72
73
  private _onCalendarSelect;
73
74
  private _onCalendarItemHover;
@@ -91,9 +91,9 @@ export class Ele extends UiBase {
91
91
  const newDate = new Date(datePoint).setHours(0, 0, 0, 0);
92
92
  const oldDate = new Date(this._selectedDate).setHours(0, 0, 0, 0);
93
93
  const setStartDate = (date) => this.timeStart = new Date(
94
- date + this._startTimeSelector.millisecond
94
+ date + this._getTimeSelectorMs("start")
95
95
  );
96
- const setEndDate = (date) => this.timeEnd = new Date(date + this._endTimeSelector.millisecond);
96
+ const setEndDate = (date) => this.timeEnd = new Date(date + this._getTimeSelectorMs("end"));
97
97
  if (newDate === oldDate) {
98
98
  setStartDate(newDate);
99
99
  setEndDate(newDate);
@@ -109,7 +109,7 @@ export class Ele extends UiBase {
109
109
  e.stopPropagation();
110
110
  if (this._selectedDate === null) {
111
111
  const newTimePoint = new Date(
112
- +e.detail + this._startTimeSelector.millisecond
112
+ +e.detail + this._getTimeSelectorMs("start")
113
113
  );
114
114
  this._selectedDate = newTimePoint;
115
115
  this.timeStart = newTimePoint;
@@ -348,6 +348,10 @@ export class Ele extends UiBase {
348
348
  ".end-date-echo-wrapper"
349
349
  ).classList.toggle("active", !!this._selectedDate);
350
350
  }
351
+ _getTimeSelectorMs(type) {
352
+ const selector = type === "start" ? this._startTimeSelector : this._endTimeSelector;
353
+ return this.minGranularity === "day" ? type === "start" ? 0 : 86399999 : selector.millisecond;
354
+ }
351
355
  abortSelecting() {
352
356
  if (!this._selectedDate) return;
353
357
  this._selectedDate = null;
@@ -3,6 +3,8 @@ import { type reExportPopoverAttrs } from '../popover/attr-sync-helper';
3
3
  import { type BaseAttrs, type BaseEmits, type Emit2EventMap, UiBase } from '../web-component-base';
4
4
  import { type DataLimit, type GenPeriodTimesOptions, type PeriodTimeInfo, type QuickGenPeriodTimesOptions, type QuickKey, UTCInfo2LocaleInfo, genPeriodTimes, localeInfo2UTCInfo, quickGenPeriodTime, quickGenPeriodTimeInfo, quickGenPeriodTimes } from './quick-key';
5
5
  export { type QuickKey, type DataLimit, type GenPeriodTimesOptions, type QuickGenPeriodTimesOptions, type PeriodTimeInfo, type Weeks, genPeriodTimes, quickGenPeriodTime, quickGenPeriodTimes, quickGenPeriodTimeInfo, localeInfo2UTCInfo, UTCInfo2LocaleInfo };
6
+ export declare const granularityList: readonly ["day", "hour", "minute", "second", "millisecond"];
7
+ export type Granularity = (typeof granularityList)[number];
6
8
  export type Attrs = BaseAttrs & reExportPopoverAttrs & {
7
9
  /**
8
10
  * Timezone in minutes. For example: UTC+05:45 => `-345`, UTC-01:00 => `60`.
@@ -31,6 +33,11 @@ export type Attrs = BaseAttrs & reExportPopoverAttrs & {
31
33
  * End locale time of the quick selection. Only works in custom mode.
32
34
  */
33
35
  'end-time'?: string | number | '';
36
+ /**
37
+ * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
38
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。忽略的时间单位视情况重置为 0 或 23 或 59 或 999。
39
+ */
40
+ 'min-granularity'?: Granularity;
34
41
  /**
35
42
  * Exclude some quick selection options.
36
43
  *
@@ -62,6 +69,8 @@ export declare class Ele extends UiBase<Attrs, Emits> {
62
69
  set startTime(val: number | string | Date);
63
70
  get endTime(): number | string | Date;
64
71
  set endTime(val: number | string | Date);
72
+ get minGranularity(): NonNullable<Attrs["min-granularity"]>;
73
+ set minGranularity(val: NonNullable<Attrs['min-granularity']>);
65
74
  get excludeField(): (QuickKey | "timezone")[];
66
75
  set excludeField(v: (QuickKey | 'timezone')[]);
67
76
  protected _style: string;
@@ -3,6 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import { debounce, getCurrentTzOffset } from "../../utils.mjs";
5
5
  import { weekKey } from "../calendar/index.mjs";
6
+ import { granularityList as timeGranularityList } from "../hhmmss-ms-list-grp/selector.mjs";
6
7
  import { Ele as PopoverEle } from "../popover/index.mjs";
7
8
  import {
8
9
  clearupPopEleAttrSync2Parent,
@@ -32,6 +33,7 @@ export {
32
33
  localeInfo2UTCInfo,
33
34
  UTCInfo2LocaleInfo
34
35
  };
36
+ export const granularityList = ["day", ...timeGranularityList];
35
37
  export class Ele extends UiBase {
36
38
  constructor() {
37
39
  super();
@@ -54,6 +56,7 @@ export class Ele extends UiBase {
54
56
  ele.timeStart = defaultPeriod.start;
55
57
  ele.timeEnd = defaultPeriod.end;
56
58
  }
59
+ ele.minGranularity = this.minGranularity;
57
60
  ele.showCalendarDatePoint();
58
61
  }, 0));
59
62
  __publicField(this, "_renderTz", debounce(() => {
@@ -119,7 +122,7 @@ export class Ele extends UiBase {
119
122
  const selector = this._periodSelector;
120
123
  selector.abortSelecting();
121
124
  this._showMenu("top");
122
- let { timeStart, timeEnd } = this._periodSelector;
125
+ let { timeStart, timeEnd } = selector;
123
126
  if (timeStart > timeEnd) [timeStart, timeEnd] = [timeEnd, timeStart];
124
127
  this.startTime = timeStart;
125
128
  this.endTime = timeEnd;
@@ -144,6 +147,7 @@ export class Ele extends UiBase {
144
147
  "quick-key",
145
148
  "start-time",
146
149
  "end-time",
150
+ "min-granularity",
147
151
  "exclude-field",
148
152
  ...popoverAttrKeys
149
153
  ];
@@ -197,6 +201,13 @@ export class Ele extends UiBase {
197
201
  if (Number.isNaN(+v)) return;
198
202
  this.setAttribute("end-time", +v + "");
199
203
  }
204
+ get minGranularity() {
205
+ return this._getAttr("min-granularity", "millisecond");
206
+ }
207
+ set minGranularity(val) {
208
+ if (!granularityList.includes(val)) return;
209
+ this.setAttribute("min-granularity", val);
210
+ }
200
211
  get excludeField() {
201
212
  const v = this._getAttr("exclude-field", "") || "";
202
213
  if (v === "") return [];
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.21",
23
+ "version": "2.0.0-alpha.23",
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": "3e500ac773a8879132d6d1b7f57e142d7d71bf2a"
42
+ "gitHead": "7f3401c9f9d978163c296f4cb729bd72a30c1084"
43
43
  }
@@ -57,7 +57,7 @@ export type Attrs = BaseAttrs &
57
57
  'showing-time'?: string | number;
58
58
  /**
59
59
  * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
60
- * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。
60
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。忽略的时间单位将被重置为 0。
61
61
  */
62
62
  'min-granularity'?: Granularity;
63
63
  /**
@@ -273,7 +273,11 @@ export class Ele extends UiBase<Attrs, Emits> {
273
273
 
274
274
  private _onCalendarSelect = (e: CalendarBaseEvent['select-time']) => {
275
275
  e.stopPropagation();
276
- this.currentTime = +e.detail + this._timeSelector.millisecond;
276
+ this.currentTime =
277
+ +e.detail +
278
+ (this.minGranularity === 'day'
279
+ ? 0
280
+ : this._timeSelector.millisecond);
277
281
  };
278
282
  private _onNavChange = (e: YyyyMmNavEvent['change']) => {
279
283
  e.stopPropagation();
@@ -38,7 +38,7 @@ export interface Attrs extends BaseAttrs {
38
38
  'time-end': string | number;
39
39
  /**
40
40
  * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
41
- * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。
41
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。忽略的时间单位视情况重置为 0 或 23 或 59 或 999。
42
42
  */
43
43
  'min-granularity'?: Granularity;
44
44
  /**
@@ -355,16 +355,26 @@ export class Ele extends UiBase<Attrs, Emits> {
355
355
  )!.classList.toggle('active', !!this._selectedDate);
356
356
  }
357
357
 
358
+ private _getTimeSelectorMs(type: 'start' | 'end') {
359
+ const selector =
360
+ type === 'start' ? this._startTimeSelector : this._endTimeSelector;
361
+ return this.minGranularity === 'day'
362
+ ? type === 'start'
363
+ ? 0
364
+ : 86399999 // 23:59:59.999
365
+ : selector.millisecond;
366
+ }
367
+
358
368
  private _updateDatePoint = (datePoint: Date) => {
359
369
  if (!this._selectedDate) return;
360
370
  const newDate = new Date(datePoint).setHours(0, 0, 0, 0);
361
371
  const oldDate = new Date(this._selectedDate).setHours(0, 0, 0, 0);
362
372
  const setStartDate = (date: number) =>
363
373
  (this.timeStart = new Date(
364
- date + this._startTimeSelector.millisecond
374
+ date + this._getTimeSelectorMs('start')
365
375
  ));
366
376
  const setEndDate = (date: number) =>
367
- (this.timeEnd = new Date(date + this._endTimeSelector.millisecond));
377
+ (this.timeEnd = new Date(date + this._getTimeSelectorMs('end')));
368
378
  if (newDate === oldDate) {
369
379
  setStartDate(newDate);
370
380
  setEndDate(newDate);
@@ -380,7 +390,7 @@ export class Ele extends UiBase<Attrs, Emits> {
380
390
  e.stopPropagation();
381
391
  if (this._selectedDate === null) {
382
392
  const newTimePoint = new Date(
383
- +e.detail + this._startTimeSelector.millisecond
393
+ +e.detail + this._getTimeSelectorMs('start')
384
394
  );
385
395
  this._selectedDate = newTimePoint;
386
396
  this.timeStart = newTimePoint;
@@ -1,5 +1,6 @@
1
1
  import { debounce, getCurrentTzOffset } from '../../utils';
2
2
  import { type Weeks, weekKey } from '../calendar';
3
+ import { granularityList as timeGranularityList } from '../hhmmss-ms-list-grp/selector';
3
4
  import type { Ele as PeriodSelectorEle } from '../period-selector';
4
5
  import { Ele as PopoverEle, type EventMap as PopoverEvent } from '../popover';
5
6
  import {
@@ -47,6 +48,9 @@ export {
47
48
  UTCInfo2LocaleInfo
48
49
  };
49
50
 
51
+ export const granularityList = ['day', ...timeGranularityList] as const;
52
+ export type Granularity = (typeof granularityList)[number];
53
+
50
54
  export type Attrs = BaseAttrs &
51
55
  reExportPopoverAttrs & {
52
56
  /**
@@ -76,6 +80,11 @@ export type Attrs = BaseAttrs &
76
80
  * End locale time of the quick selection. Only works in custom mode.
77
81
  */
78
82
  'end-time'?: string | number | '';
83
+ /**
84
+ * 选择器的粒度,表示最小可选的时间单位。默认为 millisecond。
85
+ * 例如设置为 'minute',则表示只能选择到分钟,秒和毫秒将被忽略。忽略的时间单位视情况重置为 0 或 23 或 59 或 999。
86
+ */
87
+ 'min-granularity'?: Granularity;
79
88
  /**
80
89
  * Exclude some quick selection options.
81
90
  *
@@ -106,6 +115,7 @@ export class Ele extends UiBase<Attrs, Emits> {
106
115
  'quick-key',
107
116
  'start-time',
108
117
  'end-time',
118
+ 'min-granularity',
109
119
  'exclude-field',
110
120
  ...popoverAttrKeys
111
121
  ] satisfies (keyof Attrs)[];
@@ -160,6 +170,13 @@ export class Ele extends UiBase<Attrs, Emits> {
160
170
  if (Number.isNaN(+v)) return;
161
171
  this.setAttribute('end-time', +v + '');
162
172
  }
173
+ public get minGranularity() {
174
+ return this._getAttr('min-granularity', 'millisecond');
175
+ }
176
+ public set minGranularity(val: NonNullable<Attrs['min-granularity']>) {
177
+ if (!granularityList.includes(val)) return;
178
+ this.setAttribute('min-granularity', val);
179
+ }
163
180
  public get excludeField() {
164
181
  const v = this._getAttr('exclude-field', '') || '';
165
182
  if (v === '') return [];
@@ -311,6 +328,7 @@ export class Ele extends UiBase<Attrs, Emits> {
311
328
  ele.timeStart = defaultPeriod.start;
312
329
  ele.timeEnd = defaultPeriod.end;
313
330
  }
331
+ ele.minGranularity = this.minGranularity;
314
332
  ele.showCalendarDatePoint();
315
333
  }, 0);
316
334
 
@@ -392,7 +410,7 @@ export class Ele extends UiBase<Attrs, Emits> {
392
410
  const selector = this._periodSelector;
393
411
  selector.abortSelecting();
394
412
  this._showMenu('top');
395
- let { timeStart, timeEnd } = this._periodSelector;
413
+ let { timeStart, timeEnd } = selector;
396
414
  if (timeStart > timeEnd) [timeStart, timeEnd] = [timeEnd, timeStart];
397
415
  this.startTime = timeStart;
398
416
  this.endTime = timeEnd;