@superdispatch/dates 0.45.0 → 0.46.0

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.
@@ -6,8 +6,8 @@ import { ColorVariant } from '@superdispatch/ui';
6
6
  import { DayPickerProps } from 'react-day-picker';
7
7
  import { DateTime, ToRelativeOptions, ToRelativeUnit } from 'luxon';
8
8
 
9
- declare function setDefaultTimeZone(offset: number | 'local'): string;
10
- declare function useDefaultTimeZone(offset: number | 'local'): string;
9
+ declare function setDefaultTimeZone(offset: number | 'system'): string;
10
+ declare function useDefaultTimeZone(offset: number | 'system'): string;
11
11
  declare type DateFormat = 'DateISO' | 'DateTimeISO' | 'JodaISO';
12
12
  interface DateConfig {
13
13
  readonly format: DateFormat;
@@ -156,88 +156,6 @@ interface DateRangeFieldProps extends Pick<BaseTextFieldProps, 'disabled' | 'err
156
156
  }
157
157
  declare const DateRangeField: ForwardRefExoticComponent<DateRangeFieldProps & RefAttributes<HTMLDivElement>>;
158
158
 
159
- /** @deprecated */
160
- declare type DateUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
161
- /** @deprecated */
162
- declare type DateDurationUnit = DateUnit | 'quarter' | 'week';
163
- /** @deprecated */
164
- declare type DateObject = Record<DateUnit, number>;
165
- /** @deprecated */
166
- declare type NullableDate = null | undefined | Date;
167
- /** @deprecated */
168
- declare type DateLike = number | Date;
169
- /** @deprecated */
170
- declare type NullableDateLike = null | undefined | DateLike;
171
- /** @deprecated */
172
- declare type DateRange = [Date?, Date?];
173
- /** @deprecated */
174
- declare type DateRangeLike = [DateLike?, DateLike?];
175
- /** @deprecated */
176
- declare type NullableDateRange = null | undefined | [NullableDate?, NullableDate?];
177
- /** @deprecated */
178
- declare type NullableDateRangeLike = null | undefined | [NullableDateLike?, NullableDateLike?];
179
- /** @deprecated */
180
- declare function isDate(value: unknown): value is Date;
181
- /** @deprecated */
182
- declare function isDateLike(value: unknown): value is DateLike;
183
- /** @deprecated */
184
- declare function isValidDate(value: unknown): value is Date;
185
- /** @deprecated */
186
- declare function isDateRange(range: unknown): range is DateRange;
187
- /** @deprecated */
188
- declare function isDateRangeLike(range: unknown): range is DateRangeLike;
189
- /** @deprecated */
190
- declare function isValidDateRange(range: unknown): range is DateRange;
191
- /** @deprecated */
192
- declare function toDate(value: NullableDateLike): Date;
193
- /** @deprecated */
194
- declare function toDateRange(range: NullableDateRangeLike): DateRange;
195
- /** @deprecated */
196
- declare type DateFormatVariant = 'date' | 'shortDate' | 'time' | 'dateTime';
197
- /** @deprecated */
198
- declare type DateFormatOptions = Omit<Intl.DateTimeFormatOptions, 'timeZone' | 'timeZoneName'>;
199
- /** @deprecated */
200
- declare type RelativeTimeFormatStyle = 'narrow' | 'short' | 'long';
201
- /** @deprecated */
202
- interface RelativeTimeFormatOptions {
203
- style?: RelativeTimeFormatStyle;
204
- compare?: DateLike;
205
- }
206
- /** @deprecated */
207
- declare class DateUtils {
208
- /** @deprecated */
209
- toObject(value: DateLike): DateObject;
210
- /** @deprecated */
211
- fromObject({ year, month, day, hour, minute, second, millisecond, }: Partial<DateObject>): Date;
212
- /** @deprecated */
213
- update(value: DateLike, values: Partial<DateObject>): Date;
214
- /** @deprecated */
215
- mergeDateAndTime(date: DateLike, time: DateLike): Date;
216
- /** @deprecated */
217
- startOf(value: DateLike, unit: DateDurationUnit): Date;
218
- /** @deprecated */
219
- endOf(value: DateLike, unit: DateDurationUnit): Date;
220
- /** @deprecated */
221
- plus(value: DateLike, values: Partial<DateObject>): Date;
222
- /** @deprecated */
223
- minus(value: DateLike, values: Partial<DateObject>): Date;
224
- /** @deprecated */
225
- isSameDate(value: NullableDateLike, compare: NullableDateLike, unit?: DateUnit): boolean;
226
- /** @deprecated */
227
- isSameDateRange(value: NullableDateRangeLike, compare: NullableDateRangeLike, unit?: DateUnit): boolean;
228
- /** @deprecated */
229
- diff(value: DateLike, compare: DateLike, unit: DateUnit): number;
230
- /** @deprecated */
231
- toLocaleString(value: DateLike, options?: DateFormatOptions): string;
232
- /** @deprecated */
233
- format(value: DateLike, variant: DateFormatVariant): string;
234
- /** @deprecated */
235
- formatRange(value: NullableDateRangeLike, emptyText?: string): string;
236
- /** @deprecated */
237
- formatRelativeTime(value: DateLike, { style, compare }?: RelativeTimeFormatOptions): string;
238
- }
239
- declare function useDateUtils(): DateUtils;
240
-
241
159
  interface FormattedDateConfig extends Partial<DateConfig>, FormatDateConfig {
242
160
  }
