@superdispatch/dates 0.25.1 → 0.26.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.
@@ -8,50 +8,45 @@ import { useValueObserver } from '@superdispatch/hooks';
8
8
  import { Color, mergeRefs, useUID } from '@superdispatch/ui';
9
9
  import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
10
10
  import styled from 'styled-components';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- import { Fragment as _Fragment } from "react/jsx-runtime";
13
- import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
14
12
  var Popover = /*#__PURE__*/styled(MuiPopover).withConfig({
15
13
  displayName: "BaseDatePicker__Popover",
16
14
  componentId: "SD__sc-1xvk8l6-0"
17
15
  })([".MuiPaper-rounded{border:1px solid ", ";box-shadow:0px 0px 4px 0px rgba(0,0,0,0.05),0px 4px 8px 0px rgba(0,0,0,0.12);}"], Color.Silver400);
18
16
  export var BaseDatePicker = /*#__PURE__*/forwardRef((_ref, ref) => {
19
17
  var {
20
- id,
21
- api,
22
- onClear,
23
- onClick: _onClick,
24
- onClose,
25
- onKeyDown: _onKeyDown,
26
- disabled,
27
- children,
28
- enableClearable,
29
- inputRef: inputRefProp,
30
- InputProps: inputProps
31
- } = _ref,
32
- textFieldProps = _objectWithoutProperties(_ref, _excluded);
33
-
18
+ id,
19
+ api,
20
+ onClear,
21
+ onClick: _onClick,
22
+ onClose,
23
+ onKeyDown: _onKeyDown,
24
+ disabled,
25
+ children,
26
+ enableClearable,
27
+ inputRef: inputRefProp,
28
+ InputProps: inputProps
29
+ } = _ref,
30
+ textFieldProps = _objectWithoutProperties(_ref, _excluded);
34
31
  var uid = useUID(id);
35
32
  var labelID = "".concat(uid, "-label");
36
33
  var clearIconID = "".concat(uid, "-clear-icon");
37
34
  var inputRef = useRef(null);
38
35
  var textFieldRef = useRef(null);
39
36
  var [popoverAnchor, setPopoverAnchor] = useState(null);
40
-
41
37
  function handleOpen() {
42
38
  if (!disabled && textFieldRef.current) {
43
39
  setPopoverAnchor(textFieldRef.current);
44
40
  }
45
41
  }
46
-
47
42
  function handleClose() {
48
43
  setPopoverAnchor(null);
49
44
  }
50
-
51
45
  useImperativeHandle(api, () => ({
52
46
  close: handleClose
53
- })); // We want to trigger close event only when UI will be ready after updates.
47
+ }));
54
48
 
