aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2018-08-07 19:44:03 +0200
committerFélix Sipma <felix.sipma@no-log.org>2018-08-07 19:44:03 +0200
commit360c6bc2bd7cb5f00db25ab87d60dfcf3431e6a0 (patch)
treeb0cbafcc35c002c324db6b75142164d1020c01ae
parent14dd453d56582b2560a2de7778c753514eb5311a (diff)
simplify holiday test condition
-rw-r--r--shop-client/src/Shop.js66
1 files changed, 7 insertions, 59 deletions
diff --git a/shop-client/src/Shop.js b/shop-client/src/Shop.js
index 546f9f7..0001374 100644
--- a/shop-client/src/Shop.js
+++ b/shop-client/src/Shop.js
@@ -2,66 +2,12 @@
window['moment-range'].extendMoment(moment);
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
-// https://tc39.github.io/ecma262/#sec-array.prototype.includes
-if (!Array.prototype.includes) {
- Object.defineProperty(Array.prototype, 'includes', {
- value: function(searchElement, fromIndex) {
-
- if (this == null) {
- throw new TypeError('"this" is null or not defined');
- }
-
- // 1. Let O be ? ToObject(this value).
- var o = Object(this);
-
- // 2. Let len be ? ToLength(? Get(O, "length")).
- var len = o.length >>> 0;
-
- // 3. If len is 0, return false.
- if (len === 0) {
- return false;
- }
-
- // 4. Let n be ? ToInteger(fromIndex).
- // (If fromIndex is undefined, this step produces the value 0.)
- var n = fromIndex | 0;
-
- // 5. If n ≥ 0, then
- // a. Let k be n.
- // 6. Else n < 0,
- // a. Let k be len + n.
- // b. If k < 0, let k be 0.
- var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
-
- function sameValueZero(x, y) {
- return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
- }
-
- // 7. Repeat, while k < len
- while (k < len) {
- // a. Let elementK be the result of ? Get(O, ! ToString(k)).
- // b. If SameValueZero(searchElement, elementK) is true, return true.
- if (sameValueZero(o[k], searchElement)) {
- return true;
- }
- // c. Increase k by 1.
- k++;
- }
-
- // 8. Return false
- return false;
- }
- });
-}
-
exports.pikadayNew = function (elementid) {
return function(holidays) {
- var holidayranges = holidays.map(function(dr) {
- return Array.from(moment.range(dr).by('days')).map(function(r) { return r.valueOf(); })
- });
- var holidayarray = [].concat.apply([], holidayranges);
return function () {
+ var holidayranges = holidays.map(function(dr) {
+ return moment.range(dr);
+ });
var date = moment().add(2, 'd').toDate();
var picker = new Pikaday({
field: document.getElementById(elementid),
@@ -70,8 +16,10 @@ exports.pikadayNew = function (elementid) {
minDate: date,
disableDayFn: function (date) {
var day = date.getDay();
- var mdate = moment(date).valueOf();
- return day === 0 || day === 1 || holidayarray.includes(mdate);
+ var holidayarray = holidayranges.filter(function(dr) {
+ return dr.contains(moment(date))
+ });
+ return day === 0 || day === 1 || holidayarray.length > 0;
},
i18n: {
previousMonth : 'Mois précédent',