@spothero/ui 15.0.0-beta.3 → 15.0.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/README.md +2 -2
- package/backlog/Chart/Chart.js +1 -1
- package/backlog/DateTime/DatePicker.js +1 -1
- package/backlog/DateTime/DatePickerCalendar.js +1 -1
- package/backlog/DateTime/DatePickerCalendarWithRange.js +1 -1
- package/backlog/DateTime/DateTimeRangePicker.js +2 -2
- package/backlog/DateTime/TimePicker.js +1 -1
- package/backlog/ErrorBoundary/ErrorBoundary.js +9 -7
- package/backlog/Flyout/Flyout.js +1 -1
- package/backlog/Form/Form.js +2 -2
- package/backlog/GooglePlacesSearchInput/GooglePlacesSearchInput.js +4 -1
- package/backlog/Notification/Notification.js +1 -1
- package/backlog/Portal/Portal.js +1 -1
- package/backlog/RenderInBody/RenderInBody.js +1 -1
- package/backlog/Select/Select.js +1 -1
- package/backlog/SelectControlled/SelectControlled.js +1 -1
- package/backlog/Tooltip/Tooltip.js +1 -1
- package/backlog/v1/components/Image/Image.js +1 -1
- package/backlog/v1/components/Modal/Modal.js +1 -1
- package/backlog/v1/components/Modal/ModalContent.js +1 -1
- package/package.json +21 -11
- package/styles/Chart/Chart.jsx +1 -1
- package/styles/DateTime/DatePicker.jsx +1 -1
- package/styles/DateTime/DatePickerCalendar.jsx +1 -1
- package/styles/DateTime/DatePickerCalendarWithRange.jsx +1 -1
- package/styles/DateTime/DateTimeRangePicker.jsx +2 -2
- package/styles/DateTime/TimePicker.jsx +1 -1
- package/styles/ErrorBoundary/ErrorBoundary.jsx +6 -7
- package/styles/Flyout/Flyout.jsx +1 -1
- package/styles/Form/Form.jsx +2 -2
- package/styles/GooglePlacesSearchInput/GooglePlacesSearchInput.jsx +2 -2
- package/styles/Notification/Notification.jsx +1 -1
- package/styles/Portal/Portal.jsx +1 -1
- package/styles/RenderInBody/RenderInBody.jsx +1 -1
- package/styles/Select/Select.jsx +1 -1
- package/styles/SelectControlled/SelectControlled.jsx +1 -1
- package/styles/Tooltip/Tooltip.jsx +1 -1
- package/styles/v1/components/Image/Image.jsx +1 -1
- package/styles/v1/components/Modal/Modal.jsx +1 -1
- package/styles/v1/components/Modal/ModalContent.jsx +1 -1
- package/styles/v1/components/Modal/stories/Content.stories.js +1 -1
- package/styles/v2/components/Image/Image.jsx +1 -1
- package/styles/v2/components/Modal/Modal.jsx +2 -2
- package/styles/v2/components/Modal/Modal.stories.js +4 -7
- package/v1/index.js +1 -1
- package/v1/index.js.map +1 -1
- package/v2/index.js +1 -1
- package/v2/index.js.map +1 -1
- package/backlog/utils/animation.js +0 -84
- package/backlog/utils/date.js +0 -233
- package/backlog/utils/dom.js +0 -441
- package/backlog/utils/environment.js +0 -422
- package/backlog/utils/number.js +0 -43
- package/backlog/utils/time.js +0 -282
- package/styles/utils/animation.js +0 -75
- package/styles/utils/date.js +0 -226
- package/styles/utils/dom.js +0 -428
- package/styles/utils/environment.js +0 -425
- package/styles/utils/number.js +0 -33
- package/styles/utils/time.js +0 -268
package/backlog/utils/time.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
11
|
-
|
|
12
|
-
var _isNumber = _interopRequireDefault(require("lodash/isNumber"));
|
|
13
|
-
|
|
14
|
-
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
15
|
-
|
|
16
|
-
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
17
|
-
|
|
18
|
-
var _number = _interopRequireDefault(require("./number"));
|
|
19
|
-
|
|
20
|
-
// import StringUtils from '../string/string';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Utilities for working with times.
|
|
24
|
-
* @module TimeUtils
|
|
25
|
-
*/
|
|
26
|
-
var TimeUtils = {
|
|
27
|
-
// /**
|
|
28
|
-
// * Normalizes the provided time down to the provided step.
|
|
29
|
-
// * @static
|
|
30
|
-
// * @function normalizeToStep
|
|
31
|
-
// * @param {String} time - The input value in the format hh:mm A.
|
|
32
|
-
// * @param {Number} [step=1] - The step to round down to.
|
|
33
|
-
// * @example
|
|
34
|
-
// * TimeUtils.normalizeToStep('07:07 PM', 15); // '07:00 PM'
|
|
35
|
-
// * @returns {String} - The normalized time.
|
|
36
|
-
// */
|
|
37
|
-
// normalizeToStep(time, step = 1) {
|
|
38
|
-
// if (isEmpty(time)) {
|
|
39
|
-
// return time;
|
|
40
|
-
// }
|
|
41
|
-
//
|
|
42
|
-
// if (!isString(time)) {
|
|
43
|
-
// throw new Error('The supplied time is not a string.');
|
|
44
|
-
// }
|
|
45
|
-
//
|
|
46
|
-
// const {hours, mins} = TimeUtils.getValuesFromString(time, step);
|
|
47
|
-
//
|
|
48
|
-
// return TimeUtils.getFromValuesAsString(hours, mins);
|
|
49
|
-
// },
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Provides the hours, minutes, and meridiem from a time string.
|
|
54
|
-
* @static
|
|
55
|
-
* @function getValuesFromString
|
|
56
|
-
* @param {String} time - The input value in the format hh:mm A.
|
|
57
|
-
* @param {Number} [step=1] - The step to round down to.
|
|
58
|
-
* @example
|
|
59
|
-
* TimeUtils.getValuesFromString('10:19 AM');
|
|
60
|
-
* @returns {Object} - The object containing the hours, minutes, and meridiem.
|
|
61
|
-
*/
|
|
62
|
-
getValuesFromString: function getValuesFromString(time) {
|
|
63
|
-
var step = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
64
|
-
|
|
65
|
-
if ((0, _isEmpty.default)(time)) {
|
|
66
|
-
return time;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!(0, _isString.default)(time)) {
|
|
70
|
-
throw new Error('The supplied time is not a string.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var firstPartials = time.split(':');
|
|
74
|
-
var secondPartials = firstPartials[1].split(' ');
|
|
75
|
-
var isAM = secondPartials[1] === 'AM';
|
|
76
|
-
var mins = parseInt(secondPartials[0], 10);
|
|
77
|
-
|
|
78
|
-
var minsRounded = _number.default.roundDownToNearestStep(mins, step);
|
|
79
|
-
|
|
80
|
-
var hours = parseInt(firstPartials[0], 10);
|
|
81
|
-
|
|
82
|
-
if (isAM && hours === 12) {
|
|
83
|
-
hours = 0;
|
|
84
|
-
} else if (!isAM && hours !== 12) {
|
|
85
|
-
hours += 12;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
hours: hours,
|
|
90
|
-
mins: minsRounded,
|
|
91
|
-
isAM: isAM
|
|
92
|
-
};
|
|
93
|
-
},
|
|
94
|
-
//
|
|
95
|
-
// /**
|
|
96
|
-
// * Provides the formatted time from hours and minutes values.
|
|
97
|
-
// * @static
|
|
98
|
-
// * @function getFromValuesAsString
|
|
99
|
-
// * @param {Number} hours - The hours in a 24 hour format.
|
|
100
|
-
// * @param {Number} minutes - The minutes from 0 - 60.
|
|
101
|
-
// * @param {Boolean} [roundMinutesDown=false] - Whether to round the minutes down to the provided step.
|
|
102
|
-
// * @param {Number} [step=1] - The step to round minutes down to.
|
|
103
|
-
// * @example
|
|
104
|
-
// * TimeUtils.getFromValuesAsString(20, 35); // '08:35 PM'
|
|
105
|
-
// * @returns {String} - The formatted time.
|
|
106
|
-
// */
|
|
107
|
-
// getFromValuesAsString(hours, minutes, roundMinutesDown = false, step = 1) {
|
|
108
|
-
// const meridiem = hours < 12 ? 'AM' : 'PM';
|
|
109
|
-
// let newHours = hours;
|
|
110
|
-
// let newMinutes = minutes;
|
|
111
|
-
//
|
|
112
|
-
// if (newHours > 12) {
|
|
113
|
-
// newHours -= 12;
|
|
114
|
-
// } else if (newHours === 0) {
|
|
115
|
-
// newHours = 12;
|
|
116
|
-
// }
|
|
117
|
-
//
|
|
118
|
-
// if (roundMinutesDown) {
|
|
119
|
-
// newMinutes = NumberUtils.roundDownToNearestStep(newMinutes, step);
|
|
120
|
-
// }
|
|
121
|
-
//
|
|
122
|
-
// return `${StringUtils.padWith(newHours)}:${StringUtils.padWith(
|
|
123
|
-
// newMinutes
|
|
124
|
-
// )} ${meridiem}`;
|
|
125
|
-
// },
|
|
126
|
-
//
|
|
127
|
-
// /**
|
|
128
|
-
// * Converts a mobile input time to a string in the format hh:mm A.
|
|
129
|
-
// * @static
|
|
130
|
-
// * @function getMobileAsString
|
|
131
|
-
// * @param {String} time - The input value in the format HH:mm (24 hour format).
|
|
132
|
-
// * @param {Number} [step=1] - The step to round down to.
|
|
133
|
-
// * @example
|
|
134
|
-
// * TimeUtils.getMobileAsString('22:19'); // 10:19 PM
|
|
135
|
-
// * @returns {String} - The formatted time.
|
|
136
|
-
// */
|
|
137
|
-
// getMobileAsString(time, step = 1) {
|
|
138
|
-
// if (!isString(time)) {
|
|
139
|
-
// throw new Error('The supplied time is not a string.');
|
|
140
|
-
// }
|
|
141
|
-
//
|
|
142
|
-
// const frags = time.split(':');
|
|
143
|
-
// const mins = parseInt(frags[1], 10);
|
|
144
|
-
// const minsRounded = NumberUtils.roundDownToNearestStep(mins, step);
|
|
145
|
-
// const hours = parseInt(frags[0], 10);
|
|
146
|
-
// const meridiem = hours < 12 ? 'AM' : 'PM';
|
|
147
|
-
// let hh = hours;
|
|
148
|
-
//
|
|
149
|
-
// if (hours > 12) {
|
|
150
|
-
// hh -= 12;
|
|
151
|
-
// } else if (hours === 0) {
|
|
152
|
-
// hh = 12;
|
|
153
|
-
// }
|
|
154
|
-
//
|
|
155
|
-
// return `${StringUtils.padWith(hh)}:${StringUtils.padWith(
|
|
156
|
-
// minsRounded
|
|
157
|
-
// )} ${meridiem}`;
|
|
158
|
-
// },
|
|
159
|
-
//
|
|
160
|
-
// /**
|
|
161
|
-
// * Converts a time to a date object.
|
|
162
|
-
// * @static
|
|
163
|
-
// * @function getAsDate
|
|
164
|
-
// * @param {String} time - The input value in the format hh:mm A.
|
|
165
|
-
// * @example
|
|
166
|
-
// * TimeUtils.getAsDate('10:19 PM');
|
|
167
|
-
// * @returns {Date} - The time inside of a date object.
|
|
168
|
-
// */
|
|
169
|
-
// getAsDate(time) {
|
|
170
|
-
// if (isEmpty(time)) {
|
|
171
|
-
// return null;
|
|
172
|
-
// }
|
|
173
|
-
//
|
|
174
|
-
// if (!isString(time)) {
|
|
175
|
-
// throw new Error('The supplied time is not a string.');
|
|
176
|
-
// }
|
|
177
|
-
//
|
|
178
|
-
// const {hours, mins} = TimeUtils.getValuesFromString(time);
|
|
179
|
-
// const d = new Date();
|
|
180
|
-
//
|
|
181
|
-
// d.setHours(hours);
|
|
182
|
-
// d.setMinutes(mins);
|
|
183
|
-
// d.setSeconds(0);
|
|
184
|
-
//
|
|
185
|
-
// return d;
|
|
186
|
-
// },
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Converts a time to a moment instance.
|
|
190
|
-
* @static
|
|
191
|
-
* @function getAsMoment
|
|
192
|
-
* @param {String} time - The input value in the format hh:mm A.
|
|
193
|
-
* @example
|
|
194
|
-
* TimeUtils.getAsMoment('10:19 PM');
|
|
195
|
-
* @returns {Moment} - The time inside of a moment instance.
|
|
196
|
-
*/
|
|
197
|
-
getAsMoment: function getAsMoment(time) {
|
|
198
|
-
if ((0, _isEmpty.default)(time)) {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (!(0, _isString.default)(time)) {
|
|
203
|
-
throw new Error('The supplied time is not a string.');
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
var _TimeUtils$getValuesF = TimeUtils.getValuesFromString(time),
|
|
207
|
-
hours = _TimeUtils$getValuesF.hours,
|
|
208
|
-
mins = _TimeUtils$getValuesF.mins;
|
|
209
|
-
|
|
210
|
-
return (0, _momentTimezone.default)([1, 1]).startOf('day').add(hours, 'hours').add(mins, 'minutes');
|
|
211
|
-
},
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Generate an array of times.
|
|
215
|
-
* @static
|
|
216
|
-
* @function getTimes
|
|
217
|
-
* @param {Object} data - The data to pass to the function.
|
|
218
|
-
* @param {Number} [data.step=30] - Increment times by this many minutes.
|
|
219
|
-
* @param {String} [data.format='hh:mm A'] - Moment.js format (http://momentjs.com/docs/#/displaying/format/).
|
|
220
|
-
* @param {String} [data.ignoreBefore] - Number of minutes to ignore times before in the output.
|
|
221
|
-
* @param {String} [data.ignoreAfter] - Number of minutes to ignore times after in the output.
|
|
222
|
-
* @example
|
|
223
|
-
* TimeUtils.getTimes({
|
|
224
|
-
* step: 30,
|
|
225
|
-
* format: 'hh:mm A'
|
|
226
|
-
* });
|
|
227
|
-
* @returns {Array} times - An array of times.
|
|
228
|
-
*/
|
|
229
|
-
getTimes: function getTimes() {
|
|
230
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
231
|
-
_ref$step = _ref.step,
|
|
232
|
-
step = _ref$step === void 0 ? 30 : _ref$step,
|
|
233
|
-
_ref$format = _ref.format,
|
|
234
|
-
format = _ref$format === void 0 ? 'hh:mm A' : _ref$format,
|
|
235
|
-
ignoreBefore = _ref.ignoreBefore,
|
|
236
|
-
ignoreAfter = _ref.ignoreAfter;
|
|
237
|
-
|
|
238
|
-
if (ignoreBefore && !(0, _isNumber.default)(ignoreBefore)) {
|
|
239
|
-
throw new Error('The ignoreBefore value passed was not a number.');
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (ignoreAfter && !(0, _isNumber.default)(ignoreAfter)) {
|
|
243
|
-
throw new Error('The ignoreAfter value passed was not a number.');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (ignoreBefore && ignoreAfter && ignoreBefore > ignoreAfter) {
|
|
247
|
-
throw new Error('The value of ignoreBefore should be less than the value of ignoreAfter.');
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
var dateTime = (0, _momentTimezone.default)([0, 0]);
|
|
251
|
-
var total = 1440;
|
|
252
|
-
var len = total / step;
|
|
253
|
-
var times = [];
|
|
254
|
-
var beforeMoment = ignoreBefore ? dateTime.clone().startOf('day').add(ignoreBefore, 'minutes') : null;
|
|
255
|
-
var afterMoment = ignoreAfter ? dateTime.clone().startOf('day').add(ignoreAfter, 'minutes') : null;
|
|
256
|
-
var i = 0;
|
|
257
|
-
var id = 0;
|
|
258
|
-
var shouldAdd = true;
|
|
259
|
-
var time;
|
|
260
|
-
|
|
261
|
-
for (i; i < len; i++) {
|
|
262
|
-
id = i * step;
|
|
263
|
-
time = dateTime.clone().startOf('day').add(id, 'minutes');
|
|
264
|
-
shouldAdd = beforeMoment ? time.isSameOrAfter(beforeMoment) : shouldAdd;
|
|
265
|
-
|
|
266
|
-
if (shouldAdd) {
|
|
267
|
-
shouldAdd = afterMoment ? time.isSameOrBefore(afterMoment) : shouldAdd;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (shouldAdd) {
|
|
271
|
-
times.push({
|
|
272
|
-
id: id,
|
|
273
|
-
formatted: time.format(format)
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return times;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
var _default = TimeUtils;
|
|
282
|
-
exports.default = _default;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import {window} from 'ssr-window';
|
|
2
|
-
import isString from 'lodash/isString';
|
|
3
|
-
import DOMUtils from './dom';
|
|
4
|
-
|
|
5
|
-
// t = current time, b = start value, c = change in value, d = duration
|
|
6
|
-
// http://stackoverflow.com/questions/8917921/cross-browser-javascript-not-jquery-scroll-to-top-animation
|
|
7
|
-
Math.easeInOutQuad = (t, b, c, d) => {
|
|
8
|
-
/* eslint-disable no-param-reassign, no-mixed-operators */
|
|
9
|
-
t /= d / 2;
|
|
10
|
-
|
|
11
|
-
if (t < 1) {
|
|
12
|
-
return (c / 2) * t * t + b;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
t--;
|
|
16
|
-
|
|
17
|
-
return (-c / 2) * (t * (t - 2) - 1) + b;
|
|
18
|
-
/* eslint-enable no-param-reassign, no-mixed-operators */
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Utilities for working with animations.
|
|
23
|
-
* @module AnimationUtils
|
|
24
|
-
*/
|
|
25
|
-
const AnimationUtils = {
|
|
26
|
-
/**
|
|
27
|
-
* Scrolls the specified element to the specified position.
|
|
28
|
-
* @static
|
|
29
|
-
* @function scrollTo
|
|
30
|
-
* @param {String|Element} el - The selector or element to scroll to.
|
|
31
|
-
* @param {Number} [position=0] - The position to scroll the element to.
|
|
32
|
-
* @param {Number} [duration=400] - The time (in milliseconds) to scroll.
|
|
33
|
-
* @param {String} [axis='y'] - The axis to scroll on.
|
|
34
|
-
* @param {Function} [cb] - A callback function to call when the animation finishes.
|
|
35
|
-
* @example
|
|
36
|
-
* AnimationUtils.scrollTo(window, 0, 1000);
|
|
37
|
-
* @returns {void}
|
|
38
|
-
*/
|
|
39
|
-
scrollTo(el, position = 0, duration = 400, axis = 'y', cb = null) {
|
|
40
|
-
const element = isString(el) ? DOMUtils.el(el) : el;
|
|
41
|
-
const start = axis === 'y' ? element.scrollTop : element.scrollLeft;
|
|
42
|
-
const change = position - start;
|
|
43
|
-
const increment = 20;
|
|
44
|
-
let currentTime = 0;
|
|
45
|
-
|
|
46
|
-
const animateScroll = () => {
|
|
47
|
-
currentTime += increment;
|
|
48
|
-
|
|
49
|
-
const val = Math.easeInOutQuad(
|
|
50
|
-
currentTime,
|
|
51
|
-
start,
|
|
52
|
-
change,
|
|
53
|
-
duration
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (axis === 'y') {
|
|
57
|
-
element.scrollTop = val;
|
|
58
|
-
} else {
|
|
59
|
-
element.scrollLeft = val;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (currentTime < duration) {
|
|
63
|
-
window.setTimeout(animateScroll, increment);
|
|
64
|
-
} else {
|
|
65
|
-
if (cb) {
|
|
66
|
-
cb();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
animateScroll();
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export default AnimationUtils;
|
package/styles/utils/date.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import {window} from 'ssr-window';
|
|
2
|
-
import isDate from 'lodash/isDate';
|
|
3
|
-
import isObject from 'lodash/isObject';
|
|
4
|
-
import isString from 'lodash/isString';
|
|
5
|
-
import moment from 'moment-timezone';
|
|
6
|
-
|
|
7
|
-
const splitTextDate = (date, delimeter) => {
|
|
8
|
-
const d = date.split(delimeter);
|
|
9
|
-
|
|
10
|
-
return new Date(d[2], d[0] - 1, d[1]);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const splitMobileDate = date => {
|
|
14
|
-
const d = date.split('-');
|
|
15
|
-
|
|
16
|
-
return new Date(d[0], d[1] - 1, d[2]);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Utilities for working with dates.
|
|
21
|
-
* @module DateUtils
|
|
22
|
-
*/
|
|
23
|
-
const DateUtils = {
|
|
24
|
-
// /**
|
|
25
|
-
// * Check whether input type of 'date' is supported in the current browser.
|
|
26
|
-
// * @static
|
|
27
|
-
// * @function supportsDateInput
|
|
28
|
-
// * @example
|
|
29
|
-
// * DateUtils.supportsDateInput();
|
|
30
|
-
// * @returns {Boolean} - Whether the input type is supported.
|
|
31
|
-
// */
|
|
32
|
-
// supportsDateInput() {
|
|
33
|
-
// const fakeValue = 'not-a-date';
|
|
34
|
-
// const input = document.createElement('input');
|
|
35
|
-
//
|
|
36
|
-
// input.setAttribute('type', 'date');
|
|
37
|
-
// input.setAttribute('value', fakeValue);
|
|
38
|
-
//
|
|
39
|
-
// return input.value !== fakeValue;
|
|
40
|
-
// },
|
|
41
|
-
|
|
42
|
-
// /**
|
|
43
|
-
// * Gets the closest match to the user's current time zone.
|
|
44
|
-
// * @static
|
|
45
|
-
// * @function getTimeZone
|
|
46
|
-
// * @example
|
|
47
|
-
// * DateUtils.getTimeZone(); // 'America/Chicago'
|
|
48
|
-
// * @returns {String} - The user's current time zone.
|
|
49
|
-
// */
|
|
50
|
-
// getTimeZone() {
|
|
51
|
-
// if (
|
|
52
|
-
// window.Intl &&
|
|
53
|
-
// isObject(window.Intl) &&
|
|
54
|
-
// window.Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
55
|
-
// ) {
|
|
56
|
-
// return window.Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
57
|
-
// } else {
|
|
58
|
-
// return moment.tz.guess();
|
|
59
|
-
// }
|
|
60
|
-
// },
|
|
61
|
-
|
|
62
|
-
// /**
|
|
63
|
-
// * Converts a mobile input date to a string using the specified format.
|
|
64
|
-
// * @static
|
|
65
|
-
// * @function convertToDesktop
|
|
66
|
-
// * @param {String} date - The input value in the format YYYY-MM-DD.
|
|
67
|
-
// * @param {String} [format='MM/DD/YYYY'] - The output format.
|
|
68
|
-
// * @example
|
|
69
|
-
// * DateUtils.convertToDesktop('1983-01-19');
|
|
70
|
-
// * @returns {String} - The formatted date.
|
|
71
|
-
// */
|
|
72
|
-
// convertToDesktop(date, format = 'MM/DD/YYYY') {
|
|
73
|
-
// if (!isString(date)) {
|
|
74
|
-
// throw new Error('The supplied date is not a string.');
|
|
75
|
-
// }
|
|
76
|
-
//
|
|
77
|
-
// if (date.indexOf('-') !== -1) {
|
|
78
|
-
// return moment(splitMobileDate(date)).format(format);
|
|
79
|
-
// } else {
|
|
80
|
-
// return date;
|
|
81
|
-
// }
|
|
82
|
-
// },
|
|
83
|
-
|
|
84
|
-
// /**
|
|
85
|
-
// * Converts a desktop input date to the native mobile date format.
|
|
86
|
-
// * @static
|
|
87
|
-
// * @function convertToMobile
|
|
88
|
-
// * @param {String} date - The input value in the format MM/DD/YYYY.
|
|
89
|
-
// * @example
|
|
90
|
-
// * DateUtils.convertToMobile('01/19/1983');
|
|
91
|
-
// * @returns {String} - The mobile formatted date.
|
|
92
|
-
// */
|
|
93
|
-
// convertToMobile(date) {
|
|
94
|
-
// if (!isString(date)) {
|
|
95
|
-
// throw new Error('The supplied date is not a string.');
|
|
96
|
-
// }
|
|
97
|
-
//
|
|
98
|
-
// if (date.indexOf('/') !== -1) {
|
|
99
|
-
// return moment(splitTextDate(date, '/')).format('YYYY-MM-DD');
|
|
100
|
-
// } else {
|
|
101
|
-
// return date;
|
|
102
|
-
// }
|
|
103
|
-
// },
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Converts a string date from a text or date input to a date object.
|
|
107
|
-
* @static
|
|
108
|
-
* @function getAsDate
|
|
109
|
-
* @param {String} date - The date in the format MM/DD/YYYY (text input) or YYYY-MM-DD (date input).
|
|
110
|
-
* @example
|
|
111
|
-
* DateUtils.getAsDate('1983-01-19');
|
|
112
|
-
* DateUtils.getAsDate('01/19/1983');
|
|
113
|
-
* @returns {Date} - The date object.
|
|
114
|
-
*/
|
|
115
|
-
getAsDate(date) {
|
|
116
|
-
if (!isString(date)) {
|
|
117
|
-
throw new Error('The supplied date is not a string.');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (date.indexOf('-') !== -1) {
|
|
121
|
-
// date input
|
|
122
|
-
return splitMobileDate(date);
|
|
123
|
-
} else {
|
|
124
|
-
// text input
|
|
125
|
-
return splitTextDate(date, '/');
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Converts a string date from a text or date input to a moment instance.
|
|
131
|
-
* @static
|
|
132
|
-
* @function getAsMoment
|
|
133
|
-
* @param {String} date - The date in the format MM/DD/YYYY (text input) or YYYY-MM-DD (date input).
|
|
134
|
-
* @example
|
|
135
|
-
* DateUtils.getAsMoment('1983-01-19');
|
|
136
|
-
* DateUtils.getAsMoment('01/19/1983');
|
|
137
|
-
* @returns {Moment} - The moment instance.
|
|
138
|
-
*/
|
|
139
|
-
getAsMoment(date) {
|
|
140
|
-
if (!isString(date)) {
|
|
141
|
-
throw new Error('The supplied date is not a string.');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (date.indexOf('-') !== -1) {
|
|
145
|
-
// date input
|
|
146
|
-
return moment(splitMobileDate(date));
|
|
147
|
-
} else {
|
|
148
|
-
// text input
|
|
149
|
-
return moment(splitTextDate(date, '/'));
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Combines a date moment with a time moment to return one moment instance.
|
|
155
|
-
* @static
|
|
156
|
-
* @function combineDateAndTime
|
|
157
|
-
* @param {Moment} date - The date as a moment instance.
|
|
158
|
-
* @param {Moment} time - The time as a moment instance.
|
|
159
|
-
* @example
|
|
160
|
-
* DateUtils.combineDateAndTime(moment(), moment().add(7, 'hours').add(23, 'minutes'));
|
|
161
|
-
* @returns {Moment} - The combined moment instance.
|
|
162
|
-
*/
|
|
163
|
-
combineDateAndTime(date, time) {
|
|
164
|
-
if (!moment.isMoment(date) || !moment.isMoment(time)) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
'The date and/or time supplied was not an instance of Moment.'
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return date.hours(time.hours()).minutes(time.minutes());
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Checks if one date is before another.
|
|
175
|
-
* @static
|
|
176
|
-
* @function isBefore
|
|
177
|
-
* @param {Date} dateToCheck - The date to check.
|
|
178
|
-
* @param {Date} dateToCompare - The date to check against.
|
|
179
|
-
* @param {Boolean} [useTime=false] - Whether to use the time in the comparison.
|
|
180
|
-
* @example
|
|
181
|
-
* DateUtils.isBefore(new Date(2016, 1, 19), new Date(2016, 3, 14));
|
|
182
|
-
* @returns {Boolean} - Whether the provided date is before the one being checked against.
|
|
183
|
-
*/
|
|
184
|
-
isBefore(dateToCheck, dateToCompare, useTime = false) {
|
|
185
|
-
if (!isDate(dateToCheck) || !isDate(dateToCompare)) {
|
|
186
|
-
throw new Error(
|
|
187
|
-
'The dates supplied must be instances of the Date object.'
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (!useTime) {
|
|
192
|
-
dateToCheck.setHours(0, 0, 0, 0);
|
|
193
|
-
dateToCompare.setHours(0, 0, 0, 0);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return dateToCheck < dateToCompare;
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Checks if one date is after another.
|
|
201
|
-
* @static
|
|
202
|
-
* @function isAfter
|
|
203
|
-
* @param {Date} dateToCheck - The date to check.
|
|
204
|
-
* @param {Date} dateToCompare - The date to check against.
|
|
205
|
-
* @param {Boolean} [useTime=false] - Whether to use the time in the comparison.
|
|
206
|
-
* @example
|
|
207
|
-
* DateUtils.isAfter(new Date(2016, 1, 19), new Date(2016, 3, 14));
|
|
208
|
-
* @returns {Boolean} - Whether the provided date is after the one being checked against.
|
|
209
|
-
*/
|
|
210
|
-
isAfter(dateToCheck, dateToCompare, useTime = false) {
|
|
211
|
-
if (!isDate(dateToCheck) || !isDate(dateToCompare)) {
|
|
212
|
-
throw new Error(
|
|
213
|
-
'The dates supplied must be instances of the Date object.'
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (!useTime) {
|
|
218
|
-
dateToCheck.setHours(0, 0, 0, 0);
|
|
219
|
-
dateToCompare.setHours(0, 0, 0, 0);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return dateToCheck > dateToCompare;
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
export default DateUtils;
|