49
+ // We want to trigger close event only when UI will be ready after updates.
55
50
  useValueObserver(popoverAnchor, () => {
56
51
  if (!popoverAnchor) {
57
52
  onClose === null || onClose === void 0 ? void 0 : onClose();
@@ -78,14 +73,12 @@ export var BaseDatePicker = /*#__PURE__*/forwardRef((_ref, ref) => {
78
73
  inputRef: mergeRefs(inputRef, inputRefProp),
79
74
  onClick: event => {
80
75
  _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
81
-
82
76
  if (!event.defaultPrevented) {
83
77
  handleOpen();
84
78
  }
85
79
  },
86
80
  onKeyDown: event => {
87
81
  _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(event);
88
-
89
82
  if (!event.defaultPrevented && (event.key === ' ' || event.key === 'Enter')) {
90
83
  handleOpen();
91
84
  }
@@ -10,13 +10,12 @@ import DayPicker from 'react-day-picker';
10
10
  import { useDateConfig } from "../date-config/DateConfig.js";
11
11
  import { stringifyDate } from "../date-time-utils/DateTimeUtils.js";
12
12
  import { useDateTime } from "../use-date-time/useDateTime.js";
13
- import { CalendarCaption, CalendarNavbar, CalendarWeekDay } from "./InternalCalendarComponents.js"; //
13
+ import { CalendarCaption, CalendarNavbar, CalendarWeekDay } from "./InternalCalendarComponents.js";
14
+
15
+ //
14
16
  // Styles
15
17
  //
16
-
17
- import { jsx as _jsx } from "react/jsx-runtime";
18
- import { Fragment as _Fragment } from "react/jsx-runtime";
19
- import { jsxs as _jsxs } from "react/jsx-runtime";
18
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
20
19
  var useStyles = /*#__PURE__*/makeStyles(theme => ({
21
20
  container: {
22
21
  display: 'inline-block'
@@ -223,18 +222,20 @@ var useStyles = /*#__PURE__*/makeStyles(theme => ({
223
222
  todayButton: {}
224
223
  }), {
225
224
  name: 'SD-Calendar'
226
- }); //
225
+ });
226
+
227
+ //
227
228
  // Utility Types
228
229
  //
229
230
 
230
231
  //
231
232
  // Internal Utils
232
233
  //
234
+
233
235
  function toDayPickerModifier(config, modifier) {
234
236
  if (!modifier) {
235
237
  return undefined;
236
238
  }
237
-
238
239
  return localDate => {
239
240
  var dateValue = DateTime.fromObject({
240
241
  year: localDate.getFullYear(),
@@ -252,12 +253,10 @@ function toDayPickerModifier(config, modifier) {
252
253
  });
253
254
  };
254
255
  }
255
-
256
256
  function toDayPickerHandler(config, classes, initialTime, handler) {
257
257
  if (!handler) {
258
258
  return undefined;
259
259
  }
260
-
261
260
  return (localDate, modifiers) => {
262
261
  var dateValue = DateTime.fromObject({
263
262
  year: localDate.getFullYear(),
@@ -276,35 +275,35 @@ function toDayPickerHandler(config, classes, initialTime, handler) {
276
275
  stringValue: stringifyDate(dateValue, config)
277
276
  });
278
277
  };
279
- } //
278
+ }
279
+
280
+ //
280
281
  // Calendar
281
282
  //
282
283
 
283
-
284
284
  export var Calendar = /*#__PURE__*/forwardRef((_ref, ref) => {
285
285
  var {
286
- footer,
287
- classes,
288
- direction,
289
- quickSelection,
290
- selectedDays,
291
- disabledDays,
292
- onDayClick,
293
- onDayKeyDown,
294
- onDayMouseEnter,
295
- onDayMouseLeave,
296
- onDayMouseDown,
297
- onDayMouseUp,
298
- onDayTouchEnd,
299
- onDayTouchStart,
300
- modifiers,
301
- highlightedDays,
302
- format: formatProp,
303
- initialTime: initialTimeInputProp,
304
- initialMonth: initialMonthInputProp
305
- } = _ref,
306
- dayPickerProps = _objectWithoutProperties(_ref, _excluded);
307
-
286
+ footer,
287
+ classes,
288
+ direction,
289
+ quickSelection,
290
+ selectedDays,
291
+ disabledDays,
292
+ onDayClick,
293
+ onDayKeyDown,
294
+ onDayMouseEnter,
295
+ onDayMouseLeave,
296
+ onDayMouseDown,
297
+ onDayMouseUp,
298
+ onDayTouchEnd,
299
+ onDayTouchStart,
300
+ modifiers,
301
+ highlightedDays,
302
+ format: formatProp,
303
+ initialTime: initialTimeInputProp,
304
+ initialMonth: initialMonthInputProp
305
+ } = _ref,
306
+ dayPickerProps = _objectWithoutProperties(_ref, _excluded);
308
307
  var styles = useStyles({
309
308
  classes
310
309
  });
@@ -316,15 +315,12 @@ export var Calendar = /*#__PURE__*/forwardRef((_ref, ref) => {
316
315
  var [initialTime, initialMonth] = useMemo(() => {
317
316
  var time = initialTimeInput;
318
317
  var month = initialMonthInput;
319
-
320
318
  if (!month.isValid) {
321
319
  month = DateTime.local().startOf('month');
322
320
  }
323
-
324
321
  if (!time.isValid) {
325
322
  time = month;
326
323
  }
327
-
328
324
  return [time, new Date(month.year, month.month - 1, month.day, month.hour, month.minute, month.second, month.millisecond)];
329
325
  }, [initialTimeInput, initialMonthInput]);
330
326
  var wrapModifier = toDayPickerModifier.bind(null, config);
@@ -343,19 +339,16 @@ export var Calendar = /*#__PURE__*/forwardRef((_ref, ref) => {
343
339
  return dateValue.day === dateValue.daysInMonth;
344
340
  })
345
341
  };
346
-
347
342
  if (modifiers) {
348
343
  for (var [key, modifier] of Object.entries(modifiers)) {
349
344
  dayPickerModifiers[key] = wrapModifier(modifier);
350
345
  }
351
346
  }
352
-
353
347
  if (highlightedDays) {
354
348
  for (var [_key, _modifier] of Object.entries(highlightedDays)) {
355
349
  dayPickerModifiers[styles[_key]] = wrapModifier(_modifier);
356
350
  }
357
351
  }
358
-
359
352
  return /*#__PURE__*/_jsxs(Grid, {
360
353
  ref: ref,
361
354
  container: true,
@@ -1,7 +1,6 @@
1
1
  import { List, ListItem, Typography } from '@material-ui/core';
2
2
  import { forwardRef } from 'react';
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- import { jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
4
  export var CalendarQuickSelectionItem = /*#__PURE__*/forwardRef((_ref, ref) => {
6
5
  var {
7
6
  onClick,
@@ -1,8 +1,6 @@
1
1
  import { IconButton, Typography } from '@material-ui/core';
2
2
  import { ChevronLeft, ChevronRight } from '@material-ui/icons';
3
- import { jsx as _jsx } from "react/jsx-runtime";
4
- import { Fragment as _Fragment } from "react/jsx-runtime";
5
- import { jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
4
  export function CalendarCaption(_ref) {
7
5
  var {
8
6
  date,
@@ -6,12 +6,10 @@ export function setDefaultTimeZone(offset) {
6
6
  Settings.defaultZoneName = offset;
7
7
  } else {
8
8
  var zone = FixedOffsetZone.instance(offset);
9
-
10
9
  if (zone.isValid) {
11
10
  Settings.defaultZoneName = zone.name;
12
11
  }
13
12
  }
14
-
15
13
  return Settings.defaultZoneName;
16
14
  }
17
15
  export function useDefaultTimeZone(offset) {
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["onDayClick"],
4
- _excluded2 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "variant", "enableClearable", "disableCloseOnSelect", "CalendarProps"];
4
+ _excluded2 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "variant", "enableClearable", "disableCloseOnSelect", "CalendarProps"];
5
5
  import { forwardRef, useMemo, useRef } from 'react';
6
6
  import { BaseDatePicker } from "../base-date-picker/BaseDatePicker.js";
7
7
  import { Calendar } from "../calendar/Calendar.js";
@@ -12,24 +12,23 @@ import { useDateTime } from "../use-date-time/useDateTime.js";
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  export var DateField = /*#__PURE__*/forwardRef((_ref, ref) => {
14
14
  var {
15
- onBlur,
16
- onFocus,
17
- onChange,
18
- renderFooter,
19
- renderQuickSelection,
20
- value: valueProp,
21
- format: formatProp,
22
- fallback = '',
23
- variant = 'Date',
24
- enableClearable,
25
- disableCloseOnSelect,
26
- CalendarProps: {
27
- onDayClick: _onDayClick
28
- } = {}
29
- } = _ref,
30
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded),
31
- textFieldProps = _objectWithoutProperties(_ref, _excluded2);
32
-
15
+ onBlur,
16
+ onFocus,
17
+ onChange,
18
+ renderFooter,
19
+ renderQuickSelection,
20
+ value: valueProp,
21
+ format: formatProp,
22
+ fallback = '',
23
+ variant = 'Date',
24
+ enableClearable,
25
+ disableCloseOnSelect,
26
+ CalendarProps: {
27
+ onDayClick: _onDayClick
28
+ } = {}
29
+ } = _ref,
30
+ calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded),
31
+ textFieldProps = _objectWithoutProperties(_ref, _excluded2);
33
32
  var config = useDateConfig({
34
33
  format: formatProp
35
34
  });
@@ -40,23 +39,18 @@ export var DateField = /*#__PURE__*/forwardRef((_ref, ref) => {
40
39
  fallback
41
40
  }, config));
42
41
  var dateString = useMemo(() => stringifyDate(date, config), [date, config]);
43
-
44
42
  function handleClose() {
45
43
  var _apiRef$current;
46
-
47
44
  (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
48
45
  }
49
-
50
46
  function handleChange(nextInput) {
51
47
  if (onChange) {
52
48
  onChange(toDatePayload(nextInput, config));
53
49
  }
54
-
55
50
  if (!disableCloseOnSelect) {
56
51
  handleClose();
57
52
  }
58
53
  }
59
-
60
54
  var api = {
61
55
  config,
62
56
  dateValue: date,
@@ -85,7 +79,6 @@ export var DateField = /*#__PURE__*/forwardRef((_ref, ref) => {
85
79
  },
86
80
  onDayClick: event => {
87
81
  _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
88
-
89
82
  if (!event.disabled) {
90
83
  handleChange(event.dateValue);
91
84
  }
@@ -1,8 +1,8 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["modifiers", "onDayClick", "onDayMouseEnter"],
4
- _excluded2 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "enableClearable", "disableCloseOnSelect", "CalendarProps"],
5
- _excluded3 = ["rangeStart", "rangeFinish"];
4
+ _excluded2 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "enableClearable", "disableCloseOnSelect", "CalendarProps"],
5
+ _excluded3 = ["rangeStart", "rangeFinish"];
6
6
  import { makeStyles } from '@material-ui/styles';
7
7
  import { Color } from '@superdispatch/ui';
8
8
  import { forwardRef, useMemo, useRef, useState } from 'react';
@@ -49,34 +49,31 @@ var useStyles = /*#__PURE__*/makeStyles(theme => ({
49
49
  });
50
50
  export var DateRangeField = /*#__PURE__*/forwardRef((_ref, ref) => {
51
51
  var {
52
- onBlur,
53
- onFocus,
54
- onChange,
55
- renderFooter,
56
- renderQuickSelection,
57
- value: valueProp,
58
- format: formatProp,
59
- fallback = '',
60
- enableClearable,
61
- disableCloseOnSelect,
62
- CalendarProps: {
63
- modifiers,
64
- onDayClick: _onDayClick,
65
- onDayMouseEnter: _onDayMouseEnter
66
- } = {}
67
- } = _ref,
68
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded),
69
- textFieldProps = _objectWithoutProperties(_ref, _excluded2);
70
-
52
+ onBlur,
53
+ onFocus,
54
+ onChange,
55
+ renderFooter,
56
+ renderQuickSelection,
57
+ value: valueProp,
58
+ format: formatProp,
59
+ fallback = '',
60
+ enableClearable,
61
+ disableCloseOnSelect,
62
+ CalendarProps: {
63
+ modifiers,
64
+ onDayClick: _onDayClick,
65
+ onDayMouseEnter: _onDayMouseEnter
66
+ } = {}
67
+ } = _ref,
68
+ calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded),
69
+ textFieldProps = _objectWithoutProperties(_ref, _excluded2);
71
70
  var apiRef = useRef(null);
72
-
73
71
  var _useStyles = useStyles({}),
74
- {
75
- rangeStart,
76
- rangeFinish
77
- } = _useStyles,
78
- styles = _objectWithoutProperties(_useStyles, _excluded3);
79
-
72
+ {
73
+ rangeStart,
74
+ rangeFinish
75
+ } = _useStyles,
76
+ styles = _objectWithoutProperties(_useStyles, _excluded3);
80
77
  var config = useDateConfig({
81
78
  format: formatProp
82
79
  });
@@ -90,18 +87,13 @@ export var DateRangeField = /*#__PURE__*/forwardRef((_ref, ref) => {
90
87
  var [nextCalendarStartDate, nextCalendarFinishDate] = parseDateRange([startDate, finishDate || hoveredDate], config);
91
88
  return [nextCalendarStartDate === null || nextCalendarStartDate === void 0 ? void 0 : nextCalendarStartDate.startOf('day'), nextCalendarFinishDate === null || nextCalendarFinishDate === void 0 ? void 0 : nextCalendarFinishDate.endOf('day')];
92
89
  }, [config, startDate, finishDate, hoveredDate]);
93
-
94
90
  function handleClose() {
95
91
  var _apiRef$current;
96
-
97
92
  (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
98
93
  }
99
-
100
94
  function handleChange(nextValue) {
101
95
  var _nextFinishDate;
102
-
103
96
  var [nextStartDate, nextFinishDate] = parseDateRange(nextValue, config);
104
-
105
97
  if (onChange) {
106
98
  if (nextStartDate) {
107
99
  if (startDate) {
@@ -115,19 +107,15 @@ export var DateRangeField = /*#__PURE__*/forwardRef((_ref, ref) => {
115
107
  nextStartDate = nextStartDate.startOf('day');
116
108
  }
117
109
  }
118
-
119
110
  if (nextFinishDate) {
120
111
  nextFinishDate = nextFinishDate.endOf('day');
121
112
  }
122
-
123
113
  onChange(toDateRangePayload([nextStartDate, nextFinishDate], config));
124
114
  }
125
-
126
115
  if (!disableCloseOnSelect && (_nextFinishDate = nextFinishDate) !== null && _nextFinishDate !== void 0 && _nextFinishDate.isValid) {
127
116
  handleClose();
128
117
  }
129
118
  }
130
-
131
119
  var api = {
132
120
  config,
133
121
  close: handleClose,
@@ -170,15 +158,12 @@ export var DateRangeField = /*#__PURE__*/forwardRef((_ref, ref) => {
170
158
  var {
171
159
  dateValue
172
160
  } = _ref4;
173
-
174
161
  if (calendarStartDate) {
175
162
  if (!calendarFinishDate) {
176
163
  return calendarStartDate.hasSame(dateValue, 'day');
177
164
  }
178
-
179
165
  return calendarStartDate <= dateValue && dateValue <= calendarFinishDate;
180
166
  }
181
-
182
167
  return false;
183
168
  },
184
169
  footer: renderFooter === null || renderFooter === void 0 ? void 0 : renderFooter(api),
@@ -189,7 +174,6 @@ export var DateRangeField = /*#__PURE__*/forwardRef((_ref, ref) => {
189
174
  },
190
175
  onDayClick: event => {
191
176
  _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
192
-
193
177
  if (!event.disabled) {
194
178
  if (startDate && !finishDate) {
195
179
  handleChange([startDateString, event.stringValue]);
@@ -1,5 +1,7 @@
1
1
  import { DateTime, Settings } from 'luxon';
2
- import { defaultDateConfig } from "../date-config/DateConfig.js"; //
2
+ import { defaultDateConfig } from "../date-config/DateConfig.js";
3
+
4
+ //
3
5
  // Config
4
6
  //
5
7
 
@@ -29,7 +31,9 @@ var DATE_DISPLAY_VARIANTS = {
29
31
  hour: 'numeric',
30
32
  minute: 'numeric'
31
33
  }
32
- }; //
34
+ };
35
+
36
+ //
33
37
  // Date Utils
34
38
  //
35
39
 
@@ -37,72 +41,57 @@ export function toPrimitiveDateInput(input) {
37
41
  if (typeof input == 'number' || typeof input == 'string') {
38
42
  return input;
39
43
  }
40
-
41
44
  if (input instanceof Date || input instanceof DateTime) {
42
45
  return input.valueOf();
43
46
  }
44
-
45
47
  return NaN;
46
48
  }
47
49
  export function parseDate(input) {
48
50
  var {
49
51
  format
50
52
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig;
51
-
52
53
  if (input instanceof DateTime) {
53
54
  var {
54
55
  defaultZone
55
56
  } = Settings;
56
-
57
57
  if (!defaultZone.equals(input.zone)) {
58
58
  return input.setZone(defaultZone);
59
59
  }
60
-
61
60
  return input;
62
61
  }
63
-
64
62
  if (input instanceof Date) {
65
63
  return DateTime.fromJSDate(input);
66
64
  }
67
-
68
65
  if (typeof input === 'number') {
69
66
  return DateTime.fromMillis(input);
70
67
  }
71
-
72
68
  if (typeof input == 'string') {
73
69
  switch (format) {
74
70
  case 'DateISO':
75
71
  case 'DateTimeISO':
76
72
  return DateTime.fromISO(input);
77
-
78
73
  default:
79
74
  return DateTime.fromFormat(input, DATE_FORMATS[format]);
80
75
  }
81
76
  }
82
-
83
77
  return DateTime.invalid('invalid input');
84
78
  }
85
79
  export function stringifyDate(input) {
86
80
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig;
87
81
  var date = parseDate(input, config);
88
-
89
82
  if (date.isValid) {
90
83
  var {
91
84
  format
92
85
  } = config;
93
-
94
86
  switch (format) {
95
87
  case 'DateISO':
96
88
  return date.toISODate();
97
-
98
89
  case 'DateTimeISO':
99
90
  return date.toISO();
100
-
101
91
  default:
102
92
  return date.toFormat(DATE_FORMATS[format]);
103
93
  }
104
94
  }
105
-
106
95
  return null;
107
96
  }
108
97
  export function formatDate(input, _ref) {
@@ -112,24 +101,19 @@ export function formatDate(input, _ref) {
112
101
  } = _ref;
113
102
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig;
114
103
  var date = parseDate(input, config);
115
-
116
104
  if (!date.isValid) {
117
105
  return fallback;
118
106
  }
119
-
120
107
  return date.toLocaleString(DATE_DISPLAY_VARIANTS[variant]);
121
108
  }
122
-
123
109
  function formatUnit(unit) {
124
110
  switch (unit) {
125
111
  case 'months':
126
112
  return 'mo';
127
-
128
113
  default:
129
114
  return unit.charAt(0);
130
115
  }
131
116
  }
132
-
133
117
  export function formatRelativeTime(input) {
134
118
  var {
135
119
  round = true,
@@ -142,36 +126,28 @@ export function formatRelativeTime(input) {
142
126
  var base = baseOption == null ? DateTime.now() : parseDate(baseOption, config);
143
127
  var date = parseDate(input, config);
144
128
  var padding = paddingOption ? date < base ? -paddingOption : paddingOption : 0;
145
-
146
129
  function format(value, unit) {
147
130
  var isPast = Object.is(value, -0) || value < 0;
148
131
  var diff = Math.abs(!round ? value : Math.trunc(value));
149
132
  var formattedUnit = formatUnit(unit);
150
133
  return isPast ? "".concat(diff).concat(formattedUnit, " ago") : "in ".concat(diff).concat(formattedUnit);
151
134
  }
152
-
153
135
  function differ(unit) {
154
136
  return date.plus(padding).diff(base, unit).get(unit);
155
137
  }
156
-
157
138
  if (date.isValid && base.isValid) {
158
139
  var units = ['years', 'months', 'days', 'hours', 'minutes', 'seconds'];
159
-
160
140
  if (unitOption) {
161
141
  return format(differ(unitOption), unitOption);
162
142
  }
163
-
164
143
  for (var unit of units) {
165
144
  var diff = differ(unit);
166
-
167
145
  if (Math.abs(diff) >= 1) {
168
146
  return format(diff, unit);
169
147
  }
170
148
  }
171
-
172
149
  return format(0, 'seconds');
173
150
  }
174
-
175
151
  return fallback;
176
152
  }
177
153
  export function toDatePayload(input) {
@@ -182,7 +158,9 @@ export function toDatePayload(input) {
182
158
  dateValue,
183
159
  stringValue: stringifyDate(dateValue, config)
184
160
  };
185
- } //
161
+ }
162
+
163
+ //
186
164
  // Date Range Utils
187
165
  //
188
166
 
@@ -190,17 +168,14 @@ export function toPrimitiveDateRangeInput(input) {
190
168
  if (!Array.isArray(input)) {
191
169
  return [undefined, undefined];
192
170
  }
193
-
194
171
  return [toPrimitiveDateInput(input[0]), toPrimitiveDateInput(input[1])];
195
172
  }
196
173
  export function parseDateRange(input, config) {
197
174
  var start = null;
198
175
  var finish = null;
199
-
200
176
  if (Array.isArray(input)) {
201
177
  [start = null, finish = null] = input.map(value => parseDate(value, config)).filter(date => date.isValid).sort((a, b) => a.valueOf() - b.valueOf());
202
178
  }
203
-
204
179
  return [start, finish];
205
180
  }
206
181
  export function stringifyDateRange(input, config) {
@@ -213,11 +188,9 @@ export function formatDateRange(input, _ref2) {
213
188
  } = _ref2;
214
189
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig;
215
190
  var [start, finish] = parseDateRange(input, config);
216
-
217
191
  if (!start) {
218
192
  return fallback;
219
193
  }
220
-
221
194
  var startVariant = !(finish !== null && finish !== void 0 && finish.hasSame(start, 'year')) ? 'Date' : 'ShortDate';
222
195
  var startText = formatDate(start, {
223
196
  variant: startVariant