UNPKG

@livelybone/date-generator

Version:

A module that generates calendar, which includes years, months, dates, hours, minutes, seconds

10 lines (8 loc) 1.81 kB
/** * Bundle of @livelybone/date-generator * Generated: 2020-05-17 * Version: 4.2.1 * License: MIT * Author: 2631541504@qq.com */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).monthDateGenerator={})}(this,function(e){"use strict";function l(e,t,n){var r=2<arguments.length&&void 0!==n?n:"0";return void 0===r&&(r="0"),0<(e-=(t=t.toString()).length)?new Array(e+(/\./.test(t)?2:1)).join(r)+t:t}function h(e,t){return(e%t+t)%t}function s(e){if(!e)return null;var t=/^(\d{4})-?(\d{1,2})?-?(\d{1,2})?$/;if(!t.test(e))return console.warn(new Error("Param date `".concat(e,"` is invalid. The right example: 2018[-02][-01]"))),null;var n,r,a,o=e.match(t),i={year:l(4,o[1]),month:l(2,h(+o[2]||1,12)||12)},f=(n=i.year,r=i.month,n=+n,2==(r=+r)?(a=+n)%4!=0||a%100==0&&a%400!=0?28:29:Math.ceil(Math.abs(r-7.5))%2==1?31:30);return i.date=l(2,h(+o[3]||1,f)||f),i}e.getMonthByStep=function(e,t){var n="string"==typeof e?s(e):e;if(!n)return null;var r=+n.month+t,a=h(r,12),o=Math.floor(r/12);return 0===a&&--o,{year:l(4,+n.year+o),month:l(2,a||12)}},e.gntMonth=function(e,t){e=+e;for(var n,r=(t=t||{}).splitLen||3,a="string"==typeof t.min?s(t.min):t.min,o="string"==typeof t.max?s(t.max):t.max,i=[],f=Math.ceil(12/r),h={year:l(4,(n=new Date).getFullYear()),month:l(2,n.getMonth()+1),date:l(2,n.getDate())},u=0;u<f;u+=1){i[u]=[];for(var y=0;y<r;y+=1){var m=u*r+y+1;if(12<m)break;i[u].push({year:l(4,e),month:l(2,m),canBeChose:!a&&!o||!!a&&!!o&&(e>+a.year||e===+a.year&&m>=+a.month)&&(e<+o.year||e===+o.year&&m<=+o.month)||!o&&!!a&&(e>+a.year||e===+a.year&&m>=+a.month)||!a&&!!o&&(e<+o.year||e===+o.year&&m<=+o.month),isNow:+h.year===e&&+h.month===m})}}return i},Object.defineProperty(e,"__esModule",{value:!0})});