@livelybone/date-generator
Version:
A module that generates calendar, which includes years, months, dates, hours, minutes, seconds
10 lines (8 loc) • 2.43 kB
JavaScript
/**
* 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).utilsDateGenerator={})}(this,function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function u(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"0";return void 0===n&&(n="0"),0<(e-=(t=t.toString()).length)?new Array(e+(/\./.test(t)?2:1)).join(n)+t:t}function i(e,t){return(e%t+t)%t}function n(e){return(e=+e)%4==0&&(e%100!=0||e%400==0)}function a(e,t){return e=+e,2===(t=+t)?n(e)?29:28:Math.ceil(Math.abs(t-7.5))%2==1?31:30}e.fillTo=u,e.getIntervalVal=function(a){return function(e){for(var t=Math.ceil(Math.abs(e&&e.interval||1)),n=Math.ceil(Math.abs(e&&e.min||0)),r=Math.ceil(Math.abs(e&&e.max||a-1)),o=[],i=0;i<=a;i+=t)o.push({value:u(2,i),max:a,canBeChose:n<=i&&i<=r});return o}},e.getMonthLen=a,e.isLeapYear=n,e.isNonNegInt=function(e){return(e=+e)===Math.floor(e)&&0<=e},e.nowDate=function(){var e=new Date;return{year:u(4,e.getFullYear()),month:u(2,e.getMonth()+1),date:u(2,e.getDate())}},e.nowTime=function(){var e=new Date;return{hour:u(2,e.getHours()),minute:u(2,e.getMinutes()),second:u(2,e.getSeconds())}},e.objAssign=function(n,r){return n="object"===t(n)?n:{},r="object"===t(r)?r:{},Object.keys(n).concat(Object.keys(r)).reduce(function(e,t){return t in e||(e[t]=void 0!==r[t]?r[t]:n[t]),e},{})},e.parseDate=function(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=e.match(t),r={year:u(4,n[1]),month:u(2,i(+n[2]||1,12)||12)},o=a(r.year,r.month);return r.date=u(2,i(+n[3]||1,o)||o),r},e.parseTime=function(e){if(!e)return null;var t=/^(\d{1,2}):?(\d{1,2})?:?(\d{1,2})?$/;if(!t.test(e))return console.warn(new Error("Param time `".concat(e,"` is invalid. The right example: 18[:02][:01]"))),null;var n=e.match(t);return{hour:u(2,i(+n[1],24)),minute:u(2,i(+n[2]||0,60)),second:u(2,i(+n[3]||0,60))}},e.positiveMod=i,Object.defineProperty(e,"__esModule",{value:!0})});