forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_utils.js
101 lines (85 loc) · 3.16 KB
/
date_utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSameDay = isSameDay;
exports.isSameDayAndTime = isSameDayAndTime;
exports.isDayDisabled = isDayDisabled;
exports.allDaysDisabledBefore = allDaysDisabledBefore;
exports.allDaysDisabledAfter = allDaysDisabledAfter;
exports.getEffectiveMinDate = getEffectiveMinDate;
exports.getEffectiveMaxDate = getEffectiveMaxDate;
var _moment = require('moment');
var _moment2 = _interopRequireDefault(_moment);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isSameDay(moment1, moment2) {
if (moment1 && moment2) {
return moment1.isSame(moment2, 'day');
} else {
return !moment1 && !moment2;
}
}
function isSameDayAndTime(moment1, moment2) {
if (moment1 && moment2) {
return moment1.isSame(moment2, 'minute');
} else {
return !moment1 && !moment2;
}
}
function isDayDisabled(day) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
minDate = _ref.minDate,
maxDate = _ref.maxDate,
excludeDates = _ref.excludeDates,
includeDates = _ref.includeDates,
filterDate = _ref.filterDate;
return minDate && day.isBefore(minDate, 'day') || maxDate && day.isAfter(maxDate, 'day') || excludeDates && excludeDates.some(function (excludeDate) {
return isSameDay(day, excludeDate);
}) || includeDates && !includeDates.some(function (includeDate) {
return isSameDay(day, includeDate);
}) || filterDate && !filterDate(day.clone()) || false;
}
function allDaysDisabledBefore(day, unit) {
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
minDate = _ref2.minDate,
includeDates = _ref2.includeDates;
var dateBefore = day.clone().subtract(1, unit);
return minDate && dateBefore.isBefore(minDate, unit) || includeDates && includeDates.every(function (includeDate) {
return dateBefore.isBefore(includeDate, unit);
}) || false;
}
function allDaysDisabledAfter(day, unit) {
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
maxDate = _ref3.maxDate,
includeDates = _ref3.includeDates;
var dateAfter = day.clone().add(1, unit);
return maxDate && dateAfter.isAfter(maxDate, unit) || includeDates && includeDates.every(function (includeDate) {
return dateAfter.isAfter(includeDate, unit);
}) || false;
}
function getEffectiveMinDate(_ref4) {
var minDate = _ref4.minDate,
includeDates = _ref4.includeDates;
if (includeDates && minDate) {
return _moment2.default.min(includeDates.filter(function (includeDate) {
return minDate.isSameOrBefore(includeDate, 'day');
}));
} else if (includeDates) {
return _moment2.default.min(includeDates);
} else {
return minDate;
}
}
function getEffectiveMaxDate(_ref5) {
var maxDate = _ref5.maxDate,
includeDates = _ref5.includeDates;
if (includeDates && maxDate) {
return _moment2.default.max(includeDates.filter(function (includeDate) {
return maxDate.isSameOrAfter(includeDate, 'day');
}));
} else if (includeDates) {
return _moment2.default.max(includeDates);
} else {
return maxDate;
}
}