@douyinfe/semi-foundation 2.31.2 → 2.31.3-alpha.1

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.
@@ -0,0 +1,3 @@
1
+ export default function isValidTimeZone(timeZone?: string | number) {
2
+ return ['string', 'number'].includes(typeof timeZone) && timeZone !== '';
3
+ }
@@ -19,6 +19,7 @@ import type { ArrayElement, Motion } from '../utils/type';
19
19
  import type { Type, DateInputFoundationProps, InsetInputValue } from './inputFoundation';
20
20
  import type { MonthsGridFoundationProps } from './monthsGridFoundation';
21
21
  import type { WeekStartNumber } from './_utils/getMonthTable';
22
+ import isValidTimeZone from './_utils/isValidTimeZone';
22
23
 
23
24
  export type ValidateStatus = ArrayElement<typeof strings.STATUS>;
24
25
  export type InputSize = ArrayElement<typeof strings.SIZE_SET>;
@@ -238,13 +239,6 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
238
239
  this.initPanelOpenStatus(this.getProp('defaultOpen'));
239
240
  }
240
241
 
241
- isValidTimeZone(timeZone?: string | number) {
242
- const propTimeZone = this.getProp('timeZone');
243
- const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
244
-
245
- return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
246
- }
247
-
248
242
  initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & { prevTimeZone?: string | number }) {
249
243
  const _value = (Array.isArray(value) ? [...value] : (value || value === 0) && [value]) || [];
250
244
 
@@ -280,11 +274,10 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
280
274
  for (const v of value) {
281
275
  let parsedV = (v || v === 0) && this._parseValue(v);
282
276
  if (parsedV) {
283
- if (this.isValidTimeZone(prevTimeZone)) {
284
- parsedV = zonedTimeToUtc(parsedV, prevTimeZone as string);
277
+ if (isValidTimeZone(prevTimeZone)) {
278
+ parsedV = zonedTimeToUtc(parsedV, prevTimeZone);
285
279
  }
286
-
287
- result.push(this.isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone as string) : parsedV);
280
+ result.push(isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone) : parsedV);
288
281
  }
289
282
  }
290
283
  }
@@ -1098,9 +1091,9 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
1098
1091
  */
