app-base-react
Version:
react development common base package.
1 lines • 12.3 kB
JavaScript
"use strict";var _module$exports;function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var getNextDate=function(e,t){t%=7;var n=e.getDay(),r=e.getTime(),t=t-n;return t<=0&&(t+=7),e.setTime(r+=24*t*36e5),e.getFullYear()+"-"+fix(e.getMonth()+1,2)+"-"+fix(e.getDate(),2)},fix=function(e,t){return(""+e).length<t?(new Array(t+1).join("0")+e).slice(-t):""+e},getXDate=function(e,t,n){var e=new Date(e,"0","1"),r=e.getTime();return e.setTime(r+=7*(t-1)*24*36e5),getNextDate(e,n)};module.exports=(_defineProperty(_module$exports={format:function(e){var t,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD hh:mm:ss",r={"M+":(e=this._transferDate(e)).getMonth()+1,"D+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"Q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(t in/(Y+)/.test(n)&&(n=n.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),r)new RegExp("("+t+")").test(n)&&(n=n.replace(RegExp.$1,1===RegExp.$1.length?r[t]:("00"+r[t]).substr((""+r[t]).length)));return n},countTime:function(e,t){var n,r,i,a,s=(e=this._transferDate(e)).getDate(),u=e.getMonth()+1,o=e.getFullYear(),f=e.getHours(),g=e.getMinutes(),h=e.getSeconds();if(o<10&&(o="0"+o),s<10&&(s="0"+s),f<10&&(f="0"+f),g<10&&(g="0"+g),h<10&&(h="0"+h),"year"===t)return o;if("month"===t)return u;if("day"===t)return s;if("hour"===t)return f;if("minute"===t)return g;if("seconds"===t)return h;if("week"===t){var c=void 0;switch(e.getDay()){case 0:c="星期天";break;case 1:c="星期一";break;case 2:c="星期二";break;case 3:c="星期三";break;case 4:c="星期四";break;case 5:c="星期五";break;case 6:c="星期六";break;default:return null}return c}if("daytime"===t){if(f<11&&6<f)return"早晨";if(f<=14&&11<=f)return"中午";if(14<f&&f<19)return"下午";if(19<=f&&f<=23)return"晚上";if(f<6&&0<=f)return"凌晨"}return"when"===t?(t=(e=new Date).getFullYear(),n=e.getMonth()+1,r=e.getDate(),i=e.getHours(),a=e.getMinutes(),e=e.getSeconds(),o<t?t-o+"年前":t===o?u<n?n-u+"个月前":n===u?s<r?r-s+"天前":r===s?f<i?i-f+"小时前":i===f?g<a?a-g+"分钟前":a===g?h<e?e-h+"秒前":e===h?"刚刚":h-e+"秒后":g-a+"分钟后":f-i+"小时后":s-r+"天后":u-n+"个月后":o-t+"年后"):void 0},countDown:function(i,a){var s=null,s=setInterval(function(){var e=0,t=0,n=0,r=0;0<i&&(e=Math.floor(i/86400),t=Math.floor(i/3600)-24*e,n=Math.floor(i/60)-24*e*60-60*t,r=Math.floor(i)-24*e*60*60-60*t*60-60*n),a({day:e=e<=9?"0"+e:e,hour:t=t<=9?"0"+t:t,minute:n=n<=9?"0"+n:n,second:r=r<=9?"0"+r:r}),--i<0&&clearInterval(s)},1e3)},getHMS:function(e){return 3600<e?Math.floor(e/3600)+"小时"+Math.floor(e%3600/60)+"分"+e%60+"秒":60<e?Math.floor(e/60)+"分"+e%60+"秒":60===e?"60秒":e%60+"秒"},countMillisecond:function(e,t){switch(t){case"day":return 24*e*60*60*1e3;case"hour":return 60*e*60*1e3;case"minute":return 60*e*1e3;case"second":return 1e3*e;default:return null}},formatMillisecond:function(e,t){switch(t){case"day":return e/24/60/60/1e3;case"hour":return e/60/60/1e3;case"minute":return e/60/1e3;case"second":return e/1e3;default:return null}},getTime:function(e){return this._transferDate(e).getTime()},getMilliseconds:function(e){return this._transferDate(e).getMilliseconds()},getSeconds:function(e){e=this._transferDate(e).getSeconds();return 9<e?e:"0"+e},getMinutes:function(e){e=this._transferDate(e).getMinutes();return 9<e?e:"0"+e},getHours:function(e){e=this._transferDate(e).getHours();return 9<e?e:"0"+e},getHours12:function(e){e=this._transferDate(e).getHours();return e%12==0?12:e%12},getDay:function(e){e=this._transferDate(e).getDate();return 9<e?e:"0"+e},getWeek:function(e){return this._transferDate(e).getDay()},getMonth:function(e){e=this._transferDate(e).getMonth()+1;return 9<e?e:"0"+e},getPeriod:function(e){e=+this.getMonth(e);return Math.floor((3+e)/3)},getYear:function(e){return this._transferDate(e).getFullYear()},daysOfYear:function(e){var t=this.firstDayOfYear(e),e=this.lastDayOfYear(e);return Math.ceil(this.betweenDay(t,e))},daysOfMonth:function(e){var t=this.firstDayOfMonth(e),e=this.firstDayOfNextMonth(e);return this.betweenDay(t,e)},dayOfYear:function(e){return Math.ceil(this.betweenDay(this.firstDayOfYear(e),e))},dayOfMonth:function(e){return Math.ceil(this.betweenDay(this.firstDayOfMonth(e),e))},weekOfYear:function(e){e=this.dayOfYear(e);return Math.ceil(e/7)},weekOfMonth:function(e){return this.getWeek(e)},firstDayOfYear:function(e){return this.getYear(e)+"-01-01 00:00:00"},lastDayOfYear:function(e){e=this.getYear(e);return e+"-12-"+this.daysOfMonth(e+"-12-01 00:00:00")+" 23:59:59"},firstDayOfMonth:function(e){return this.getYear(e)+"-"+this.getMonth(e)+"-01 00:00:00"},lastDayOfMonth:function(e){var t=this.daysOfMonth(e);return this.getYear(e)+"-"+this.getMonth(e)+"-"+t+" 23:59:59"},firstTimeOfDay:function(e){return this.getYear(e)+"-"+this.getMonth(e)+"-"+this.getDay(e)+" 00:00:00"},lastTimeOfDay:function(e){return this.getYear(e)+"-"+this.getMonth(e)+"-"+this.getDay(e)+" 23:59:59"},firstDayOfWeek:function(e){var t=this.getWeek(e),e=this.minusDays(e,t);return this.getYear(e)+"-"+this.getMonth(e)+"-"+this.getDay(e)+" 00:00:00"},lastDayOfWeek:function(e){var t=6-this.getWeek(e),e=this.minusDays(e,t);return this.getYear(e)+"-"+this.getMonth(e)+"-"+this.getDay(e)+" 23:59:59"},firstDayOfNextMonth:function(e){var t=this.getYear(e),e=this.getMonth(e);return 12<(e=+e+1)&&(t+=1,e-=12),t+"-"+(e=9<e?e:"0"+e)+"-01 00:00:00"},betweenMillSecond:function(e,t){e=this.getTime(this._transferDate(e));return this.getTime(this._transferDate(t))-e},betweenSecond:function(e,t){return Math.floor(this.betweenMillSecond(e,t)/1e3)},betweenMinute:function(e,t){return Math.floor(this.betweenMillSecond(e,t)/6e4)},betweenHour:function(e,t){return Math.floor(this.betweenMillSecond(e,t)/36e5)},betweenDay:function(e,t){var n=24,r=3600,e=this.betweenSecond(e,t),t=n,n=r;return Math.ceil(e/(n*t))},betweenMonth:function(e,t){e=this.betweenDay(e,t);return Math.floor(e/30)},betweenYear:function(e,t){e=this.betweenDay(e,t);return Math.floor(e/365)},plusMillisSeconds:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(+e+ +t))},plusSeconds:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(+e+1e3*t))},plusMinutes:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(+e+60*t*1e3))},plusHours:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e+60*t*60*1e3))},plusDays:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(+e+60*t*60*1e3*24))},plusMonths:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e+30*t*60*60*1e3*24))},plusYears:function(e,t,n){var e=this._transferDate(e).getTime(),r=365,t=t*(r=n?366:r)*60*60*1e3*24;return this._format(new Date(e+t))},minusMillisSeconds:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e-+t))},minusSeconds:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e-1e3*t))},minusMinutes:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e-60*t*1e3))},minusHours:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e-60*t*60*1e3))},minusDays:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e-60*t*60*1e3*24))},minusMonths:function(e,t){e=this._transferDate(e).getTime();return this._format(new Date(e-30*t*60*60*1e3*24))},minusYears:function(e,t,n){var e=this._transferDate(e).getTime(),r=365,t=t*(r=n?366:r)*60*60*1e3*24;return this._format(new Date(e-t))},isEq:function(e,t){return this.getTime(this._transferDate(e))===this.getTime(this._transferDate(t))},isAfter:function(e,t){return this.getTime(this._transferDate(e))<this.getTime(this._transferDate(t))},isBefore:function(e,t){e=this.getTime(this._transferDate(e));return this.getTime(this._transferDate(t))<e},_transferDate:function(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:new Date;return"string"==typeof t?(e=new Date(t))instanceof Date&&!isNaN(e.getTime())?e:new Date(e.replace(/-/g,"/")):t||new Date},_format:function(e){return this.getYear(e)+"-"+this.getMonth(e)+"-"+this.getDay(e)+" "+this.getHours(e)+":"+this.getMinutes(e)+":"+this.getSeconds(e)},getTimestamp:function(){return(new Date).getTime()},getMinute:function(e){e?("string"==typeof e&&(e=e.substring(0,19<e.length?19:e.length)),(i=new Date(e))instanceof Date&&!isNaN(i.getTime())||(i=new Date(e.replace(/-/g,"/")))):i=new Date;try{(0<e.indexOf("T")||0<e.indexOf("Z"))&&i.setHours(i.getHours()-i.getTimezoneOffset()/60)}catch(e){}var e=i.getFullYear(),t=i.getMonth()+1,n=i.getDate(),r=i.getHours(),i=i.getMinutes();return e+"-"+(t=t<=9?"0"+t:t)+"-"+(n=n<=9?"0"+n:n)+" "+(r=r<=9?"0"+r:r)+":"+(i=i<=9?"0"+i:i)},getNow:function(e){e?("string"==typeof e&&(e=e.substring(0,19<e.length?19:e.length)),(a=new Date(e))instanceof Date&&!isNaN(a.getTime())||(a=new Date(e.replace(/-/g,"/")))):a=new Date;try{(0<e.indexOf("T")||0<e.indexOf("Z"))&&a.setHours(a.getHours()-a.getTimezoneOffset()/60)}catch(e){}var e=a.getFullYear(),t=a.getMonth()+1,n=a.getDate(),r=a.getHours(),i=a.getMinutes(),a=a.getSeconds();return e+"-"+(t=t<=9?"0"+t:t)+"-"+(n=n<=9?"0"+n:n)+" "+(r=r<=9?"0"+r:r)+":"+(i=i<=9?"0"+i:i)+":"+(a=a<=9?"0"+a:a)}},"getYear",function(){return(new Date).getFullYear()}),_defineProperty(_module$exports,"getWeek",function(){var e=new Date,t=(n=new Date(e.getFullYear(),0,1)).getDay(),t=0!=t?7-t+1:1,n=new Date(e.getFullYear(),0,1+t),t=Math.ceil((e.valueOf()-n.valueOf())/864e5);return Math.ceil(t/7)+1}),_defineProperty(_module$exports,"getDate",function(e,t){if(t||""==t||(t="-"),!e)return"";"string"==typeof e&&(e=e.substring(0,19<e.length?19:e.length)),(r=new Date(e))instanceof Date&&!isNaN(r.getTime())||(r=new Date(e.replace(/-/g,"/")));try{(0<e.indexOf("T")||0<e.indexOf("Z"))&&r.setHours(r.getHours()-r.getTimezoneOffset()/60)}catch(e){}var e=r.getFullYear(),n=r.getMonth()+1,r=r.getDate();return e+t+(n=n<=9?"0"+n:n)+t+(r=r<=9?"0"+r:r)}),_defineProperty(_module$exports,"getDateTime",function(e){if(!e)return"";"string"==typeof e&&(e=e.substring(0,19<e.length?19:e.length)),(a=new Date(e))instanceof Date&&!isNaN(a.getTime())||(a=new Date(e.replace(/-/g,"/")));try{(0<e.indexOf("T")||0<e.indexOf("Z"))&&a.setHours(a.getHours()-a.getTimezoneOffset()/60)}catch(e){}var e=a.getFullYear(),t=a.getMonth()+1,n=a.getDate(),r=a.getHours(),i=a.getMinutes(),a=a.getSeconds();return e+"-"+(t=t<=9?"0"+t:t)+"-"+(n=n<=9?"0"+n:n)+" "+(r=r<=9?"0"+r:r)+":"+(i=i<=9?"0"+i:i)+":"+(a=a<=9?"0"+a:a)}),_defineProperty(_module$exports,"getYear",function(e){if(!e)return"";"string"==typeof e&&(e=e.substring(0,19<e.length?19:e.length)),(n=new Date(e))instanceof Date&&!isNaN(n.getTime())||(n=new Date(e.replace(/-/g,"/")));try{(0<e.indexOf("T")||0<e.indexOf("Z"))&&n.setHours(n.getHours()-n.getTimezoneOffset()/60)}catch(e){}var e=n.getFullYear(),t=n.getMonth()+1,n=n.getDate();return t<=9&&0,n<=9&&0,e}),_defineProperty(_module$exports,"getTime",function(e){if(!e)return"";"string"==typeof e&&(e=e.substring(0,19<e.length?19:e.length)),(n=new Date(e))instanceof Date&&!isNaN(n.getTime())||(n=new Date(e.replace(/-/g,"/")));try{(0<e.indexOf("T")||0<e.indexOf("Z"))&&n.setHours(n.getHours()-n.getTimezoneOffset()/60)}catch(e){}var e=n.getHours(),t=n.getMinutes(),n=n.getSeconds();return(e=e<=9?"0"+e:e)+":"+(t=t<=9?"0"+t:t)+":"+(n=n<=9?"0"+n:n)}),_defineProperty(_module$exports,"getPreMonth",function(e){var e=e.split("-"),t=e[0],n=e[1],e=e[2],n=(new Date(t,n,0).getDate(),parseInt(n)-1),r=(0==n&&(t=parseInt(t)-1,n=12),new Date(t,n,0));return t+"-"+(n=n<10?"0"+n:n)+"-"+(e=(r=r.getDate())<e?r:e)}),_defineProperty(_module$exports,"getNextMonth",function(e){var e=e.split("-"),t=e[0],n=e[1],e=e[2],n=(new Date(t,n,0).getDate(),parseInt(n)+1),r=(13==n&&(t=parseInt(t)+1,n=1),new Date(t,n,0));return t+"-"+(n=n<10?"0"+n:n)+"-"+(e=(r=r.getDate())<e?r:e)}),_defineProperty(_module$exports,"getDateRange",function(e,t){return null==e||""==e||null==t||""==t?"":[getXDate(e,t-=1,5),getXDate(e,+t+1,4)]}),_defineProperty(_module$exports,"getStrDate",function(e){return e&&14===e.length?(0,e.substring(0,4)+"-"+e.substring(4,6)+"-"+e.substring(6,8)+" "+e.substring(8,10)+":"+e.substring(10,12)+":"+e.substring(12,14)):""}),_module$exports);