@spaced-out/ui-design-system 0.3.7 → 0.3.8-beta.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.
- package/CHANGELOG.md +7 -0
- package/lib/components/DateRangePicker/Calendar.js +10 -7
- package/lib/components/DateRangePicker/Calendar.js.flow +13 -9
- package/lib/components/DateRangePicker/DateRangePicker.js +27 -10
- package/lib/components/DateRangePicker/DateRangePicker.js.flow +45 -21
- package/lib/components/DateRangePicker/DateRangeWrapper.js +22 -19
- package/lib/components/DateRangePicker/DateRangeWrapper.js.flow +29 -22
- package/lib/components/DateRangePicker/Day.js +3 -3
- package/lib/components/DateRangePicker/Day.js.flow +4 -3
- package/lib/utils/date-range-picker/date-range-picker.js +63 -38
- package/lib/utils/date-range-picker/date-range-picker.js.flow +75 -38
- package/lib/utils/date-range-picker/timezones.js +12 -2
- package/lib/utils/date-range-picker/timezones.js.flow +13 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.3.8-beta.0](https://github.com/spaced-out/ui-design-system/compare/v0.3.7...v0.3.8-beta.0) (2024-12-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* [CE-15675, CE-15677] adding consistency wrt to timezone in daterangepicker ([#296](https://github.com/spaced-out/ui-design-system/issues/296)) ([992ce9e](https://github.com/spaced-out/ui-design-system/commit/992ce9e2988ec531b8bfdadb02976fbcb63ee5be))
|
|
11
|
+
|
|
5
12
|
### [0.3.7](https://github.com/spaced-out/ui-design-system/compare/v0.3.6...v0.3.7) (2024-11-29)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -5,8 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Calendar = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
9
9
|
var _utils = require("../../utils");
|
|
10
|
+
var _dateRangePicker = require("../../utils/date-range-picker");
|
|
10
11
|
var _Text = require("../Text");
|
|
11
12
|
var _Day = require("./Day");
|
|
12
13
|
var _CalendarModule = _interopRequireDefault(require("./Calendar.module.css"));
|
|
@@ -23,9 +24,9 @@ const getFormattedDate = (marker, dateRange) => {
|
|
|
23
24
|
} = dateRange;
|
|
24
25
|
switch (marker) {
|
|
25
26
|
case _utils.MARKERS.DATE_RANGE_START:
|
|
26
|
-
return startDate ?
|
|
27
|
+
return startDate ? _moment.default.utc(startDate).format('MMMM D, YYYY') : 'Start Date';
|
|
27
28
|
default:
|
|
28
|
-
return endDate ?
|
|
29
|
+
return endDate ? _moment.default.utc(endDate).format('MMMM D, YYYY') : 'End Date';
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
const Calendar = _ref => {
|
|
@@ -37,7 +38,8 @@ const Calendar = _ref => {
|
|
|
37
38
|
handlers,
|
|
38
39
|
hoverDay,
|
|
39
40
|
dateRange,
|
|
40
|
-
inHoverRange
|
|
41
|
+
inHoverRange,
|
|
42
|
+
today
|
|
41
43
|
} = _ref;
|
|
42
44
|
return /*#__PURE__*/React.createElement("div", {
|
|
43
45
|
className: _CalendarModule.default.calendar
|
|
@@ -62,18 +64,19 @@ const Calendar = _ref => {
|
|
|
62
64
|
onDayClick,
|
|
63
65
|
onDayHover
|
|
64
66
|
} = handlers;
|
|
67
|
+
const dateValue = _moment.default.utc(date);
|
|
65
68
|
return /*#__PURE__*/React.createElement(_Day.Day, {
|
|
66
69
|
key: date,
|
|
67
70
|
date: date,
|
|
68
71
|
filled: isStart || isEnd,
|
|
69
72
|
onClick: () => onDayClick(date),
|
|
70
73
|
onHover: () => onDayHover(date),
|
|
71
|
-
outlined: (0,
|
|
72
|
-
disabled: minDate && (0,
|
|
74
|
+
outlined: (0, _dateRangePicker.isSame)(date, today, 'd'),
|
|
75
|
+
disabled: minDate && (0, _dateRangePicker.isBefore)(date, minDate) || (0, _dateRangePicker.isAfter)(date, maxDate) || !(0, _dateRangePicker.isSame)(date, value, 'month'),
|
|
73
76
|
endOfRange: isEnd && !isRangeValid,
|
|
74
77
|
highlighted: highlighted && !isRangeValid,
|
|
75
78
|
startOfRange: isStart && !isRangeValid,
|
|
76
|
-
value:
|
|
79
|
+
value: dateValue.date(),
|
|
77
80
|
hoverDay: hoverDay
|
|
78
81
|
});
|
|
79
82
|
}))));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
// $FlowFixMe[untyped-import]
|
|
5
|
-
import moment from 'moment
|
|
5
|
+
import moment from 'moment';
|
|
6
6
|
|
|
7
7
|
import type {DateRange} from '../../types';
|
|
8
8
|
import {
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
NAVIGATION_ACTION,
|
|
17
17
|
WEEKDAYS,
|
|
18
18
|
} from '../../utils';
|
|
19
|
+
import {isAfter, isBefore, isSame} from '../../utils/date-range-picker';
|
|
19
20
|
import {BodySmall, SubTitleExtraSmall, TEXT_COLORS} from '../Text';
|
|
20
21
|
|
|
21
22
|
import {Day} from './Day';
|
|
@@ -39,6 +40,7 @@ type CalendarProps = {
|
|
|
39
40
|
action: $Values<typeof NAVIGATION_ACTION>,
|
|
40
41
|
) => void,
|
|
41
42
|
},
|
|
43
|
+
today: string,
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
const getFormattedDate = (marker: string, dateRange: DateRange) => {
|
|
@@ -46,10 +48,10 @@ const getFormattedDate = (marker: string, dateRange: DateRange) => {
|
|
|
46
48
|
switch (marker) {
|
|
47
49
|
case MARKERS.DATE_RANGE_START:
|
|
48
50
|
return startDate
|
|
49
|
-
? moment(startDate).format('MMMM D, YYYY')
|
|
51
|
+
? moment.utc(startDate).format('MMMM D, YYYY')
|
|
50
52
|
: 'Start Date';
|
|
51
53
|
default:
|
|
52
|
-
return endDate ? moment(endDate).format('MMMM D, YYYY') : 'End Date';
|
|
54
|
+
return endDate ? moment.utc(endDate).format('MMMM D, YYYY') : 'End Date';
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
|
|
@@ -62,6 +64,7 @@ export const Calendar = ({
|
|
|
62
64
|
hoverDay,
|
|
63
65
|
dateRange,
|
|
64
66
|
inHoverRange,
|
|
67
|
+
today,
|
|
65
68
|
}: CalendarProps): React.Node => (
|
|
66
69
|
<div className={css.calendar}>
|
|
67
70
|
<SubTitleExtraSmall
|
|
@@ -85,13 +88,14 @@ export const Calendar = ({
|
|
|
85
88
|
|
|
86
89
|
{getDaysInMonth(value).map((week, index) => (
|
|
87
90
|
<div key={week[index]} className={css.calendarRow}>
|
|
88
|
-
{week.map((date) => {
|
|
91
|
+
{week.map((date: string) => {
|
|
89
92
|
const isRangeValid = isStartDateEndDateSame(dateRange);
|
|
90
93
|
const isStart = isStartOfRange(dateRange, date);
|
|
91
94
|
const isEnd = isEndOfRange(dateRange, date);
|
|
92
95
|
const highlighted =
|
|
93
96
|
inDateRange(dateRange, date) || inHoverRange(date);
|
|
94
97
|
const {onDayClick, onDayHover} = handlers;
|
|
98
|
+
const dateValue = moment.utc(date);
|
|
95
99
|
|
|
96
100
|
return (
|
|
97
101
|
<Day
|
|
@@ -100,16 +104,16 @@ export const Calendar = ({
|
|
|
100
104
|
filled={isStart || isEnd}
|
|
101
105
|
onClick={() => onDayClick(date)}
|
|
102
106
|
onHover={() => onDayHover(date)}
|
|
103
|
-
outlined={
|
|
107
|
+
outlined={isSame(date, today, 'd')}
|
|
104
108
|
disabled={
|
|
105
|
-
(minDate &&
|
|
106
|
-
|
|
107
|
-
!
|
|
109
|
+
(minDate && isBefore(date, minDate)) ||
|
|
110
|
+
isAfter(date, maxDate) ||
|
|
111
|
+
!isSame(date, value, 'month')
|
|
108
112
|
}
|
|
109
113
|
endOfRange={isEnd && !isRangeValid}
|
|
110
114
|
highlighted={highlighted && !isRangeValid}
|
|
111
115
|
startOfRange={isStart && !isRangeValid}
|
|
112
|
-
value={
|
|
116
|
+
value={dateValue.date()}
|
|
113
117
|
hoverDay={hoverDay}
|
|
114
118
|
/>
|
|
115
119
|
);
|
|
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DateRangePicker = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _lodash = require("lodash");
|
|
8
9
|
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
9
10
|
var _utils = require("../../utils");
|
|
10
11
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
12
|
+
var _dateRangePicker = require("../../utils/date-range-picker");
|
|
11
13
|
var _DateRangeWrapper = require("./DateRangeWrapper");
|
|
12
14
|
var _DateRangePickerModule = _interopRequireDefault(require("./DateRangePicker.module.css"));
|
|
13
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -27,33 +29,43 @@ const DateRangePicker = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
27
29
|
hideTimezone = false,
|
|
28
30
|
selectedDateRange = {}
|
|
29
31
|
} = _ref;
|
|
30
|
-
const
|
|
32
|
+
const localTimezone = _momentTimezone.default.tz.guess();
|
|
33
|
+
const {
|
|
34
|
+
timezone: inputTimezone = ''
|
|
35
|
+
} = selectedDateRange;
|
|
36
|
+
const validTimezone = (0, _lodash.isEmpty)(inputTimezone) ? localTimezone : inputTimezone;
|
|
37
|
+
const [today, setToday] = React.useState(() => (0, _dateRangePicker.getTodayInTimezone)(validTimezone));
|
|
31
38
|
const {
|
|
32
39
|
validMinDate,
|
|
33
40
|
validMaxDate,
|
|
34
|
-
validTimezone,
|
|
35
41
|
validDateRange
|
|
36
|
-
} = (0, _utils.getValidDates)(
|
|
42
|
+
} = React.useMemo(() => (0, _utils.getValidDates)({
|
|
43
|
+
selectedDateRange,
|
|
44
|
+
minDate,
|
|
45
|
+
maxDate,
|
|
46
|
+
today,
|
|
47
|
+
onError
|
|
48
|
+
}), [today]);
|
|
37
49
|
const {
|
|
38
50
|
startDate,
|
|
39
51
|
endDate
|
|
40
52
|
} = validDateRange;
|
|
41
53
|
const validRangeEndMonth = endDate ? (0, _utils.getMonthEndDate)(endDate) : (0, _utils.getMonthEndDate)(today);
|
|
42
|
-
const validRangeStartMonth = startDate && !(0,
|
|
54
|
+
const validRangeStartMonth = startDate && endDate && !(0, _dateRangePicker.isSame)(startDate, endDate, 'month') ? (0, _utils.getMonthEndDate)(startDate) : (0, _utils.getMonthEndDate)((0, _utils.getSubtractedDate)(validRangeEndMonth, 1, 'M'));
|
|
43
55
|
const [dateRange, setDateRange] = React.useState(validDateRange);
|
|
44
56
|
const [timezone, setTimezone] = React.useState(validTimezone);
|
|
45
57
|
const [hoverDay, setHoverDay] = React.useState('');
|
|
46
58
|
const [rangeStartMonth, setRangeStartMonth] = React.useState(validRangeStartMonth);
|
|
47
59
|
const [rangeEndMonth, setRangeEndMonth] = React.useState(validRangeEndMonth);
|
|
48
60
|
const setRangeStartMonthValidated = date => {
|
|
49
|
-
if ((0,
|
|
61
|
+
if ((0, _dateRangePicker.isSameOrAfter)(date, validMinDate) && (0, _dateRangePicker.isBefore)(date, rangeEndMonth)) {
|
|
50
62
|
setRangeStartMonth(date);
|
|
51
63
|
} else {
|
|
52
64
|
setRangeStartMonth((0, _utils.getMonthEndDate)(validMinDate));
|
|
53
65
|
}
|
|
54
66
|
};
|
|
55
67
|
const setRangeEndMonthValidated = date => {
|
|
56
|
-
if ((0,
|
|
68
|
+
if ((0, _dateRangePicker.isSameOrBefore)(date, validMaxDate) && (0, _dateRangePicker.isAfter)(date, rangeStartMonth)) {
|
|
57
69
|
setRangeEndMonth(date);
|
|
58
70
|
} else {
|
|
59
71
|
setRangeEndMonth((0, _utils.getMonthEndDate)(validMaxDate));
|
|
@@ -73,7 +85,7 @@ const DateRangePicker = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
73
85
|
startDate,
|
|
74
86
|
endDate
|
|
75
87
|
} = dateRange;
|
|
76
|
-
if (startDate && !endDate && (0,
|
|
88
|
+
if (startDate && !endDate && (0, _dateRangePicker.isSameOrAfter)(day, startDate)) {
|
|
77
89
|
setDateRange({
|
|
78
90
|
startDate,
|
|
79
91
|
endDate: day
|
|
@@ -90,13 +102,17 @@ const DateRangePicker = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
90
102
|
startDate,
|
|
91
103
|
endDate
|
|
92
104
|
} = dateRange;
|
|
93
|
-
return Boolean(startDate && !endDate && hoverDay && (0,
|
|
105
|
+
return Boolean(startDate && !endDate && hoverDay && (0, _dateRangePicker.isAfter)(hoverDay, startDate) && (0, _dateRangePicker.isBetween)(day, startDate, hoverDay));
|
|
94
106
|
};
|
|
95
107
|
const handlers = {
|
|
96
108
|
onDayClick,
|
|
97
109
|
onDayHover: setHoverDay,
|
|
98
110
|
onMonthNavigate
|
|
99
111
|
};
|
|
112
|
+
const handleTimeZone = newTimezone => {
|
|
113
|
+
setToday((0, _dateRangePicker.getTodayInTimezone)(newTimezone));
|
|
114
|
+
setTimezone(newTimezone);
|
|
115
|
+
};
|
|
100
116
|
return /*#__PURE__*/React.createElement(_DateRangeWrapper.DateRangeWrapper, {
|
|
101
117
|
ref: ref,
|
|
102
118
|
minDate: validMinDate,
|
|
@@ -107,14 +123,15 @@ const DateRangePicker = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
107
123
|
onCancel: onCancel,
|
|
108
124
|
timezone: timezone,
|
|
109
125
|
dateRange: dateRange,
|
|
110
|
-
setTimezone:
|
|
126
|
+
setTimezone: handleTimeZone,
|
|
111
127
|
rangeStartMonth: rangeStartMonth,
|
|
112
128
|
rangeEndMonth: rangeEndMonth,
|
|
113
129
|
inHoverRange: inHoverRange,
|
|
114
130
|
setRangeStartMonth: setRangeStartMonthValidated,
|
|
115
131
|
setRangeEndMonth: setRangeEndMonthValidated,
|
|
116
132
|
hideTimezone: hideTimezone,
|
|
117
|
-
cardWrapperClass: (0, _classify.default)(_DateRangePickerModule.default.container, classNames?.wrapper)
|
|
133
|
+
cardWrapperClass: (0, _classify.default)(_DateRangePickerModule.default.container, classNames?.wrapper),
|
|
134
|
+
today: today
|
|
118
135
|
});
|
|
119
136
|
});
|
|
120
137
|
exports.DateRangePicker = DateRangePicker;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import {isEmpty} from 'lodash';
|
|
4
5
|
// $FlowFixMe[untyped-import]
|
|
5
6
|
import moment from 'moment-timezone';
|
|
6
7
|
|
|
@@ -10,7 +11,6 @@ import type {
|
|
|
10
11
|
DateRangeWithTimezone,
|
|
11
12
|
} from '../../types';
|
|
12
13
|
import {
|
|
13
|
-
formatIsoDate,
|
|
14
14
|
getAddedDate,
|
|
15
15
|
getMonthEndDate,
|
|
16
16
|
getSubtractedDate,
|
|
@@ -19,6 +19,15 @@ import {
|
|
|
19
19
|
NAVIGATION_ACTION,
|
|
20
20
|
} from '../../utils';
|
|
21
21
|
import classify from '../../utils/classify';
|
|
22
|
+
import {
|
|
23
|
+
getTodayInTimezone,
|
|
24
|
+
isAfter,
|
|
25
|
+
isBefore,
|
|
26
|
+
isBetween,
|
|
27
|
+
isSame,
|
|
28
|
+
isSameOrAfter,
|
|
29
|
+
isSameOrBefore,
|
|
30
|
+
} from '../../utils/date-range-picker';
|
|
22
31
|
|
|
23
32
|
import {DateRangeWrapper} from './DateRangeWrapper';
|
|
24
33
|
|
|
@@ -55,17 +64,35 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
55
64
|
}: DateRangePickerProps,
|
|
56
65
|
ref,
|
|
57
66
|
): React.Node => {
|
|
58
|
-
const
|
|
67
|
+
const localTimezone = moment.tz.guess();
|
|
68
|
+
const {timezone: inputTimezone = ''} = selectedDateRange;
|
|
69
|
+
|
|
70
|
+
const validTimezone = isEmpty(inputTimezone)
|
|
71
|
+
? localTimezone
|
|
72
|
+
: inputTimezone;
|
|
59
73
|
|
|
60
|
-
const
|
|
61
|
-
|
|
74
|
+
const [today, setToday] = React.useState(() =>
|
|
75
|
+
getTodayInTimezone(validTimezone),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const {validMinDate, validMaxDate, validDateRange} = React.useMemo(
|
|
79
|
+
() =>
|
|
80
|
+
getValidDates({
|
|
81
|
+
selectedDateRange,
|
|
82
|
+
minDate,
|
|
83
|
+
maxDate,
|
|
84
|
+
today,
|
|
85
|
+
onError,
|
|
86
|
+
}),
|
|
87
|
+
[today],
|
|
88
|
+
);
|
|
62
89
|
|
|
63
90
|
const {startDate, endDate} = validDateRange;
|
|
64
91
|
const validRangeEndMonth = endDate
|
|
65
92
|
? getMonthEndDate(endDate)
|
|
66
93
|
: getMonthEndDate(today);
|
|
67
94
|
const validRangeStartMonth =
|
|
68
|
-
startDate && !
|
|
95
|
+
startDate && endDate && !isSame(startDate, endDate, 'month')
|
|
69
96
|
? getMonthEndDate(startDate)
|
|
70
97
|
: getMonthEndDate(getSubtractedDate(validRangeEndMonth, 1, 'M'));
|
|
71
98
|
|
|
@@ -78,20 +105,16 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
78
105
|
React.useState<string>(validRangeEndMonth);
|
|
79
106
|
|
|
80
107
|
const setRangeStartMonthValidated = (date: string) => {
|
|
81
|
-
if (
|
|
82
|
-
moment(date).isSameOrAfter(validMinDate) &&
|
|
83
|
-
moment(date).isBefore(rangeEndMonth)
|
|
84
|
-
) {
|
|
108
|
+
if (isSameOrAfter(date, validMinDate) && isBefore(date, rangeEndMonth)) {
|
|
85
109
|
setRangeStartMonth(date);
|
|
86
110
|
} else {
|
|
87
111
|
setRangeStartMonth(getMonthEndDate(validMinDate));
|
|
88
112
|
}
|
|
89
113
|
};
|
|
90
|
-
|
|
91
114
|
const setRangeEndMonthValidated = (date: string) => {
|
|
92
115
|
if (
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
isSameOrBefore(date, validMaxDate) &&
|
|
117
|
+
isAfter(date, rangeStartMonth)
|
|
95
118
|
) {
|
|
96
119
|
setRangeEndMonth(date);
|
|
97
120
|
} else {
|
|
@@ -122,7 +145,7 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
122
145
|
|
|
123
146
|
const onDayClick = (day: string) => {
|
|
124
147
|
const {startDate, endDate} = dateRange;
|
|
125
|
-
if (startDate && !endDate &&
|
|
148
|
+
if (startDate && !endDate && isSameOrAfter(day, startDate)) {
|
|
126
149
|
setDateRange({startDate, endDate: day});
|
|
127
150
|
} else {
|
|
128
151
|
setDateRange({startDate: day});
|
|
@@ -136,13 +159,8 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
136
159
|
startDate &&
|
|
137
160
|
!endDate &&
|
|
138
161
|
hoverDay &&
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
moment(startDate),
|
|
142
|
-
moment(hoverDay),
|
|
143
|
-
null,
|
|
144
|
-
'[]',
|
|
145
|
-
),
|
|
162
|
+
isAfter(hoverDay, startDate) &&
|
|
163
|
+
isBetween(day, startDate, hoverDay),
|
|
146
164
|
);
|
|
147
165
|
};
|
|
148
166
|
|
|
@@ -152,6 +170,11 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
152
170
|
onMonthNavigate,
|
|
153
171
|
};
|
|
154
172
|
|
|
173
|
+
const handleTimeZone = (newTimezone) => {
|
|
174
|
+
setToday(getTodayInTimezone(newTimezone));
|
|
175
|
+
setTimezone(newTimezone);
|
|
176
|
+
};
|
|
177
|
+
|
|
155
178
|
return (
|
|
156
179
|
<DateRangeWrapper
|
|
157
180
|
ref={ref}
|
|
@@ -163,7 +186,7 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
163
186
|
onCancel={onCancel}
|
|
164
187
|
timezone={timezone}
|
|
165
188
|
dateRange={dateRange}
|
|
166
|
-
setTimezone={
|
|
189
|
+
setTimezone={handleTimeZone}
|
|
167
190
|
rangeStartMonth={rangeStartMonth}
|
|
168
191
|
rangeEndMonth={rangeEndMonth}
|
|
169
192
|
inHoverRange={inHoverRange}
|
|
@@ -171,6 +194,7 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
171
194
|
setRangeEndMonth={setRangeEndMonthValidated}
|
|
172
195
|
hideTimezone={hideTimezone}
|
|
173
196
|
cardWrapperClass={classify(css.container, classNames?.wrapper)}
|
|
197
|
+
today={today}
|
|
174
198
|
/>
|
|
175
199
|
);
|
|
176
200
|
},
|
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DateRangeWrapper = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
9
9
|
var _utils = require("../../utils");
|
|
10
10
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
11
|
+
var _dateRangePicker = require("../../utils/date-range-picker");
|
|
11
12
|
var _Button = require("../Button");
|
|
12
13
|
var _Card = require("../Card");
|
|
13
14
|
var _Dropdown = require("../Dropdown");
|
|
@@ -56,31 +57,31 @@ const CalendarHeader = _ref => {
|
|
|
56
57
|
className: (0, _classify.default)(_DateRangeWrapperModule.default.headerIcon, {
|
|
57
58
|
[_DateRangeWrapperModule.default.disabledIcon]: prevDisabled
|
|
58
59
|
}),
|
|
59
|
-
onClick: onClickPrevious,
|
|
60
|
+
onClick: () => !prevDisabled && onClickPrevious(),
|
|
60
61
|
color: prevDisabled ? 'disabled' : 'secondary'
|
|
61
62
|
}), /*#__PURE__*/React.createElement(_Dropdown.Dropdown, {
|
|
62
63
|
size: "small",
|
|
63
|
-
disabled: !availableMonths.length || (0,
|
|
64
|
+
disabled: !availableMonths.length || (0, _dateRangePicker.isAfter)(minDate, maxDate),
|
|
64
65
|
menu: {
|
|
65
|
-
selectedKeys: [
|
|
66
|
+
selectedKeys: [_moment.default.utc(date).month().toString()],
|
|
66
67
|
options: availableMonths
|
|
67
68
|
},
|
|
68
69
|
onChange: event => {
|
|
69
|
-
setMonth((0, _utils.getMonthEndDate)(
|
|
70
|
+
setMonth((0, _utils.getMonthEndDate)(_moment.default.utc(date).set('M', event.key)));
|
|
70
71
|
},
|
|
71
|
-
dropdownInputText: _utils.MONTHS[
|
|
72
|
+
dropdownInputText: _utils.MONTHS[_moment.default.utc(date).month()].label,
|
|
72
73
|
scrollMenuToBottom: true
|
|
73
74
|
}), /*#__PURE__*/React.createElement(_Dropdown.Dropdown, {
|
|
74
|
-
disabled: !availableYears.length || (0,
|
|
75
|
+
disabled: !availableYears.length || (0, _dateRangePicker.isAfter)(minDate, maxDate),
|
|
75
76
|
menu: {
|
|
76
|
-
selectedKeys: [
|
|
77
|
+
selectedKeys: [_moment.default.utc(date).year().toString()],
|
|
77
78
|
options: availableYears
|
|
78
79
|
},
|
|
79
80
|
size: "small",
|
|
80
81
|
onChange: event => {
|
|
81
|
-
setMonth((0, _utils.getMonthEndDate)(
|
|
82
|
+
setMonth((0, _utils.getMonthEndDate)(_moment.default.utc(date).set('y', event.key)));
|
|
82
83
|
},
|
|
83
|
-
dropdownInputText:
|
|
84
|
+
dropdownInputText: _moment.default.utc(date).year(),
|
|
84
85
|
scrollMenuToBottom: true
|
|
85
86
|
}), /*#__PURE__*/React.createElement(_Icon.ClickableIcon, {
|
|
86
87
|
size: "small",
|
|
@@ -89,7 +90,7 @@ const CalendarHeader = _ref => {
|
|
|
89
90
|
className: (0, _classify.default)(_DateRangeWrapperModule.default.headerIcon, {
|
|
90
91
|
[_DateRangeWrapperModule.default.disabledIcon]: nextDisabled
|
|
91
92
|
}),
|
|
92
|
-
onClick: onClickNext,
|
|
93
|
+
onClick: () => !nextDisabled && onClickNext(),
|
|
93
94
|
color: nextDisabled ? 'disabled' : 'secondary'
|
|
94
95
|
}));
|
|
95
96
|
};
|
|
@@ -110,16 +111,17 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
110
111
|
setRangeStartMonth,
|
|
111
112
|
setRangeEndMonth,
|
|
112
113
|
cardWrapperClass,
|
|
113
|
-
hideTimezone
|
|
114
|
+
hideTimezone,
|
|
115
|
+
today
|
|
114
116
|
} = _ref2;
|
|
115
|
-
const canNavigateCloser =
|
|
117
|
+
const canNavigateCloser = _moment.default.utc(rangeStartMonth).year() !== _moment.default.utc(rangeEndMonth).year() || Math.abs(_moment.default.utc(rangeStartMonth).month() - _moment.default.utc(rangeEndMonth).month()) > 1;
|
|
116
118
|
const handleApplyClick = () => {
|
|
117
119
|
const {
|
|
118
120
|
startDate,
|
|
119
121
|
endDate
|
|
120
122
|
} = dateRange;
|
|
121
|
-
const startDateUTC = startDate && (0,
|
|
122
|
-
const endDateUTC = endDate && (0,
|
|
123
|
+
const startDateUTC = startDate && (0, _dateRangePicker.addTimezoneStartOfDay)(startDate, timezone);
|
|
124
|
+
const endDateUTC = endDate && (0, _dateRangePicker.addTimezoneEndOfDay)(endDate, timezone);
|
|
123
125
|
onApply({
|
|
124
126
|
startDate,
|
|
125
127
|
endDate,
|
|
@@ -137,7 +139,8 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
137
139
|
hoverDay,
|
|
138
140
|
dateRange,
|
|
139
141
|
minDate,
|
|
140
|
-
maxDate
|
|
142
|
+
maxDate,
|
|
143
|
+
today
|
|
141
144
|
};
|
|
142
145
|
return /*#__PURE__*/React.createElement(_FocusManager.FocusManager, null, /*#__PURE__*/React.createElement(_Card.Card, {
|
|
143
146
|
classNames: {
|
|
@@ -153,7 +156,7 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
153
156
|
date: rangeStartMonth,
|
|
154
157
|
setMonth: setRangeStartMonth,
|
|
155
158
|
nextDisabled: !canNavigateCloser,
|
|
156
|
-
prevDisabled: (0,
|
|
159
|
+
prevDisabled: (0, _dateRangePicker.isSameOrBefore)(rangeStartMonth, minDate, 'month'),
|
|
157
160
|
minDate: minDate,
|
|
158
161
|
maxDate: maxDate,
|
|
159
162
|
onClickNext: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_START, _utils.NAVIGATION_ACTION.NEXT),
|
|
@@ -164,7 +167,7 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
164
167
|
rangeEndMonth: rangeEndMonth,
|
|
165
168
|
date: rangeEndMonth,
|
|
166
169
|
setMonth: setRangeEndMonth,
|
|
167
|
-
nextDisabled: (0,
|
|
170
|
+
nextDisabled: (0, _dateRangePicker.isSameOrAfter)(rangeEndMonth, maxDate, 'month'),
|
|
168
171
|
prevDisabled: !canNavigateCloser,
|
|
169
172
|
minDate: minDate,
|
|
170
173
|
maxDate: maxDate,
|
|
@@ -184,7 +187,7 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
184
187
|
className: _DateRangeWrapperModule.default.timezoneDropdownContainer
|
|
185
188
|
}, !hideTimezone && /*#__PURE__*/React.createElement(_Dropdown.SimpleDropdown, {
|
|
186
189
|
options: (0, _utils.getTimezones)(),
|
|
187
|
-
disabled: (0,
|
|
190
|
+
disabled: (0, _dateRangePicker.isAfter)(minDate, maxDate),
|
|
188
191
|
classNames: {
|
|
189
192
|
box: _DateRangeWrapperModule.default.timezoneDropdown
|
|
190
193
|
},
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
// $FlowFixMe[untyped-import]
|
|
5
|
-
import moment from 'moment
|
|
5
|
+
import moment from 'moment';
|
|
6
6
|
|
|
7
7
|
import type {DateRange, DateRangeWithTimezone} from '../../types';
|
|
8
8
|
import {
|
|
9
|
-
addTimezone,
|
|
10
9
|
generateAvailableYears,
|
|
11
10
|
getAvailableMonths,
|
|
12
11
|
getMonthEndDate,
|
|
@@ -16,6 +15,13 @@ import {
|
|
|
16
15
|
NAVIGATION_ACTION,
|
|
17
16
|
} from '../../utils';
|
|
18
17
|
import classify from '../../utils/classify';
|
|
18
|
+
import {
|
|
19
|
+
addTimezoneEndOfDay,
|
|
20
|
+
addTimezoneStartOfDay,
|
|
21
|
+
isAfter,
|
|
22
|
+
isSameOrAfter,
|
|
23
|
+
isSameOrBefore,
|
|
24
|
+
} from '../../utils/date-range-picker';
|
|
19
25
|
import {Button} from '../Button';
|
|
20
26
|
import {
|
|
21
27
|
Card,
|
|
@@ -72,6 +78,7 @@ type DateRangeWrapperProps = {
|
|
|
72
78
|
action: $Values<typeof NAVIGATION_ACTION>,
|
|
73
79
|
) => void,
|
|
74
80
|
},
|
|
81
|
+
today: string,
|
|
75
82
|
};
|
|
76
83
|
|
|
77
84
|
const CalendarHeader = ({
|
|
@@ -111,33 +118,33 @@ const CalendarHeader = ({
|
|
|
111
118
|
className={classify(css.headerIcon, {
|
|
112
119
|
[css.disabledIcon]: prevDisabled,
|
|
113
120
|
})}
|
|
114
|
-
onClick={onClickPrevious}
|
|
121
|
+
onClick={() => !prevDisabled && onClickPrevious()}
|
|
115
122
|
color={prevDisabled ? 'disabled' : 'secondary'}
|
|
116
123
|
/>
|
|
117
124
|
<Dropdown
|
|
118
125
|
size="small"
|
|
119
|
-
disabled={!availableMonths.length ||
|
|
126
|
+
disabled={!availableMonths.length || isAfter(minDate, maxDate)}
|
|
120
127
|
menu={{
|
|
121
|
-
selectedKeys: [moment(date).month().toString()],
|
|
128
|
+
selectedKeys: [moment.utc(date).month().toString()],
|
|
122
129
|
options: availableMonths,
|
|
123
130
|
}}
|
|
124
131
|
onChange={(event) => {
|
|
125
|
-
setMonth(getMonthEndDate(moment(date).set('M', event.key)));
|
|
132
|
+
setMonth(getMonthEndDate(moment.utc(date).set('M', event.key)));
|
|
126
133
|
}}
|
|
127
|
-
dropdownInputText={MONTHS[moment(date).month()].label}
|
|
134
|
+
dropdownInputText={MONTHS[moment.utc(date).month()].label}
|
|
128
135
|
scrollMenuToBottom
|
|
129
136
|
/>
|
|
130
137
|
<Dropdown
|
|
131
|
-
disabled={!availableYears.length ||
|
|
138
|
+
disabled={!availableYears.length || isAfter(minDate, maxDate)}
|
|
132
139
|
menu={{
|
|
133
|
-
selectedKeys: [moment(date).year().toString()],
|
|
140
|
+
selectedKeys: [moment.utc(date).year().toString()],
|
|
134
141
|
options: availableYears,
|
|
135
142
|
}}
|
|
136
143
|
size="small"
|
|
137
144
|
onChange={(event) => {
|
|
138
|
-
setMonth(getMonthEndDate(moment(date).set('y', event.key)));
|
|
145
|
+
setMonth(getMonthEndDate(moment.utc(date).set('y', event.key)));
|
|
139
146
|
}}
|
|
140
|
-
dropdownInputText={moment(date).year()}
|
|
147
|
+
dropdownInputText={moment.utc(date).year()}
|
|
141
148
|
scrollMenuToBottom
|
|
142
149
|
/>
|
|
143
150
|
<ClickableIcon
|
|
@@ -147,7 +154,7 @@ const CalendarHeader = ({
|
|
|
147
154
|
className={classify(css.headerIcon, {
|
|
148
155
|
[css.disabledIcon]: nextDisabled,
|
|
149
156
|
})}
|
|
150
|
-
onClick={onClickNext}
|
|
157
|
+
onClick={() => !nextDisabled && onClickNext()}
|
|
151
158
|
color={nextDisabled ? 'disabled' : 'secondary'}
|
|
152
159
|
/>
|
|
153
160
|
</div>
|
|
@@ -176,19 +183,21 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
176
183
|
setRangeEndMonth,
|
|
177
184
|
cardWrapperClass,
|
|
178
185
|
hideTimezone,
|
|
186
|
+
today,
|
|
179
187
|
}: DateRangeWrapperProps,
|
|
180
188
|
ref,
|
|
181
189
|
): React.Node => {
|
|
182
190
|
const canNavigateCloser =
|
|
183
|
-
moment(rangeStartMonth).year() !== moment(rangeEndMonth).year() ||
|
|
191
|
+
moment.utc(rangeStartMonth).year() !== moment.utc(rangeEndMonth).year() ||
|
|
184
192
|
Math.abs(
|
|
185
|
-
moment(rangeStartMonth).month() - moment(rangeEndMonth).month(),
|
|
193
|
+
moment.utc(rangeStartMonth).month() - moment.utc(rangeEndMonth).month(),
|
|
186
194
|
) > 1;
|
|
187
195
|
|
|
188
196
|
const handleApplyClick = () => {
|
|
189
197
|
const {startDate, endDate} = dateRange;
|
|
190
|
-
const startDateUTC =
|
|
191
|
-
|
|
198
|
+
const startDateUTC =
|
|
199
|
+
startDate && addTimezoneStartOfDay(startDate, timezone);
|
|
200
|
+
const endDateUTC = endDate && addTimezoneEndOfDay(endDate, timezone);
|
|
192
201
|
onApply({
|
|
193
202
|
startDate,
|
|
194
203
|
endDate,
|
|
@@ -207,6 +216,7 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
207
216
|
dateRange,
|
|
208
217
|
minDate,
|
|
209
218
|
maxDate,
|
|
219
|
+
today,
|
|
210
220
|
};
|
|
211
221
|
|
|
212
222
|
return (
|
|
@@ -225,10 +235,7 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
225
235
|
date={rangeStartMonth}
|
|
226
236
|
setMonth={setRangeStartMonth}
|
|
227
237
|
nextDisabled={!canNavigateCloser}
|
|
228
|
-
prevDisabled={
|
|
229
|
-
minDate,
|
|
230
|
-
'M',
|
|
231
|
-
)}
|
|
238
|
+
prevDisabled={isSameOrBefore(rangeStartMonth, minDate, 'month')}
|
|
232
239
|
minDate={minDate}
|
|
233
240
|
maxDate={maxDate}
|
|
234
241
|
onClickNext={() =>
|
|
@@ -250,7 +257,7 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
250
257
|
rangeEndMonth={rangeEndMonth}
|
|
251
258
|
date={rangeEndMonth}
|
|
252
259
|
setMonth={setRangeEndMonth}
|
|
253
|
-
nextDisabled={
|
|
260
|
+
nextDisabled={isSameOrAfter(rangeEndMonth, maxDate, 'month')}
|
|
254
261
|
prevDisabled={!canNavigateCloser}
|
|
255
262
|
minDate={minDate}
|
|
256
263
|
maxDate={maxDate}
|
|
@@ -280,7 +287,7 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
280
287
|
{!hideTimezone && (
|
|
281
288
|
<SimpleDropdown
|
|
282
289
|
options={getTimezones()}
|
|
283
|
-
disabled={
|
|
290
|
+
disabled={isAfter(minDate, maxDate)}
|
|
284
291
|
classNames={{
|
|
285
292
|
box: css.timezoneDropdown,
|
|
286
293
|
}}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Day = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
9
9
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
10
10
|
var _Button = require("../Button");
|
|
11
11
|
var _Text = require("../Text");
|
|
@@ -54,9 +54,9 @@ const Day = _ref => {
|
|
|
54
54
|
type: "ghost",
|
|
55
55
|
color: getTextColor(disabled, filled),
|
|
56
56
|
className: (0, _classify.default)(_DayModule.default.calendarRowItem, {
|
|
57
|
-
[_DayModule.default.calendarRowItemHover]: !disabled &&
|
|
57
|
+
[_DayModule.default.calendarRowItemHover]: !disabled && _moment.default.utc(date).isSame(hoverDay),
|
|
58
58
|
[_DayModule.default.calendarRowItemFilled]: !disabled && filled,
|
|
59
|
-
[_DayModule.default.calendarRowItemOutlined]:
|
|
59
|
+
[_DayModule.default.calendarRowItemOutlined]: outlined
|
|
60
60
|
})
|
|
61
61
|
}, value));
|
|
62
62
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
// $FlowFixMe[untyped-import]
|
|
4
|
-
import moment from 'moment
|
|
4
|
+
import moment from 'moment';
|
|
5
5
|
|
|
6
6
|
// $FlowFixMe[untyped-import]
|
|
7
7
|
import classify from '../../utils/classify';
|
|
@@ -63,9 +63,10 @@ export const Day = ({
|
|
|
63
63
|
type="ghost"
|
|
64
64
|
color={getTextColor(disabled, filled)}
|
|
65
65
|
className={classify(css.calendarRowItem, {
|
|
66
|
-
[css.calendarRowItemHover]:
|
|
66
|
+
[css.calendarRowItemHover]:
|
|
67
|
+
!disabled && moment.utc(date).isSame(hoverDay),
|
|
67
68
|
[css.calendarRowItemFilled]: !disabled && filled,
|
|
68
|
-
[css.calendarRowItemOutlined]:
|
|
69
|
+
[css.calendarRowItemOutlined]: outlined,
|
|
69
70
|
})}
|
|
70
71
|
>
|
|
71
72
|
{value}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.wrangleMoment = exports.isStartOfRange = exports.isStartDateEndDateSame = exports.isEndOfRange = exports.inDateRange = exports.getValidDates = exports.getTimezones = exports.getSubtractedDate = exports.getMonthEndDate = exports.getDaysInMonth = exports.getAvailableMonths = exports.getAddedDate = exports.generateAvailableYears = exports.formatIsoDate = exports.checkRangeValidity = exports.
|
|
6
|
+
exports.wrangleMoment = exports.isValid = exports.isStartOfRange = exports.isStartDateEndDateSame = exports.isSameOrBefore = exports.isSameOrAfter = exports.isSame = exports.isEndOfRange = exports.isBetween = exports.isBefore = exports.isAfter = exports.inDateRange = exports.getValidDates = exports.getTimezones = exports.getSubtractedDate = exports.getMonthEndDate = exports.getDaysInMonth = exports.getAvailableMonths = exports.getAddedDate = exports.generateAvailableYears = exports.formatIsoDate = exports.checkRangeValidity = exports.WEEKDAYS = exports.NAVIGATION_ACTION = exports.MONTHS = exports.MARKERS = exports.DATE_RANGE_PICKER_ERRORS = void 0;
|
|
7
7
|
var _parseISO = _interopRequireDefault(require("date-fns/parseISO"));
|
|
8
8
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
9
9
|
var _lodash = require("lodash");
|
|
10
|
-
var
|
|
10
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
11
11
|
var _timezones = require("./timezones");
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
@@ -85,9 +85,9 @@ const DATE_RANGE_PICKER_ERRORS = Object.freeze({
|
|
|
85
85
|
});
|
|
86
86
|
exports.DATE_RANGE_PICKER_ERRORS = DATE_RANGE_PICKER_ERRORS;
|
|
87
87
|
const checkRangeValidity = (rangeStart, rangeEnd, errorBody, onError) => {
|
|
88
|
-
const isRangeStartValid = (
|
|
89
|
-
const isRangeEndValid = isRangeStartValid && (
|
|
90
|
-
const isRangeValid = isRangeEndValid && (
|
|
88
|
+
const isRangeStartValid = isValid(rangeStart);
|
|
89
|
+
const isRangeEndValid = isRangeStartValid && isValid(rangeEnd);
|
|
90
|
+
const isRangeValid = isRangeEndValid && isSameOrBefore(rangeStart, rangeEnd);
|
|
91
91
|
(0, _invariant.default)(isRangeValid, JSON.stringify(errorBody));
|
|
92
92
|
if (!isRangeValid) {
|
|
93
93
|
onError?.(errorBody);
|
|
@@ -101,23 +101,23 @@ const wrangleMoment = date => {
|
|
|
101
101
|
} else if (!date) {
|
|
102
102
|
return new Date();
|
|
103
103
|
}
|
|
104
|
-
return date instanceof
|
|
104
|
+
return date instanceof _moment.default ? date.toDate() : (0, _parseISO.default)(date);
|
|
105
105
|
};
|
|
106
106
|
exports.wrangleMoment = wrangleMoment;
|
|
107
|
-
const formatIsoDate = date =>
|
|
107
|
+
const formatIsoDate = date => _moment.default.utc(date).format('YYYY-MM-DD');
|
|
108
108
|
exports.formatIsoDate = formatIsoDate;
|
|
109
109
|
const isStartOfRange = (_ref, date) => {
|
|
110
110
|
let {
|
|
111
111
|
startDate
|
|
112
112
|
} = _ref;
|
|
113
|
-
return Boolean(startDate) &&
|
|
113
|
+
return Boolean(startDate) && _moment.default.utc(date).isSame(_moment.default.utc(startDate), 'd');
|
|
114
114
|
};
|
|
115
115
|
exports.isStartOfRange = isStartOfRange;
|
|
116
116
|
const isEndOfRange = (_ref2, date) => {
|
|
117
117
|
let {
|
|
118
118
|
endDate
|
|
119
119
|
} = _ref2;
|
|
120
|
-
return Boolean(endDate) &&
|
|
120
|
+
return Boolean(endDate) && _moment.default.utc(date).isSame(_moment.default.utc(endDate), 'd');
|
|
121
121
|
};
|
|
122
122
|
exports.isEndOfRange = isEndOfRange;
|
|
123
123
|
const inDateRange = (_ref3, date) => {
|
|
@@ -126,10 +126,10 @@ const inDateRange = (_ref3, date) => {
|
|
|
126
126
|
endDate
|
|
127
127
|
} = _ref3;
|
|
128
128
|
if (startDate && endDate) {
|
|
129
|
-
const momentDay =
|
|
130
|
-
const momentStartDate =
|
|
131
|
-
const momentEndDate =
|
|
132
|
-
return
|
|
129
|
+
const momentDay = _moment.default.utc(date);
|
|
130
|
+
const momentStartDate = _moment.default.utc(startDate);
|
|
131
|
+
const momentEndDate = _moment.default.utc(endDate);
|
|
132
|
+
return isBetween(momentDay, momentStartDate, momentEndDate);
|
|
133
133
|
}
|
|
134
134
|
return false;
|
|
135
135
|
};
|
|
@@ -140,21 +140,21 @@ const isStartDateEndDateSame = _ref4 => {
|
|
|
140
140
|
endDate
|
|
141
141
|
} = _ref4;
|
|
142
142
|
if (startDate && endDate) {
|
|
143
|
-
return
|
|
143
|
+
return _moment.default.utc(startDate).isSame(_moment.default.utc(endDate), 'd');
|
|
144
144
|
}
|
|
145
145
|
return false;
|
|
146
146
|
};
|
|
147
147
|
exports.isStartDateEndDateSame = isStartDateEndDateSame;
|
|
148
148
|
const getMonthAndYear = date => {
|
|
149
|
-
const momentDate = date ?
|
|
149
|
+
const momentDate = date ? _moment.default.utc(date) : _moment.default.utc();
|
|
150
150
|
return [momentDate.month(), momentDate.year()];
|
|
151
151
|
};
|
|
152
152
|
const getDaysInMonth = date => {
|
|
153
|
-
const startWeek =
|
|
154
|
-
const endWeek =
|
|
153
|
+
const startWeek = _moment.default.utc(date).startOf('month').startOf('week');
|
|
154
|
+
const endWeek = _moment.default.utc(date).endOf('month').endOf('week');
|
|
155
155
|
const days = [],
|
|
156
156
|
current = startWeek;
|
|
157
|
-
while (
|
|
157
|
+
while (isBefore(current, endWeek)) {
|
|
158
158
|
days.push(current.clone().format('YYYY-MM-DD'));
|
|
159
159
|
current.add(1, 'd');
|
|
160
160
|
}
|
|
@@ -164,7 +164,7 @@ const getDaysInMonth = date => {
|
|
|
164
164
|
if (daysInChunks.length === 5) {
|
|
165
165
|
const nextWeek = getAddedDate(endWeek, WEEKDAYS.length, 'd');
|
|
166
166
|
const extraDays = [];
|
|
167
|
-
while (
|
|
167
|
+
while (isSameOrBefore(current, nextWeek)) {
|
|
168
168
|
extraDays.push(current.clone().format('YYYY-MM-DD'));
|
|
169
169
|
current.add(1, 'd');
|
|
170
170
|
}
|
|
@@ -173,14 +173,12 @@ const getDaysInMonth = date => {
|
|
|
173
173
|
return daysInChunks;
|
|
174
174
|
};
|
|
175
175
|
exports.getDaysInMonth = getDaysInMonth;
|
|
176
|
-
const getAddedDate = (date, addCount, timeUnit) => formatIsoDate(
|
|
176
|
+
const getAddedDate = (date, addCount, timeUnit) => formatIsoDate(_moment.default.utc(date).add(addCount, timeUnit));
|
|
177
177
|
exports.getAddedDate = getAddedDate;
|
|
178
|
-
const getSubtractedDate = (date, subtractCount, timeUnit) => formatIsoDate(
|
|
178
|
+
const getSubtractedDate = (date, subtractCount, timeUnit) => formatIsoDate(_moment.default.utc(date).subtract(subtractCount, timeUnit));
|
|
179
179
|
exports.getSubtractedDate = getSubtractedDate;
|
|
180
|
-
const getMonthEndDate = date => formatIsoDate(
|
|
180
|
+
const getMonthEndDate = date => formatIsoDate(_moment.default.utc(date).endOf('M'));
|
|
181
181
|
exports.getMonthEndDate = getMonthEndDate;
|
|
182
|
-
const addTimezone = (date, timezone) => _momentTimezone.default.tz(date, timezone).startOf('d').utc().toISOString();
|
|
183
|
-
exports.addTimezone = addTimezone;
|
|
184
182
|
const getTimezones = () => Object.keys(_timezones.TIMEZONES).reduce((menuOptions, key) => {
|
|
185
183
|
menuOptions.push({
|
|
186
184
|
key,
|
|
@@ -197,10 +195,10 @@ const generateAvailableYears = _ref5 => {
|
|
|
197
195
|
rangeStartMonth,
|
|
198
196
|
rangeEndMonth
|
|
199
197
|
} = _ref5;
|
|
200
|
-
const rangeStartYear =
|
|
201
|
-
const rangeEndYear =
|
|
198
|
+
const rangeStartYear = _moment.default.utc(rangeStartMonth).year();
|
|
199
|
+
const rangeEndYear = _moment.default.utc(rangeEndMonth).year();
|
|
202
200
|
const isWithinRange = year => marker === MARKERS.DATE_RANGE_START ? year <= rangeEndYear : year >= rangeStartYear;
|
|
203
|
-
return (0, _lodash.range)(
|
|
201
|
+
return (0, _lodash.range)(_moment.default.utc(minDate).year(), _moment.default.utc(maxDate).year() + 1).filter(year => isWithinRange(year)).map(year => ({
|
|
204
202
|
key: year.toString(),
|
|
205
203
|
label: year.toString()
|
|
206
204
|
}));
|
|
@@ -242,15 +240,18 @@ const getAvailableMonths = _ref6 => {
|
|
|
242
240
|
});
|
|
243
241
|
};
|
|
244
242
|
exports.getAvailableMonths = getAvailableMonths;
|
|
245
|
-
const getValidDates =
|
|
246
|
-
|
|
247
|
-
|
|
243
|
+
const getValidDates = _ref7 => {
|
|
244
|
+
let {
|
|
245
|
+
selectedDateRange,
|
|
246
|
+
minDate,
|
|
247
|
+
maxDate,
|
|
248
|
+
today,
|
|
249
|
+
onError
|
|
250
|
+
} = _ref7;
|
|
248
251
|
const {
|
|
249
252
|
startDate,
|
|
250
|
-
endDate
|
|
251
|
-
timezone = ''
|
|
253
|
+
endDate
|
|
252
254
|
} = selectedDateRange;
|
|
253
|
-
const validTimezone = (0, _lodash.isEmpty)(timezone) ? localTimezone : timezone;
|
|
254
255
|
const validMaxDate = maxDate && !(0, _lodash.isEmpty)(maxDate) ? maxDate : today;
|
|
255
256
|
const validMinDate = minDate && !(0, _lodash.isEmpty)(minDate) ? minDate : getSubtractedDate(today, 8, 'y');
|
|
256
257
|
const isRangeValid = (min, max, errorMessage) => checkRangeValidity(min, max, errorMessage, onError);
|
|
@@ -262,7 +263,6 @@ const getValidDates = (selectedDateRange, minDate, maxDate, onError) => {
|
|
|
262
263
|
const isStartDateInvalid = isMinMaxRangeInvalid || (0, _lodash.isEmpty)(startDate) || !isRangeValid(validMinDate, startDate, DATE_RANGE_PICKER_ERRORS.START_DATE_EARLY);
|
|
263
264
|
if (isMinMaxRangeInvalid || isStartDateInvalid) {
|
|
264
265
|
return {
|
|
265
|
-
validTimezone,
|
|
266
266
|
validDateRange: {
|
|
267
267
|
startDate: null,
|
|
268
268
|
endDate: null
|
|
@@ -271,7 +271,6 @@ const getValidDates = (selectedDateRange, minDate, maxDate, onError) => {
|
|
|
271
271
|
validMaxDate
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
|
-
|
|
275
274
|
// if endDate is defined then it should be before maxDate
|
|
276
275
|
const isEndDateInvalid = (0, _lodash.isEmpty)(endDate) || !isRangeValid(endDate, validMaxDate, DATE_RANGE_PICKER_ERRORS.END_DATE_LATE);
|
|
277
276
|
|
|
@@ -279,7 +278,6 @@ const getValidDates = (selectedDateRange, minDate, maxDate, onError) => {
|
|
|
279
278
|
const isStartEndRangeInvalid = isEndDateInvalid || !isRangeValid(startDate, endDate, DATE_RANGE_PICKER_ERRORS.START_DATE_LATE);
|
|
280
279
|
if (isEndDateInvalid || isStartEndRangeInvalid) {
|
|
281
280
|
return {
|
|
282
|
-
validTimezone,
|
|
283
281
|
validDateRange: {
|
|
284
282
|
startDate,
|
|
285
283
|
endDate: null
|
|
@@ -289,7 +287,6 @@ const getValidDates = (selectedDateRange, minDate, maxDate, onError) => {
|
|
|
289
287
|
};
|
|
290
288
|
}
|
|
291
289
|
return {
|
|
292
|
-
validTimezone,
|
|
293
290
|
validDateRange: {
|
|
294
291
|
startDate: (0, _lodash.isEmpty)(startDate) ? null : startDate,
|
|
295
292
|
endDate: (0, _lodash.isEmpty)(endDate) ? null : endDate
|
|
@@ -298,4 +295,32 @@ const getValidDates = (selectedDateRange, minDate, maxDate, onError) => {
|
|
|
298
295
|
validMaxDate
|
|
299
296
|
};
|
|
300
297
|
};
|
|
301
|
-
|
|
298
|
+
|
|
299
|
+
// If date1 is same as date2 w.r.t the unit passed
|
|
300
|
+
exports.getValidDates = getValidDates;
|
|
301
|
+
const isSame = (date1, date2, unit) => _moment.default.utc(date1).isSame(_moment.default.utc(date2), unit);
|
|
302
|
+
|
|
303
|
+
// If date1 is before date2
|
|
304
|
+
exports.isSame = isSame;
|
|
305
|
+
const isBefore = (date1, date2) => _moment.default.utc(date1).isBefore(_moment.default.utc(date2));
|
|
306
|
+
|
|
307
|
+
// If date1 is after date2 w.r.t the unit passed
|
|
308
|
+
exports.isBefore = isBefore;
|
|
309
|
+
const isAfter = (date1, date2) => _moment.default.utc(date1).isAfter(_moment.default.utc(date2));
|
|
310
|
+
|
|
311
|
+
// If date1 is same or before date2 w.r.t the unit passed
|
|
312
|
+
exports.isAfter = isAfter;
|
|
313
|
+
const isSameOrBefore = (date1, date2, unit) => _moment.default.utc(date1).isSameOrBefore(_moment.default.utc(date2), unit);
|
|
314
|
+
|
|
315
|
+
// If date1 is same or after date2 w.r.t the unit passed
|
|
316
|
+
exports.isSameOrBefore = isSameOrBefore;
|
|
317
|
+
const isSameOrAfter = (date1, date2, unit) => _moment.default.utc(date1).isSameOrAfter(_moment.default.utc(date2), unit);
|
|
318
|
+
|
|
319
|
+
// If date is between startRange and endRange
|
|
320
|
+
exports.isSameOrAfter = isSameOrAfter;
|
|
321
|
+
const isBetween = (date, startRange, endRange) => _moment.default.utc(date).isBetween(_moment.default.utc(startRange), _moment.default.utc(endRange), null, '[]');
|
|
322
|
+
|
|
323
|
+
// If the date results in a date that exists in the calendar
|
|
324
|
+
exports.isBetween = isBetween;
|
|
325
|
+
const isValid = date => _moment.default.utc(date).isValid();
|
|
326
|
+
exports.isValid = isValid;
|
|
@@ -5,7 +5,7 @@ import parseISO from 'date-fns/parseISO';
|
|
|
5
5
|
import invariant from 'invariant';
|
|
6
6
|
import {chunk, isEmpty, range} from 'lodash';
|
|
7
7
|
// $FlowFixMe[untyped-import]
|
|
8
|
-
import moment from 'moment
|
|
8
|
+
import moment from 'moment';
|
|
9
9
|
import type {
|
|
10
10
|
DateRange,
|
|
11
11
|
DateRangePickerError,
|
|
@@ -67,10 +67,9 @@ export const checkRangeValidity = (
|
|
|
67
67
|
errorBody: DateRangePickerError,
|
|
68
68
|
onError?: (DateRangePickerError) => void,
|
|
69
69
|
): boolean => {
|
|
70
|
-
const isRangeStartValid =
|
|
71
|
-
const isRangeEndValid = isRangeStartValid &&
|
|
72
|
-
const isRangeValid =
|
|
73
|
-
isRangeEndValid && moment(rangeStart).isSameOrBefore(rangeEnd);
|
|
70
|
+
const isRangeStartValid = isValid(rangeStart);
|
|
71
|
+
const isRangeEndValid = isRangeStartValid && isValid(rangeEnd);
|
|
72
|
+
const isRangeValid = isRangeEndValid && isSameOrBefore(rangeStart, rangeEnd);
|
|
74
73
|
|
|
75
74
|
invariant(isRangeValid, JSON.stringify(errorBody));
|
|
76
75
|
if (!isRangeValid) {
|
|
@@ -90,23 +89,23 @@ export const wrangleMoment = (date?: string | Date): Date => {
|
|
|
90
89
|
};
|
|
91
90
|
|
|
92
91
|
export const formatIsoDate = (date?: string | Date): string =>
|
|
93
|
-
moment
|
|
92
|
+
moment.utc(date).format('YYYY-MM-DD');
|
|
94
93
|
|
|
95
94
|
export const isStartOfRange = ({startDate}: DateRange, date: string): boolean =>
|
|
96
|
-
Boolean(startDate) && moment(date).isSame(moment(startDate), 'd');
|
|
95
|
+
Boolean(startDate) && moment.utc(date).isSame(moment.utc(startDate), 'd');
|
|
97
96
|
|
|
98
97
|
export const isEndOfRange = ({endDate}: DateRange, date: string): boolean =>
|
|
99
|
-
Boolean(endDate) && moment(date).isSame(moment(endDate), 'd');
|
|
98
|
+
Boolean(endDate) && moment.utc(date).isSame(moment.utc(endDate), 'd');
|
|
100
99
|
|
|
101
100
|
export const inDateRange = (
|
|
102
101
|
{startDate, endDate}: DateRange,
|
|
103
102
|
date: string,
|
|
104
103
|
): boolean => {
|
|
105
104
|
if (startDate && endDate) {
|
|
106
|
-
const momentDay = moment(date);
|
|
107
|
-
const momentStartDate = moment(startDate);
|
|
108
|
-
const momentEndDate = moment(endDate);
|
|
109
|
-
return
|
|
105
|
+
const momentDay = moment.utc(date);
|
|
106
|
+
const momentStartDate = moment.utc(startDate);
|
|
107
|
+
const momentEndDate = moment.utc(endDate);
|
|
108
|
+
return isBetween(momentDay, momentStartDate, momentEndDate);
|
|
110
109
|
}
|
|
111
110
|
return false;
|
|
112
111
|
};
|
|
@@ -116,23 +115,23 @@ export const isStartDateEndDateSame = ({
|
|
|
116
115
|
endDate,
|
|
117
116
|
}: DateRange): boolean => {
|
|
118
117
|
if (startDate && endDate) {
|
|
119
|
-
return moment(startDate).isSame(moment(endDate), 'd');
|
|
118
|
+
return moment.utc(startDate).isSame(moment.utc(endDate), 'd');
|
|
120
119
|
}
|
|
121
120
|
return false;
|
|
122
121
|
};
|
|
123
122
|
|
|
124
123
|
const getMonthAndYear = (date) => {
|
|
125
|
-
const momentDate = date ? moment(date) : moment();
|
|
124
|
+
const momentDate = date ? moment.utc(date) : moment.utc();
|
|
126
125
|
return [momentDate.month(), momentDate.year()];
|
|
127
126
|
};
|
|
128
127
|
|
|
129
128
|
export const getDaysInMonth = (date: string): Array<Array<string>> => {
|
|
130
|
-
const startWeek = moment(date).startOf('month').startOf('week');
|
|
131
|
-
const endWeek = moment(date).endOf('month').endOf('week');
|
|
129
|
+
const startWeek = moment.utc(date).startOf('month').startOf('week');
|
|
130
|
+
const endWeek = moment.utc(date).endOf('month').endOf('week');
|
|
132
131
|
const days = [],
|
|
133
132
|
current = startWeek;
|
|
134
133
|
|
|
135
|
-
while (
|
|
134
|
+
while (isBefore(current, endWeek)) {
|
|
136
135
|
days.push(current.clone().format('YYYY-MM-DD'));
|
|
137
136
|
current.add(1, 'd');
|
|
138
137
|
}
|
|
@@ -142,7 +141,7 @@ export const getDaysInMonth = (date: string): Array<Array<string>> => {
|
|
|
142
141
|
if (daysInChunks.length === 5) {
|
|
143
142
|
const nextWeek = getAddedDate(endWeek, WEEKDAYS.length, 'd');
|
|
144
143
|
const extraDays = [];
|
|
145
|
-
while (
|
|
144
|
+
while (isSameOrBefore(current, nextWeek)) {
|
|
146
145
|
extraDays.push(current.clone().format('YYYY-MM-DD'));
|
|
147
146
|
current.add(1, 'd');
|
|
148
147
|
}
|
|
@@ -156,19 +155,16 @@ export const getAddedDate = (
|
|
|
156
155
|
date: string,
|
|
157
156
|
addCount: number,
|
|
158
157
|
timeUnit: TimeUnit,
|
|
159
|
-
): string => formatIsoDate(moment(date).add(addCount, timeUnit));
|
|
158
|
+
): string => formatIsoDate(moment.utc(date).add(addCount, timeUnit));
|
|
160
159
|
|
|
161
160
|
export const getSubtractedDate = (
|
|
162
161
|
date: string,
|
|
163
162
|
subtractCount: number,
|
|
164
163
|
timeUnit: TimeUnit,
|
|
165
|
-
): string => formatIsoDate(moment(date).subtract(subtractCount, timeUnit));
|
|
164
|
+
): string => formatIsoDate(moment.utc(date).subtract(subtractCount, timeUnit));
|
|
166
165
|
|
|
167
166
|
export const getMonthEndDate = (date: string): string =>
|
|
168
|
-
formatIsoDate(moment(date).endOf('M'));
|
|
169
|
-
|
|
170
|
-
export const addTimezone = (date: string, timezone: string): string =>
|
|
171
|
-
moment.tz(date, timezone).startOf('d').utc().toISOString();
|
|
167
|
+
formatIsoDate(moment.utc(date).endOf('M'));
|
|
172
168
|
|
|
173
169
|
export const getTimezones = (): Array<MenuOption> =>
|
|
174
170
|
Object.keys(TIMEZONES).reduce((menuOptions, key) => {
|
|
@@ -192,15 +188,15 @@ export const generateAvailableYears = ({
|
|
|
192
188
|
rangeStartMonth: string,
|
|
193
189
|
rangeEndMonth: string,
|
|
194
190
|
}): Array<MenuOption> => {
|
|
195
|
-
const rangeStartYear = moment(rangeStartMonth).year();
|
|
196
|
-
const rangeEndYear = moment(rangeEndMonth).year();
|
|
191
|
+
const rangeStartYear = moment.utc(rangeStartMonth).year();
|
|
192
|
+
const rangeEndYear = moment.utc(rangeEndMonth).year();
|
|
197
193
|
|
|
198
194
|
const isWithinRange = (year: number) =>
|
|
199
195
|
marker === MARKERS.DATE_RANGE_START
|
|
200
196
|
? year <= rangeEndYear
|
|
201
197
|
: year >= rangeStartYear;
|
|
202
198
|
|
|
203
|
-
return range(moment(minDate).year(), moment(maxDate).year() + 1)
|
|
199
|
+
return range(moment.utc(minDate).year(), moment.utc(maxDate).year() + 1)
|
|
204
200
|
.filter((year) => isWithinRange(year))
|
|
205
201
|
.map((year) => ({
|
|
206
202
|
key: year.toString(),
|
|
@@ -251,22 +247,25 @@ export const getAvailableMonths = ({
|
|
|
251
247
|
});
|
|
252
248
|
};
|
|
253
249
|
|
|
254
|
-
export const getValidDates = (
|
|
250
|
+
export const getValidDates = ({
|
|
251
|
+
selectedDateRange,
|
|
252
|
+
minDate,
|
|
253
|
+
maxDate,
|
|
254
|
+
today,
|
|
255
|
+
onError,
|
|
256
|
+
}: {
|
|
255
257
|
selectedDateRange: DateRangeWithTimezone,
|
|
256
258
|
minDate?: ?string,
|
|
257
259
|
maxDate?: ?string,
|
|
260
|
+
today: string,
|
|
258
261
|
onError?: (DateRangePickerError) => void,
|
|
259
|
-
): {
|
|
260
|
-
validTimezone: string,
|
|
262
|
+
}): {
|
|
261
263
|
validMinDate: string,
|
|
262
264
|
validMaxDate: string,
|
|
263
265
|
validDateRange: DateRange,
|
|
264
266
|
} => {
|
|
265
|
-
const
|
|
266
|
-
const localTimezone = moment.tz.guess();
|
|
267
|
-
const {startDate, endDate, timezone = ''} = selectedDateRange;
|
|
267
|
+
const {startDate, endDate} = selectedDateRange;
|
|
268
268
|
|
|
269
|
-
const validTimezone = isEmpty(timezone) ? localTimezone : timezone;
|
|
270
269
|
const validMaxDate = maxDate && !isEmpty(maxDate) ? maxDate : today;
|
|
271
270
|
const validMinDate =
|
|
272
271
|
minDate && !isEmpty(minDate) ? minDate : getSubtractedDate(today, 8, 'y');
|
|
@@ -293,13 +292,11 @@ export const getValidDates = (
|
|
|
293
292
|
|
|
294
293
|
if (isMinMaxRangeInvalid || isStartDateInvalid) {
|
|
295
294
|
return {
|
|
296
|
-
validTimezone,
|
|
297
295
|
validDateRange: {startDate: null, endDate: null},
|
|
298
296
|
validMinDate,
|
|
299
297
|
validMaxDate,
|
|
300
298
|
};
|
|
301
299
|
}
|
|
302
|
-
|
|
303
300
|
// if endDate is defined then it should be before maxDate
|
|
304
301
|
const isEndDateInvalid =
|
|
305
302
|
isEmpty(endDate) ||
|
|
@@ -316,7 +313,6 @@ export const getValidDates = (
|
|
|
316
313
|
|
|
317
314
|
if (isEndDateInvalid || isStartEndRangeInvalid) {
|
|
318
315
|
return {
|
|
319
|
-
validTimezone,
|
|
320
316
|
validDateRange: {startDate, endDate: null},
|
|
321
317
|
validMinDate,
|
|
322
318
|
validMaxDate,
|
|
@@ -324,7 +320,6 @@ export const getValidDates = (
|
|
|
324
320
|
}
|
|
325
321
|
|
|
326
322
|
return {
|
|
327
|
-
validTimezone,
|
|
328
323
|
validDateRange: {
|
|
329
324
|
startDate: isEmpty(startDate) ? null : startDate,
|
|
330
325
|
endDate: isEmpty(endDate) ? null : endDate,
|
|
@@ -333,3 +328,45 @@ export const getValidDates = (
|
|
|
333
328
|
validMaxDate,
|
|
334
329
|
};
|
|
335
330
|
};
|
|
331
|
+
|
|
332
|
+
// If date1 is same as date2 w.r.t the unit passed
|
|
333
|
+
export const isSame = (
|
|
334
|
+
date1: string,
|
|
335
|
+
date2: string,
|
|
336
|
+
unit: 'd' | 'month',
|
|
337
|
+
): boolean => moment.utc(date1).isSame(moment.utc(date2), unit);
|
|
338
|
+
|
|
339
|
+
// If date1 is before date2
|
|
340
|
+
export const isBefore = (date1: string, date2: string): boolean =>
|
|
341
|
+
moment.utc(date1).isBefore(moment.utc(date2));
|
|
342
|
+
|
|
343
|
+
// If date1 is after date2 w.r.t the unit passed
|
|
344
|
+
export const isAfter = (date1: string, date2: string): boolean =>
|
|
345
|
+
moment.utc(date1).isAfter(moment.utc(date2));
|
|
346
|
+
|
|
347
|
+
// If date1 is same or before date2 w.r.t the unit passed
|
|
348
|
+
export const isSameOrBefore = (
|
|
349
|
+
date1?: ?string,
|
|
350
|
+
date2?: ?string,
|
|
351
|
+
unit?: 'd' | 'month',
|
|
352
|
+
): boolean => moment.utc(date1).isSameOrBefore(moment.utc(date2), unit);
|
|
353
|
+
|
|
354
|
+
// If date1 is same or after date2 w.r.t the unit passed
|
|
355
|
+
export const isSameOrAfter = (
|
|
356
|
+
date1?: ?string,
|
|
357
|
+
date2?: ?string,
|
|
358
|
+
unit?: 'd' | 'month',
|
|
359
|
+
): boolean => moment.utc(date1).isSameOrAfter(moment.utc(date2), unit);
|
|
360
|
+
|
|
361
|
+
// If date is between startRange and endRange
|
|
362
|
+
export const isBetween = (
|
|
363
|
+
date: string,
|
|
364
|
+
startRange: string,
|
|
365
|
+
endRange: string,
|
|
366
|
+
): boolean =>
|
|
367
|
+
moment
|
|
368
|
+
.utc(date)
|
|
369
|
+
.isBetween(moment.utc(startRange), moment.utc(endRange), null, '[]');
|
|
370
|
+
|
|
371
|
+
// If the date results in a date that exists in the calendar
|
|
372
|
+
export const isValid = (date?: ?string): boolean => moment.utc(date).isValid();
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TIMEZONES = void 0;
|
|
6
|
+
exports.getTodayInTimezone = exports.addTimezoneStartOfDay = exports.addTimezoneEndOfDay = exports.TIMEZONES = void 0;
|
|
7
|
+
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
|
|
10
|
+
// $FlowFixMe[untyped-import]
|
|
7
11
|
|
|
8
12
|
const TIMEZONES = {
|
|
9
13
|
'Pacific/Niue': '(GMT-11:00) Niue',
|
|
@@ -259,4 +263,10 @@ const TIMEZONES = {
|
|
|
259
263
|
'Pacific/Tongatapu': '(GMT+13:00) Tongatapu',
|
|
260
264
|
'Pacific/Kiritimati': '(GMT+14:00) Kiritimati'
|
|
261
265
|
};
|
|
262
|
-
exports.TIMEZONES = TIMEZONES;
|
|
266
|
+
exports.TIMEZONES = TIMEZONES;
|
|
267
|
+
const addTimezoneStartOfDay = (date, timezone) => _momentTimezone.default.tz(date, timezone).startOf('d').toISOString();
|
|
268
|
+
exports.addTimezoneStartOfDay = addTimezoneStartOfDay;
|
|
269
|
+
const addTimezoneEndOfDay = (date, timezone) => _momentTimezone.default.tz(date, timezone).endOf('d').toISOString();
|
|
270
|
+
exports.addTimezoneEndOfDay = addTimezoneEndOfDay;
|
|
271
|
+
const getTodayInTimezone = timezone => _momentTimezone.default.tz(timezone).format('YYYY-MM-DD');
|
|
272
|
+
exports.getTodayInTimezone = getTodayInTimezone;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
|
+
// $FlowFixMe[untyped-import]
|
|
4
|
+
import moment from 'moment-timezone';
|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
export const TIMEZONES = {
|
|
4
8
|
'Pacific/Niue': '(GMT-11:00) Niue',
|
|
5
9
|
'Pacific/Pago_Pago': '(GMT-11:00) Pago Pago',
|
|
@@ -254,3 +258,12 @@ export const TIMEZONES = {
|
|
|
254
258
|
'Pacific/Tongatapu': '(GMT+13:00) Tongatapu',
|
|
255
259
|
'Pacific/Kiritimati': '(GMT+14:00) Kiritimati',
|
|
256
260
|
};
|
|
261
|
+
|
|
262
|
+
export const addTimezoneStartOfDay = (date: string, timezone: string): string =>
|
|
263
|
+
moment.tz(date, timezone).startOf('d').toISOString();
|
|
264
|
+
|
|
265
|
+
export const addTimezoneEndOfDay = (date: string, timezone: string): string =>
|
|
266
|
+
moment.tz(date, timezone).endOf('d').toISOString();
|
|
267
|
+
|
|
268
|
+
export const getTodayInTimezone = (timezone: string): string =>
|
|
269
|
+
moment.tz(timezone).format('YYYY-MM-DD');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spaced-out/ui-design-system",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Sense UI components library",
|
|
6
6
|
"author": {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"highcharts": "^11.4.1",
|
|
50
50
|
"highcharts-react-official": "^3.2.1",
|
|
51
51
|
"lodash": "^4.17.21",
|
|
52
|
+
"moment": "^2.29.4",
|
|
52
53
|
"moment-timezone": "^0.5.45",
|
|
53
54
|
"react-dropzone": "^14.2.3",
|
|
54
55
|
"react-window": "^1.8.10"
|