# All files calendardates.cjs.js

98.51% Statements 66/67
83.33% Branches 20/24
100% Functions 30/30
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2756x
     "use strict";function _classCallCheck(t,e){Iif(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function _createClass(t,e,n){return e&&_defineProperties(t.prototype,e),n&&_defineProperties(t,n),t}var monthTypes={PREVIOUS:"previous",CURRENT:"current",NEXT:"next"},pad=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0";return t<10?e+t:t},iso8601=function(t){return"".concat(t.getFullYear(),"-").concat(pad(t.getMonth()+1),"-").concat(pad(t.getDate()))},getLastDate=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},getFirstDayIndex=function(t){var e=new Date(t.getFullYear(),t.getMonth(),1).toDateString().substring(0,3);return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].indexOf(e)},getDatesWithMetadata=function(t){return new Promise(function(e){var n=[],a=getPreviousDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.PREVIOUS}}),r=getCurrentDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.CURRENT}});n=n.concat(a).concat(r);var o=getNextDates(t,n.length).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.NEXT}});e(n.concat(o))})},dateMapper=function(t){return function(e){return Array(t).fill().map(e)}},getCurrentDates=function(t){var e=getLastDate(t);return dateMapper(e)(function(e,n){var a=n+1;return t.setDate(a),{date:a,iso:iso8601(t)}})},getPreviousDates=function(t){var e=t.getMonth(),n=t.getFullYear(),a=Math.min(e-1,11),r=new Date(n,a),o=getLastDate(r),u=o-getFirstDayIndex(t)+1;return dateMapper(o-u+1)(function(t,e){var n=u+e;return r.setDate(n),{date:n,iso:iso8601(r)}})},getNextDates=function(t,e){var n=42-e,a=t.getMonth()+1===12?0:t.getMonth()+1,r=0===a?t.getFullYear()+1:t.getFullYear(),o=new Date(r,a);return dateMapper(n)(function(t,e){var n=e+1;return o.setDate(n),{date:n,iso:iso8601(o)}})},CalendarDates=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"getDates",value:function(t){return new Promise(function(e){return e(getDatesWithMetadata(t).then(function(t){return t.map(function(t){return t})}))})}},{key:"getMatrix",value:function(t){return new Promise(function(e){e(getDatesWithMetadata(t).then(function(t){return t.reduce(function(t,e,n){return(n%7==0?t.push([e]):t[t.length-1].push(e))&&t},[])}))})}}]),t}();module.exports=CalendarDates;