1099
1092
  disposeCallbackArgs(value: Date | Date[]) {
1100
1093
  let _value = Array.isArray(value) ? value : (value && [value]) || [];
1094
+ const timeZone = this.getProp('timeZone');
1101
1095
 
1102
- if (this.isValidTimeZone()) {
1103
- const timeZone = this.getProp('timeZone');
1096
+ if (isValidTimeZone(timeZone)) {
1104
1097
  _value = _value.map(date => zonedTimeToUtc(date, timeZone));
1105
1098
  }
1106
1099
  const type = this.getProp('type');
@@ -23,6 +23,7 @@ import isNullOrUndefined from '../utils/isNullOrUndefined';
23
23
  import { BaseValueType, DateInputFoundationProps, PresetPosition, ValueType } from './foundation';
24
24
  import { MonthDayInfo } from './monthFoundation';
25
25
  import { ArrayElement } from '../utils/type';
26
+ import isValidTimeZone from './_utils/isValidTimeZone';
26
27
 
27
28
  const dateDiffFns = {
28
29
  month: differenceInCalendarMonths,
@@ -448,13 +449,6 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
448
449
  return format(date, token, { locale: dateFnsLocale });
449
450
  }
450
451
 
451
- isValidTimeZone(timeZone?: string | number) {
452
- const propTimeZone = this.getProp('timeZone');
453
- const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
454
-
455
- return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
456
- }
457
-
458
452
  /**
459
453
  * 根据 type 处理 onChange 返回的参数
460
454
  *
@@ -484,9 +478,9 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
484
478
  */
485
479
  disposeCallbackArgs(value: Date | Date[]) {
486
480
  let _value = Array.isArray(value) ? value : (value && [value]) || [];
481
+ const timeZone = this.getProp('timeZone');
487
482
 
488
- if (this.isValidTimeZone()) {
489
- const timeZone = this.getProp('timeZone');
483
+ if (isValidTimeZone(timeZone)) {
490
484
  _value = _value.map(date => zonedTimeToUtc(date, timeZone));
491
485
  }
492
486
  const type = this.getProp('type');
@@ -0,0 +1 @@
1
+ export default function isValidTimeZone(timeZone?: string | number): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isValidTimeZone;
7
+
8
+ function isValidTimeZone(timeZone) {
9
+ return ['string', 'number'].includes(typeof timeZone) && timeZone !== '';
10
+ }
@@ -187,7 +187,6 @@ export interface DatePickerAdapter extends DefaultAdapter<DatePickerFoundationPr
187
187
  export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapter> {
188
188
  constructor(adapter: DatePickerAdapter);
189
189
  init(): void;
190
- isValidTimeZone(timeZone?: string | number): boolean;
191
190
  initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & {
192
191
  prevTimeZone?: string | number;
193
192
  }): void;
@@ -37,6 +37,8 @@ var _getInsetInputFormatToken = _interopRequireDefault(require("./_utils/getInse
37
37
 
38
38
  var _getInsetInputValueFromInsetInputStr = _interopRequireDefault(require("./_utils/getInsetInputValueFromInsetInputStr"));
39
39
 
40
+ var _isValidTimeZone = _interopRequireDefault(require("./_utils/isValidTimeZone"));
41
+
40
42
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
43
 
42
44
  /* eslint-disable no-nested-ternary */
@@ -105,14 +107,6 @@ class DatePickerFoundation extends _foundation.default {
105
107
  this.initPanelOpenStatus(this.getProp('defaultOpen'));
106
108
  }
107
109
 
108
- isValidTimeZone(timeZone) {
109
- const propTimeZone = this.getProp('timeZone');
110
-
111
- const _timeZone = (0, _isNullOrUndefined.default)(timeZone) ? propTimeZone : timeZone;
112
-
113
- return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
114
- }
115
-
116
110
  initFromProps(_ref) {
117
111
  let {
118
112
  value,
@@ -165,11 +159,11 @@ class DatePickerFoundation extends _foundation.default {
165
159
  let parsedV = (v || v === 0) && this._parseValue(v);
166
160
 
167
161
  if (parsedV) {
168
- if (this.isValidTimeZone(prevTimeZone)) {
162
+ if ((0, _isValidTimeZone.default)(prevTimeZone)) {
169
163
  parsedV = (0, _dateFnsExtra.zonedTimeToUtc)(parsedV, prevTimeZone);
170
164
  }
171
165
 
172
- result.push(this.isValidTimeZone(timeZone) ? (0, _dateFnsExtra.utcToZonedTime)(parsedV, timeZone) : parsedV);
166
+ result.push((0, _isValidTimeZone.default)(timeZone) ? (0, _dateFnsExtra.utcToZonedTime)(parsedV, timeZone) : parsedV);
173
167
  }
174
168
  }
175
169
  }
@@ -1155,8 +1149,9 @@ class DatePickerFoundation extends _foundation.default {
1155
1149
  disposeCallbackArgs(value) {
1156
1150
  let _value = Array.isArray(value) ? value : value && [value] || [];
1157
1151
 
1158
- if (this.isValidTimeZone()) {
1159
- const timeZone = this.getProp('timeZone');
1152
+ const timeZone = this.getProp('timeZone');
1153
+
1154
+ if ((0, _isValidTimeZone.default)(timeZone)) {
1160
1155
  _value = _value.map(date => (0, _dateFnsExtra.zonedTimeToUtc)(date, timeZone));
1161
1156
  }
1162
1157
 
@@ -158,7 +158,6 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
158
158
  * @returns
159
159
  */
160
160
  localeFormat(date: Date, token: string): string;
161
- isValidTimeZone(timeZone?: string | number): boolean;
162
161
  /**
163
162
  * 根据 type 处理 onChange 返回的参数
164
163
  *
@@ -27,7 +27,7 @@ var _dateFnsExtra = require("../utils/date-fns-extra");
27
27
 
28
28
  var _getDefaultFormatToken = require("./_utils/getDefaultFormatToken");
29
29
 
30
- var _isNullOrUndefined = _interopRequireDefault(require("../utils/isNullOrUndefined"));
30
+ var _isValidTimeZone = _interopRequireDefault(require("./_utils/isValidTimeZone"));
31
31
 
32
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
33
 
@@ -438,14 +438,6 @@ class MonthsGridFoundation extends _foundation.default {
438
438
  locale: dateFnsLocale
439
439
  });
440
440
  }
441
-
442
- isValidTimeZone(timeZone) {
443
- const propTimeZone = this.getProp('timeZone');
444
-
445
- const _timeZone = (0, _isNullOrUndefined.default)(timeZone) ? propTimeZone : timeZone;
446
-
447
- return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
448
- }
449
441
  /**
450
442
  * 根据 type 处理 onChange 返回的参数
451
443
  *
@@ -478,8 +470,9 @@ class MonthsGridFoundation extends _foundation.default {
478
470
  disposeCallbackArgs(value) {
479
471
  let _value = Array.isArray(value) ? value : value && [value] || [];
480
472
 
481
- if (this.isValidTimeZone()) {
482
- const timeZone = this.getProp('timeZone');
473
+ const timeZone = this.getProp('timeZone');
474
+
475
+ if ((0, _isValidTimeZone.default)(timeZone)) {
483
476
  _value = _value.map(date => (0, _dateFnsExtra.zonedTimeToUtc)(date, timeZone));
484
477
  }
485
478
 
@@ -36,11 +36,8 @@ class SwitchFoundation extends _foundation.default {
36
36
 
37
37
  init() {
38
38
  const {
39
- defaultChecked,
40
- checked,
41
39
  disabled
42
40
  } = this.getProps();
43
- this.setChecked(defaultChecked || checked);
44
41
  this.setDisabled(disabled);
45
42
  }
46
43
 
@@ -18,30 +18,36 @@ export declare const toIANA: (tz: string | number) => any;
18
18
  * @returns {Date}
19
19
  */
20
20
  declare const parse: (date: string | number | Date, formatToken: string, options?: any) => Date;
21
+ declare const format: (date: number | Date, formatToken: string, options?: any) => string;
21
22
  /**
23
+ * Given a date and any time zone, returns a Date with the equivalent UTC time
22
24
  *
23
- * @param {string | number | Date} date
24
- * @param {string} formatToken
25
- * @param {object} [options]
26
- * @param {string} [options.timeZone]
27
- */
28
- declare const format: (date: string | number | Date, formatToken: string, options?: any) => string;
29
- /**
25
+ * @example
26
+ * ```javascript
27
+ * import { zonedTimeToUtc } from 'date-fns-tz'
28
+ * const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone
29
+ * const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
30
+ * const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
31
+ * ```
30
32
  *
31
- * @param {string | number | Date} date
32
- * @param {string} timeZone
33
- * @param {object} options
34
- * @returns {Date}
33
+ * @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
35
34
  */
36
- declare const utcToZonedTime: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
35
+ declare const utcToZonedTime: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
37
36
  /**
37
+ * Get a date/time representing local time in a given time zone from the UTC date
38
38
  *
39
- * @param {string | number | Date} date
40
- * @param {string} timeZone
41
- * @param {object} options
42
- * @returns {Date}
39
+ * @example
40
+ * ```
41
+ * import { utcToZonedTime } from 'date-fns-tz'
42
+ * const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
43
+ * const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
44
+ * renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
45
+ * renderTimeZoneSelect(timeZone) // America/New_York
46
+ * ```
47
+ *
48
+ * @see https://github.com/marnusw/date-fns-tz#utctozonedtime
43
49
  */
44
- declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
50
+ declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
45
51
  /**
46
52
  * return current system hour offset based on utc:
47
53
  *
@@ -75,14 +75,6 @@ const parse = (date, formatToken, options) => {
75
75
 
76
76
  return (0, _dateFnsTz.toDate)(date, options);
77
77
  };
78
- /**
79
- *
80
- * @param {string | number | Date} date
81
- * @param {string} formatToken
82
- * @param {object} [options]
83
- * @param {string} [options.timeZone]
84
- */
85
-
86
78
  /* istanbul ignore next */
87
79
 
88
80
 
@@ -100,11 +92,17 @@ const format = (date, formatToken, options) => {
100
92
  return (0, _dateFnsTz.format)(date, formatToken, options);
101
93
  };
102
94
  /**
95
+ * Given a date and any time zone, returns a Date with the equivalent UTC time
103
96
  *
104
- * @param {string | number | Date} date
105
- * @param {string} timeZone
106
- * @param {object} options
107
- * @returns {Date}
97
+ * @example
98
+ * ```javascript
99
+ * import { zonedTimeToUtc } from 'date-fns-tz'
100
+ * const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone
101
+ * const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
102
+ * const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
103
+ * ```
104
+ *
105
+ * @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
108
106
  */
109
107
 
110
108
 
@@ -112,11 +110,18 @@ exports.format = format;
112
110
 
113
111
  const utcToZonedTime = (date, timeZone, options) => (0, _dateFnsTz.utcToZonedTime)(date, toIANA(timeZone), options);
114
112
  /**
113
+ * Get a date/time representing local time in a given time zone from the UTC date
115
114
  *
116
- * @param {string | number | Date} date
117
- * @param {string} timeZone
118
- * @param {object} options
119
- * @returns {Date}
115
+ * @example
116
+ * ```
117
+ * import { utcToZonedTime } from 'date-fns-tz'
118
+ * const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
119
+ * const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
120
+ * renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
121
+ * renderTimeZoneSelect(timeZone) // America/New_York
122
+ * ```
123
+ *
124
+ * @see https://github.com/marnusw/date-fns-tz#utctozonedtime
120
125
  */
121
126
 
122
127
 
@@ -0,0 +1 @@
1
+ export default function isValidTimeZone(timeZone?: string | number): boolean;
@@ -0,0 +1,3 @@
1
+ export default function isValidTimeZone(timeZone) {
2
+ return ['string', 'number'].includes(typeof timeZone) && timeZone !== '';
3
+ }
@@ -187,7 +187,6 @@ export interface DatePickerAdapter extends DefaultAdapter<DatePickerFoundationPr
187
187
  export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapter> {
188
188
  constructor(adapter: DatePickerAdapter);
189
189
  init(): void;
190
- isValidTimeZone(timeZone?: string | number): boolean;
191
190
  initFromProps({ value, timeZone, prevTimeZone }: Pick<DatePickerFoundationProps, 'value' | 'timeZone'> & {
192
191
  prevTimeZone?: string | number;
193
192
  }): void;
@@ -18,6 +18,7 @@ import { strings } from './constants';
18
18
  import { strings as inputStrings } from '../input/constants';
19
19
  import getInsetInputFormatToken from './_utils/getInsetInputFormatToken';
20
20
  import getInsetInputValueFromInsetInputStr from './_utils/getInsetInputValueFromInsetInputStr';
21
+ import isValidTimeZone from './_utils/isValidTimeZone';
21
22
  /**
22
23
  * The datePicker foundation.js is responsible for maintaining the date value and the input box value, as well as the callback of both
23
24
  * task 1. Accept the selected date change, update the date value, and update the input box value according to the date = > Notify the change
@@ -81,14 +82,6 @@ export default class DatePickerFoundation extends BaseFoundation {
81
82
  this.initPanelOpenStatus(this.getProp('defaultOpen'));
82
83
  }
83
84
 
84
- isValidTimeZone(timeZone) {
85
- const propTimeZone = this.getProp('timeZone');
86
-
87
- const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
88
-
89
- return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
90
- }
91
-
92
85
  initFromProps(_ref) {
93
86
  let {
94
87
  value,
@@ -141,11 +134,11 @@ export default class DatePickerFoundation extends BaseFoundation {
141
134
  let parsedV = (v || v === 0) && this._parseValue(v);
142
135
 
143
136
  if (parsedV) {
144
- if (this.isValidTimeZone(prevTimeZone)) {
137
+ if (isValidTimeZone(prevTimeZone)) {
145
138
  parsedV = zonedTimeToUtc(parsedV, prevTimeZone);
146
139
  }
147
140
 
148
- result.push(this.isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone) : parsedV);
141
+ result.push(isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone) : parsedV);
149
142
  }
150
143
  }
151
144
  }
@@ -1134,8 +1127,9 @@ export default class DatePickerFoundation extends BaseFoundation {
1134
1127
  disposeCallbackArgs(value) {
1135
1128
  let _value = Array.isArray(value) ? value : value && [value] || [];
1136
1129
 
1137
- if (this.isValidTimeZone()) {
1138
- const timeZone = this.getProp('timeZone');
1130
+ const timeZone = this.getProp('timeZone');
1131
+
1132
+ if (isValidTimeZone(timeZone)) {
1139
1133
  _value = _value.map(date => zonedTimeToUtc(date, timeZone));
1140
1134
  }
1141
1135
 
@@ -158,7 +158,6 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
158
158
  * @returns
159
159
  */
160
160
  localeFormat(date: Date, token: string): string;
161
- isValidTimeZone(timeZone?: string | number): boolean;
162
161
  /**
163
162
  * 根据 type 处理 onChange 返回的参数
164
163
  *
@@ -11,7 +11,7 @@ import { formatFullDate } from './_utils/getMonthTable';
11
11
  import { compatibleParse } from './_utils/parser';
12
12
  import { zonedTimeToUtc } from '../utils/date-fns-extra';
13
13
  import { getDefaultFormatTokenByType } from './_utils/getDefaultFormatToken';
14
- import isNullOrUndefined from '../utils/isNullOrUndefined';
14
+ import isValidTimeZone from './_utils/isValidTimeZone';
15
15
  const dateDiffFns = {
16
16
  month: differenceInCalendarMonths,
17
17
  year: differenceInCalendarYears
@@ -417,14 +417,6 @@ export default class MonthsGridFoundation extends BaseFoundation {
417
417
  locale: dateFnsLocale
418
418
  });
419
419
  }
420
-
421
- isValidTimeZone(timeZone) {
422
- const propTimeZone = this.getProp('timeZone');
423
-
424
- const _timeZone = isNullOrUndefined(timeZone) ? propTimeZone : timeZone;
425
-
426
- return ['string', 'number'].includes(typeof _timeZone) && _timeZone !== '';
427
- }
428
420
  /**
429
421
  * 根据 type 处理 onChange 返回的参数
430
422
  *
@@ -457,8 +449,9 @@ export default class MonthsGridFoundation extends BaseFoundation {
457
449
  disposeCallbackArgs(value) {
458
450
  let _value = Array.isArray(value) ? value : value && [value] || [];
459
451
 
460
- if (this.isValidTimeZone()) {
461
- const timeZone = this.getProp('timeZone');
452
+ const timeZone = this.getProp('timeZone');
453
+
454
+ if (isValidTimeZone(timeZone)) {
462
455
  _value = _value.map(date => zonedTimeToUtc(date, timeZone));
463
456
  }
464
457
 
@@ -25,11 +25,8 @@ export default class SwitchFoundation extends BaseFoundation {
25
25
 
26
26
  init() {
27
27
  const {
28
- defaultChecked,
29
- checked,
30
28
  disabled
31
29
  } = this.getProps();
32
- this.setChecked(defaultChecked || checked);
33
30
  this.setDisabled(disabled);
34
31
  }
35
32
 
@@ -18,30 +18,36 @@ export declare const toIANA: (tz: string | number) => any;
18
18
  * @returns {Date}
19
19
  */
20
20
  declare const parse: (date: string | number | Date, formatToken: string, options?: any) => Date;
21
+ declare const format: (date: number | Date, formatToken: string, options?: any) => string;
21
22
  /**
23
+ * Given a date and any time zone, returns a Date with the equivalent UTC time
22
24
  *
23
- * @param {string | number | Date} date
24
- * @param {string} formatToken
25
- * @param {object} [options]
26
- * @param {string} [options.timeZone]
27
- */
28
- declare const format: (date: string | number | Date, formatToken: string, options?: any) => string;
29
- /**
25
+ * @example
26
+ * ```javascript
27
+ * import { zonedTimeToUtc } from 'date-fns-tz'
28
+ * const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone
29
+ * const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
30
+ * const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
31
+ * ```
30
32
  *
31
- * @param {string | number | Date} date
32
- * @param {string} timeZone
33
- * @param {object} options
34
- * @returns {Date}
33
+ * @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
35
34
  */
36
- declare const utcToZonedTime: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
35
+ declare const utcToZonedTime: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
37
36
  /**
37
+ * Get a date/time representing local time in a given time zone from the UTC date
38
38
  *
39
- * @param {string | number | Date} date
40
- * @param {string} timeZone
41
- * @param {object} options
42
- * @returns {Date}
39
+ * @example
40
+ * ```
41
+ * import { utcToZonedTime } from 'date-fns-tz'
42
+ * const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
43
+ * const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
44
+ * renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
45
+ * renderTimeZoneSelect(timeZone) // America/New_York
46
+ * ```
47
+ *
48
+ * @see https://github.com/marnusw/date-fns-tz#utctozonedtime
43
49
  */
44
- declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => Date;
50
+ declare const zonedTimeToUtc: (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => Date;
45
51
  /**
46
52
  * return current system hour offset based on utc:
47
53
  *
@@ -62,14 +62,6 @@ const parse = (date, formatToken, options) => {
62
62
 
63
63
  return toDate(date, options);
64
64
  };
65
- /**
66
- *
67
- * @param {string | number | Date} date
68
- * @param {string} formatToken
69
- * @param {object} [options]
70
- * @param {string} [options.timeZone]
71
- */
72
-
73
65
  /* istanbul ignore next */
74
66
 
75
67
 
@@ -85,21 +77,34 @@ const format = (date, formatToken, options) => {
85
77
  return dateFnsFormat(date, formatToken, options);
86
78
  };
87
79
  /**
80
+ * Given a date and any time zone, returns a Date with the equivalent UTC time
88
81
  *
89
- * @param {string | number | Date} date
90
- * @param {string} timeZone
91
- * @param {object} options
92
- * @returns {Date}
82
+ * @example
83
+ * ```javascript
84
+ * import { zonedTimeToUtc } from 'date-fns-tz'
85
+ * const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone
86
+ * const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
87
+ * const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
88
+ * ```
89
+ *
90
+ * @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
93
91
  */
94
92
 
95
93
 
96
94
  const utcToZonedTime = (date, timeZone, options) => dateFnsUtcToZonedTime(date, toIANA(timeZone), options);
97
95
  /**
96
+ * Get a date/time representing local time in a given time zone from the UTC date
98
97
  *
99
- * @param {string | number | Date} date
100
- * @param {string} timeZone
101
- * @param {object} options
102
- * @returns {Date}
98
+ * @example
99
+ * ```
100
+ * import { utcToZonedTime } from 'date-fns-tz'
101
+ * const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
102
+ * const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
103
+ * renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
104
+ * renderTimeZoneSelect(timeZone) // America/New_York
105
+ * ```
106
+ *
107
+ * @see https://github.com/marnusw/date-fns-tz#utctozonedtime
103
108
  */
104
109
 
105
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.31.2",
3
+ "version": "2.31.3-alpha.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
@@ -10,8 +10,8 @@
10
10
  "@douyinfe/semi-animation": "2.12.0",
11
11
  "async-validator": "^3.5.0",
12
12
  "classnames": "^2.2.6",
13
- "date-fns": "^2.9.0",
14
- "date-fns-tz": "^1.0.10",
13
+ "date-fns": "^2.29.3",
14
+ "date-fns-tz": "^1.3.8",
15
15
  "lodash": "^4.17.21",
16
16
  "memoize-one": "^5.2.1",
17
17
  "scroll-into-view-if-needed": "^2.2.24"
@@ -23,7 +23,7 @@
23
23
  "*.scss",
24
24
  "*.css"
25
25
  ],
26
- "gitHead": "43a8fa54b5c662bad2fbb53603846b5c33f5d8da",
26
+ "gitHead": "245df62669b489032329e4da301a5fdcabe11ecd",
27
27
  "devDependencies": {
28
28
  "@babel/plugin-transform-runtime": "^7.15.8",
29
29
  "@babel/preset-env": "^7.15.8",
@@ -15,8 +15,7 @@ export default class SwitchFoundation<P = Record<string, any>, S = Record<string
15
15
  }
16
16
 
17
17
  init(): void {
18
- const { defaultChecked, checked, disabled } = this.getProps();
19
- this.setChecked(defaultChecked || checked);
18
+ const { disabled } = this.getProps();
20
19
  this.setDisabled(disabled);
21
20
  }
22
21
 
@@ -45,7 +44,7 @@ export default class SwitchFoundation<P = Record<string, any>, S = Record<string
45
44
  if (target.matches(':focus-visible')) {
46
45
  this._adapter.setFocusVisible(true);
47
46
  }
48
- } catch (error){
47
+ } catch (error) {
49
48
  warning(true, 'Warning: [Semi Switch] The current browser does not support the focus-visible');
50
49
  }
51
50
  }
@@ -100,15 +100,8 @@ const parse = (date: string | number | Date, formatToken: string, options?: any)
100
100
  return toDate(date, options);
101
101
  };
102
102
 
103
- /**
104
- *
105
- * @param {string | number | Date} date
106
- * @param {string} formatToken
107
- * @param {object} [options]
108
- * @param {string} [options.timeZone]
109
- */
110
103
  /* istanbul ignore next */
111
- const format = (date: string | number | Date, formatToken: string, options?: any) => {
104
+ const format = (date: number | Date, formatToken: string, options?: any) => {
112
105
  if (options && options.timeZone != null && options.timeZone !== '') {
113
106
  const timeZone = toIANA(options.timeZone);
114
107
  options = { ...options, timeZone };
@@ -120,22 +113,35 @@ const format = (date: string | number | Date, formatToken: string, options?: any
120
113
  };
121
114
 
122
115
  /**
123
- *
124
- * @param {string | number | Date} date
125
- * @param {string} timeZone
126
- * @param {object} options
127
- * @returns {Date}
116
+ * Given a date and any time zone, returns a Date with the equivalent UTC time
117
+ *
118
+ * @example
119
+ * ```javascript
120
+ * import { zonedTimeToUtc } from 'date-fns-tz'
121
+ * const date = getDatePickerValue() // e.g. 2014-06-25 10:00:00 (picked in any time zone
122
+ * const timeZone = getTimeZoneValue() // e.g. America/Los_Angeles
123
+ * const utcDate = zonedTimeToUtc(date, timeZone) // In June 10am in Los Angeles is 5pm UTC
124
+ * ```
125
+ *
126
+ * @see https://github.com/marnusw/date-fns-tz#zonedtimetoutc
128
127
  */
129
- const utcToZonedTime = (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => dateFnsUtcToZonedTime(date, toIANA(timeZone), options);
128
+ const utcToZonedTime = (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => dateFnsUtcToZonedTime(date, toIANA(timeZone), options);
130
129
 
131
130
  /**
132
- *
133
- * @param {string | number | Date} date
134
- * @param {string} timeZone
135
- * @param {object} options
136
- * @returns {Date}
131
+ * Get a date/time representing local time in a given time zone from the UTC date
132
+ *
133
+ * @example
134
+ * ```
135
+ * import { utcToZonedTime } from 'date-fns-tz'
136
+ * const { isoDate, timeZone } = fetchInitialValues() // 2014-06-25T10:00:00.000Z, America/New_York
137
+ * const date = utcToZonedTime(isoDate, timeZone) // In June 10am UTC is 6am in New York (-04:00)
138
+ * renderDatePicker(date) // 2014-06-25 06:00:00 (in the system time zone)
139
+ * renderTimeZoneSelect(timeZone) // America/New_York
140
+ * ```
141
+ *
142
+ * @see https://github.com/marnusw/date-fns-tz#utctozonedtime
137
143
  */
138
- const zonedTimeToUtc = (date: string | number | Date, timeZone: string, options?: OptionsWithTZ) => dateFnsZonedTimeToUtc(date, toIANA(timeZone), options);
144
+ const zonedTimeToUtc = (date: string | number | Date, timeZone: string | number, options?: OptionsWithTZ) => dateFnsZonedTimeToUtc(date, toIANA(timeZone), options);
139
145
 
140
146
  /**
141
147
  * return current system hour offset based on utc: