UNPKG

@fast-china/utils

Version:

Fast 工具库.

3 lines (2 loc) 4.35 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("lodash-unified"),t={getGreet(){const e=(new Date).getHours();let t="";return t=e<5?"夜深了,注意身体哦!":e<9?"早上好!欢迎回来!":e<12?"上午好!欢迎回来!":e<14?"中午好!欢迎回来!":e<18?"下午好!欢迎回来!":e<24?"晚上好!欢迎回来!":"您好!欢迎回来!",t},dateTimeFix(t){if(e.isNil(t))return"";let s;s="string"==typeof t?new Date(t).getTime():"number"==typeof t?t.toString().length<=10?1e3*t:t:t.getTime();const n=36e5,r=(new Date).getTime(),a=r-s,u=Math.abs(a)/6e4,o=Math.abs(a)/n,D=Math.abs(a)/864e5,l=new Date(r),w=new Date(s),g=12*(l.getFullYear()-w.getFullYear())+(l.getMonth()-w.getMonth()),H=a<0?"后":"前";if(Math.abs(g)>=12){return`${Math.floor(Math.abs(g)/12)}${H}`}if(Math.abs(g)>=6)return`半年${H}`;if(Math.abs(g)>=1)return`${Math.abs(g)}${H}`;if(D>=15)return`半月${H}`;if(D>=7){return`${Math.floor(D/7)}${H}`}return D>=1?`${Math.floor(D)}${H}`:o>=1?`${Math.floor(o)}小时${H}`:u>=1?`${Math.floor(u)}分钟${H}`:"刚刚"},getSimpleTime(){const e=new Date;return e.setHours(0,0,0),e},getDefaultTime(e=!1){const t=new Date,s=new Date;return e?t.setMonth(t.getMonth()+1):s.setMonth(s.getMonth()-1),s.setHours(0,0,0),t.setHours(23,59,59),[s,t]},getSimpleShortcuts:(e=!1)=>e?[{text:"今天",value:()=>{const e=new Date;return e.setHours(0,0,0),e}},{text:"明天",value:()=>{const e=new Date;return e.setDate(e.getDate()+1),e.setHours(0,0,0),e}},{text:"一周后",value:()=>{const e=new Date;return e.setDate(e.getDate()+7),e.setHours(0,0,0),e}},{text:"一月后",value:()=>{const e=new Date;return e.setMonth(e.getMonth()+1),e.setHours(0,0,0),e}},{text:"一年后",value:()=>{const e=new Date;return e.setFullYear(e.getFullYear()+1),e.setHours(0,0,0),e}}]:[{text:"今天",value:()=>{const e=new Date;return e.setHours(0,0,0),e}},{text:"昨天",value:()=>{const e=new Date;return e.setDate(e.getDate()-1),e.setHours(0,0,0),e}},{text:"一周前",value:()=>{const e=new Date;return e.setDate(e.getDate()-7),e.setHours(0,0,0),e}},{text:"一月前",value:()=>{const e=new Date;return e.setMonth(e.getMonth()-1),e.setHours(0,0,0),e}},{text:"一年前",value:()=>{const e=new Date;return e.setFullYear(e.getFullYear()-1),e.setHours(0,0,0),e}}],getShortcuts:(e=!1)=>e?[{text:"后1天",value:()=>{const e=new Date,t=new Date;return e.setDate(e.getDate()+1),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"后3天",value:()=>{const e=new Date,t=new Date;return e.setDate(e.getDate()+3),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"后1周",value:()=>{const e=new Date,t=new Date;return e.setDate(e.getDate()+7),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"后1月",value:()=>{const e=new Date,t=new Date;return e.setMonth(e.getMonth()+1),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"后3月",value:()=>{const e=new Date,t=new Date;return e.setMonth(e.getMonth()+3),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"后6月",value:()=>{const e=new Date,t=new Date;return e.setMonth(e.getMonth()+6),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"后1年",value:()=>{const e=new Date,t=new Date;return e.setFullYear(e.getFullYear()+1),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}}]:[{text:"近1天",value:()=>{const e=new Date,t=new Date;return t.setDate(t.getDate()-1),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"近3天",value:()=>{const e=new Date,t=new Date;return t.setDate(t.getDate()-3),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"近1周",value:()=>{const e=new Date,t=new Date;return t.setDate(t.getDate()-7),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"近1月",value:()=>{const e=new Date,t=new Date;return t.setMonth(t.getMonth()-1),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"近3月",value:()=>{const e=new Date,t=new Date;return t.setMonth(t.getMonth()-3),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"近6月",value:()=>{const e=new Date,t=new Date;return t.setMonth(t.getMonth()-6),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}},{text:"近1年",value:()=>{const e=new Date,t=new Date;return t.setFullYear(t.getFullYear()-1),t.setHours(0,0,0),e.setHours(23,59,59),[t,e]}}],getDisabledDate:e=>e.getTime()>Date.now()};exports.dateUtil=t; //# sourceMappingURL=index.js.map