243
161
  declare function useFormattedDate(input: NullableDateInput, { variant, fallback, ...dateConfig }: FormattedDateConfig): string;
@@ -268,4 +186,4 @@ declare function useDateTimeRange(input: NullableDateRangeInput, options?: Parti
268
186
 
269
187
  declare function useDateTime(input: NullableDateInput, options?: Partial<DateConfig>): DateTime;
270
188
 
271
- export { Calendar, CalendarClassNameMap, CalendarClassNames, CalendarDateEvent, CalendarDayEventHandler, CalendarDayHighlightColor, CalendarHighlightedDays, CalendarModifier, CalendarModifiers, CalendarProps, CalendarQuickSelection, CalendarQuickSelectionItem, CalendarQuickSelectionItemProps, CalendarQuickSelectionProps, DateConfig, DateConfigProvider, DateConfigProviderProps, DateDisplayVariant, DateDurationUnit, DateField, DateFieldAPI, DateFieldProps, DateFormat, DateFormatOptions, DateFormatVariant, DateLike, DateObject, DatePayload, DateRange, DateRangeField, DateRangeFieldProps, DateRangeLike, DateRangePayload, DateString, DateStringRange, DateTimeRange, DateUnit, DateUtils, FormatDateConfig, FormatDateRangeOptions, FormatRelativeTimeOptions, FormattedDate, FormattedDateConfig, FormattedDateProps, FormattedRelativeTime, FormattedRelativeTimeOptions, FormattedRelativeTimeProps, NullableDate, NullableDateInput, NullableDateLike, NullableDateRange, NullableDateRangeInput, NullableDateRangeLike, NullableDateString, PrimitiveDateInput, PrimitiveDateRangeInput, RelativeTimeFormatOptions, RelativeTimeFormatStyle, TimeField, TimeFieldProps, defaultDateConfig, formatDate, formatDateRange, formatRelativeTime, isDate, isDateLike, isDateRange, isDateRangeLike, isValidDate, isValidDateRange, parseDate, parseDateRange, setDefaultTimeZone, stringifyDate, stringifyDateRange, toDate, toDatePayload, toDateRange, toDateRangePayload, toPrimitiveDateInput, toPrimitiveDateRangeInput, useDateConfig, useDateTime, useDateTimeRange, useDateUtils, useDefaultTimeZone, useFormattedDate, useFormattedRelativeTime };
189
+ export { Calendar, CalendarClassNameMap, CalendarClassNames, CalendarDateEvent, CalendarDayEventHandler, CalendarDayHighlightColor, CalendarHighlightedDays, CalendarModifier, CalendarModifiers, CalendarProps, CalendarQuickSelection, CalendarQuickSelectionItem, CalendarQuickSelectionItemProps, CalendarQuickSelectionProps, DateConfig, DateConfigProvider, DateConfigProviderProps, DateDisplayVariant, DateField, DateFieldAPI, DateFieldProps, DateFormat, DatePayload, DateRangeField, DateRangeFieldProps, DateRangePayload, DateString, DateStringRange, DateTimeRange, FormatDateConfig, FormatDateRangeOptions, FormatRelativeTimeOptions, FormattedDate, FormattedDateConfig, FormattedDateProps, FormattedRelativeTime, FormattedRelativeTimeOptions, FormattedRelativeTimeProps, NullableDateInput, NullableDateRangeInput, NullableDateString, PrimitiveDateInput, PrimitiveDateRangeInput, TimeField, TimeFieldProps, defaultDateConfig, formatDate, formatDateRange, formatRelativeTime, parseDate, parseDateRange, setDefaultTimeZone, stringifyDate, stringifyDateRange, toDatePayload, toDateRangePayload, toPrimitiveDateInput, toPrimitiveDateRangeInput, useDateConfig, useDateTime, useDateTimeRange, useDefaultTimeZone, useFormattedDate, useFormattedRelativeTime };
package/dist-web/index.js CHANGED
@@ -15,15 +15,16 @@ import { Autocomplete } from '@material-ui/lab';
15
15
 
16
16
  Settings.defaultLocale = 'en-US';
17
17
  function setDefaultTimeZone(offset) {
18
- if (offset === 'local') {
19
- Settings.defaultZoneName = offset;
18
+ if (offset === 'system') {
19
+ Settings.defaultZone = offset;
20
20
  } else {
21
21
  var zone = FixedOffsetZone.instance(offset);
22
- if (zone.isValid) {
23
- Settings.defaultZoneName = zone.name;
24
- }
22
+ Settings.defaultZone = zone.name;
23
+ }
24
+ if (typeof Settings.defaultZone === 'string') {
25
+ return Settings.defaultZone;
25
26
  }
26
- return Settings.defaultZoneName;
27
+ return Settings.defaultZone.name;
27
28
  }
28
29
  function useDefaultTimeZone(offset) {
29
30
  return useMemo(() => setDefaultTimeZone(offset), [offset]);
@@ -1175,274 +1176,6 @@ var DateRangeField = /*#__PURE__*/forwardRef((_ref, ref) => {
1175
1176
  });
1176
1177
  if (process.env.NODE_ENV !== "production") DateRangeField.displayName = "DateRangeField";
1177
1178
 
1178
- /** @deprecated */
1179
-
1180
- /** @deprecated */
1181
-
1182
- /** @deprecated */
1183
-
1184
- /** @deprecated */
1185
-
1186
- /** @deprecated */
1187
-
1188
- /** @deprecated */
1189
-
1190
- /** @deprecated */
1191
-
1192
- /** @deprecated */
1193
-
1194
- /** @deprecated */
1195
-
1196
- /** @deprecated */
1197
-
1198
- /** @deprecated */
1199
- function toDateTime(value) {
1200
- return typeof value === 'number' ? DateTime.fromMillis(value) : DateTime.fromJSDate(value);
1201
- }
1202
-
1203
- /** @deprecated */
1204
- function isDate(value) {
1205
- return value != null && value instanceof Date;
1206
- }
1207
-
1208
- /** @deprecated */
1209
- function isDateLike(value) {
1210
- return isDate(value) || typeof value === 'number' && Number.isInteger(value);
1211
- }
1212
-
1213
- /** @deprecated */
1214
- function isValidDate(value) {
1215
- return isDate(value) && Number.isFinite(value.getTime());
1216
- }
1217
-
1218
- /** @deprecated */
1219
- function checkRange(range, validator) {
1220
- if (!Array.isArray(range) || range.length > 2) {
1221
- return false;
1222
- }
1223
- var [start, finish] = range;
1224
- return (start == null || validator(start)) && (finish == null || validator(finish));
1225
- }
1226
-
1227
- /** @deprecated */
1228
- function isDateRange(range) {
1229
- return checkRange(range, isDate);
1230
- }
1231
-
1232
- /** @deprecated */
1233
- function isDateRangeLike(range) {
1234
- return checkRange(range, isDateLike);
1235
- }
1236
-
1237
- /** @deprecated */
1238
- function isValidDateRange(range) {
1239
- return checkRange(range, isValidDate);
1240
- }
1241
-
1242
- /** @deprecated */
1243
- function toDate(value) {
1244
- return !isDateLike(value) ? new Date(NaN) : new Date(value);
1245
- }
1246
-
1247
- /** @deprecated */
1248
- function toDateRange(range) {
1249
- if (range == null || !isDateRangeLike(range)) {
1250
- return [];
1251
- }
1252
- return range.filter(x => x != null).map(x => x == null ? undefined : toDate(x)).sort((a, b) => !isValidDate(a) ? -1 : !isValidDate(b) ? 1 : a.valueOf() - b.valueOf());
1253
- }
1254
-
1255
- /** @deprecated */
1256
-
1257
- /** @deprecated */
1258
-
1259
- /** @deprecated */
1260
-
1261
- /** @deprecated */
1262
-
1263
- /** @deprecated */
1264
- class DateUtils {
1265
- /** @deprecated */
1266
- toObject(value) {
1267
- var {
1268
- year = NaN,
1269
- month = NaN,
1270
- day = NaN,
1271
- hour = NaN,
1272
- minute = NaN,
1273
- second = NaN,
1274
- millisecond = NaN
1275
- } = toDateTime(value).toObject({
1276
- includeConfig: false
1277
- });
1278
- return {
1279
- year,
1280
- month,
1281
- day,
1282
- hour,
1283
- minute,
1284
- second,
1285
- millisecond
1286
- };
1287
- }
1288
-
1289
- /** @deprecated */
1290
- fromObject(_ref) {
1291
- var {
1292
- year = 0,
1293
- month = 1,
1294
- day = 1,
1295
- hour = 0,
1296
- minute = 0,
1297
- second = 0,
1298
- millisecond = 0
1299
- } = _ref;
1300
- if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day) || Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
1301
- return new Date(NaN);
1302
- }
1303
- return DateTime.fromObject({
1304
- year,
1305
- month,
1306
- day,
1307
- hour,
1308
- minute,
1309
- second,
1310
- millisecond
1311
- }).toJSDate();
1312
- }
1313
-
1314
- /** @deprecated */
1315
- update(value, values) {
1316
- return toDateTime(value).set(values).toJSDate();
1317
- }
1318
-
1319
- /** @deprecated */
1320
- mergeDateAndTime(date, time) {
1321
- var {
1322
- hour,
1323
- minute,
1324
- second,
1325
- millisecond
1326
- } = this.toObject(time);
1327
- if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
1328
- return new Date(NaN);
1329
- }
1330
- return this.update(date, {
1331
- hour,
1332
- minute,
1333
- second,
1334
- millisecond
1335
- });
1336
- }
1337
-
1338
- /** @deprecated */
1339
- startOf(value, unit) {
1340
- return toDateTime(value).startOf(unit).toJSDate();
1341
- }
1342
-
1343
- /** @deprecated */
1344
- endOf(value, unit) {
1345
- return toDateTime(value).endOf(unit).toJSDate();
1346
- }
1347
-
1348
- /** @deprecated */
1349
- plus(value, values) {
1350
- return toDateTime(value).plus(values).toJSDate();
1351
- }
1352
-
1353
- /** @deprecated */
1354
- minus(value, values) {
1355
- return toDateTime(value).minus(values).toJSDate();
1356
- }
1357
-
1358
- /** @deprecated */
1359
- isSameDate(value, compare) {
1360
- var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'millisecond';
1361
- if (value == null && compare == null) {
1362
- return true;
1363
- }
1364
- if (value == null || compare == null) {
1365
- return false;
1366
- }
1367
- var dateTimeValue = toDateTime(value);
1368
- var dateTimeCompare = toDateTime(compare);
1369
- return dateTimeValue.isValid && dateTimeCompare.isValid && dateTimeValue.startOf(unit).equals(dateTimeCompare.startOf(unit));
1370
- }
1371
-
1372
- /** @deprecated */
1373
- isSameDateRange(value, compare, unit) {
1374
- var range1 = toDateRange(value);
1375
- var range2 = toDateRange(compare);
1376
- return !range1.some((date, idx) => !this.isSameDate(date, range2[idx], unit));
1377
- }
1378
-
1379
- /** @deprecated */
1380
- diff(value, compare, unit) {
1381
- var valueDateTime = toDateTime(value);
1382
- var compareDateTime = toDateTime(compare);
1383
- return valueDateTime.diff(compareDateTime, unit).as(unit);
1384
- }
1385
-
1386
- /** @deprecated */
1387
- toLocaleString(value, options) {
1388
- return toDateTime(value).toLocaleString(options);
1389
- }
1390
-
1391
- /** @deprecated */
1392
- format(value, variant) {
1393
- return this.toLocaleString(value, variant === 'date' ? {
1394
- day: '2-digit',
1395
- month: 'short',
1396
- year: 'numeric'
1397
- } : variant === 'shortDate' ? {
1398
- day: '2-digit',
1399
- month: 'short'
1400
- } : variant === 'time' ? {
1401
- hour: 'numeric',
1402
- minute: 'numeric'
1403
- } : {
1404
- day: '2-digit',
1405
- month: 'short',
1406
- year: 'numeric',
1407
- hour: 'numeric',
1408
- minute: 'numeric'
1409
- });
1410
- }
1411
-
1412
- /** @deprecated */
1413
- formatRange(value) {
1414
- var emptyText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1415
- var range = toDateRange(value);
1416
- if (!isValidDateRange(range)) {
1417
- return 'Invalid Date Range';
1418
- }
1419
- var [start, finish] = range;
1420
- if (!start) {
1421
- return emptyText;
1422
- }
1423
- var startText = this.format(start, !this.isSameDate(start, finish, 'year') ? 'date' : 'shortDate');
1424
- var finishText = !finish ? '…' : this.format(finish, 'date');
1425
- return "".concat(startText, " - ").concat(finishText);
1426
- }
1427
-
1428
- /** @deprecated */
1429
- formatRelativeTime(value) {
1430
- var {
1431
- style = 'long',
1432
- compare = Date.now()
1433
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1434
- var valueDateTime = toDateTime(value);
1435
- var compareDateTime = toDateTime(compare);
1436
- return valueDateTime.toRelative({
1437
- style,
1438
- base: compareDateTime
1439
- });
1440
- }
1441
- }
1442
- function useDateUtils() {
1443
- return useMemo(() => new DateUtils(), []);
1444
- }
1445
-
1446
1179
  var _excluded$5 = ["unit", "round", "padding", "fallback", "base"],
1447
1180
  _excluded2$3 = ["date", "fallback"];
1448
1181
  function useFormattedRelativeTime(input) {
@@ -1600,5 +1333,5 @@ var TimeField = /*#__PURE__*/forwardRef((_ref2, ref) => {
1600
1333
  });
1601
1334
  if (process.env.NODE_ENV !== "production") TimeField.displayName = "TimeField";
1602
1335
 
1603
- export { Calendar, CalendarQuickSelection, CalendarQuickSelectionItem, DateConfigProvider, DateField, DateRangeField, DateUtils, FormattedDate, FormattedRelativeTime, TimeField, defaultDateConfig, formatDate, formatDateRange, formatRelativeTime, isDate, isDateLike, isDateRange, isDateRangeLike, isValidDate, isValidDateRange, parseDate, parseDateRange, setDefaultTimeZone, stringifyDate, stringifyDateRange, toDate, toDatePayload, toDateRange, toDateRangePayload, toPrimitiveDateInput, toPrimitiveDateRangeInput, useDateConfig, useDateTime, useDateTimeRange, useDateUtils, useDefaultTimeZone, useFormattedDate, useFormattedRelativeTime };
1336
+ export { Calendar, CalendarQuickSelection, CalendarQuickSelectionItem, DateConfigProvider, DateField, DateRangeField, FormattedDate, FormattedRelativeTime, TimeField, defaultDateConfig, formatDate, formatDateRange, formatRelativeTime, parseDate, parseDateRange, setDefaultTimeZone, stringifyDate, stringifyDateRange, toDatePayload, toDateRangePayload, toPrimitiveDateInput, toPrimitiveDateRangeInput, useDateConfig, useDateTime, useDateTimeRange, useDefaultTimeZone, useFormattedDate, useFormattedRelativeTime };
1604
1337
  //# sourceMappingURL=index.js.map