@luke-zhang-04/dateplus
Version:
A simple program to assist with date manipulation
8 lines (7 loc) • 4.26 kB
JavaScript
/**
* DatePlus v4.0.0-beta2 | A simple program to assist with date manipulation
* @copyright Copyright (C) 2020 - 2021 Luke Zhang
* @license MIT
*/
const e=e=>({ms:e%1e3,seconds:(e-e%1e3)/1e3}),t=e,r=e=>{const t=e%1e3%1e3,r=(e-e%1e3)/1e3%60;return{ms:t,seconds:r,minutes:(e-1e3*r-t)/6e4}},s=r,a=e=>{const t=e%1e3%1e3,r=(e-e%1e3)/1e3%60,s=(e-1e3*r-t)/6e4%60;return{ms:t,seconds:r,minutes:s,hours:(e-1e3*s*60-1e3*r-t)/36e5}},n=a,o=e=>{const t=e%1e3%1e3,r=(e-e%1e3)/1e3%60,s=(e-1e3*r-t)/6e4%60,a=(e-1e3*s*60-1e3*r-t)/36e5%24;return{ms:t,seconds:r,minutes:s,hours:a,days:(e-1e3*a*60*60-1e3*s*60-1e3*r-t)/864e5}},u=e=>1e3*e,d=u,h=e=>r(u(e)),y=h,i=e=>a(u(e)),m=i,c=e=>o(u(e)),M=c,g=e=>60*e*1e3,l=c,b=e=>60*e,p=b,D=e=>a(g(e)),f=D,E=e=>o(g(e)),S=E,N=e=>60*e*60*1e3,P=N,x=e=>60*e*60,J=x,W=e=>60*e,A=W,F=e=>o(N(e)),H=F,T=e=>24*e*60*60*1e3,k=e=>24*e*60*60,v=k,w=e=>24*e*60,O=w,Z=e=>24*e,j=Z,q={hrsPerDay:24,minsPerHr:60,secsPerMin:60,msPerSec:1e3},z={0:"Sunday",1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday"},B={0:"January",1:"Feburary",2:"March",3:"April",4:"May",5:"June",6:"July",7:"August",8:"September",9:"October",10:"November",11:"December"},C=6e4,G=36e5,I=864e5,K={y:"year",m:"month",d:"day"},L=(e,t="/")=>e.split(t).map((e=>e.length<2?"0".concat(e):e)).join(t),Q=(e,t="y:m:d",r="/")=>{const s={m:(e.getMonth()+1).toString(),d:e.getDate().toString(),y:e.getFullYear().toString()};return t.split(":").map((e=>s[e])).join(r)},R=(e,t="y:m:d",r="auto")=>{let s="/";if("auto"===r){for(const t of e)if(isNaN(Number(t))){s=t;break}}else s=r;const a=e.split(s),n=t.split(":"),o={};for(let e=0;e<3;e++){o[K[n[e]]]=Number(a[e])}return o},U=e=>z[e],V=e=>B[e],X=(e,t)=>-1*Math.round((e.getTime()-t.getTime())/864e5),Y=(e,t)=>-1*Math.round((e.getTime()-t.getTime())/36e5),$=(e,t)=>-1*Math.round((e.getTime()-t.getTime())/6e4),_=(e,t)=>-1*Math.round((e.getTime()-t.getTime())/1e3),ee=(e,t)=>-1*Math.round(e.getTime()-t.getTime()),te=(e,t,r="about")=>{const s=2592e6,a=31536e6,n=ee(e,t);let o;return n<6e4?(o=Math.round(n/1e3),"".concat(o," second").concat(1===o?"":"s"," ago")):n<36e5?(o=Math.round(n/6e4),"".concat(o," minute").concat(1===o?"":"s"," ago")):n<864e5?(o=Math.round(n/36e5),"".concat(o," hour").concat(1===o?"":"s"," ago")):n<s?(o=Math.round(n/864e5),"".concat(r," ").concat(o," day").concat(1===o?"":"s"," ago")):n<a?(o=Math.round(n/s),"".concat(r," ").concat(o," month").concat(1===o?"":"s"," ago")):(o=Math.round(n/a),"".concat(r," ").concat(o," year").concat(1===o?"":"s"," ago"))},re=e=>{const t=e.constructor(e.getTime());return t.setMinutes(e.getMinutes()-e.getTimezoneOffset()),t},se=()=>{const e=new Date;return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())};class ae extends Date{addZeros(e="/"){return L(this.formatDate(),e)}formatDate(e="y:m:d",t="/"){return Q(this,e,t)}getWordDay(){return z[this.getDay()]}getWordMonth(){return B[this.getMonth()]}getElapsedDays(e){return X(this,e)}getElapsedHours(e){return Y(this,e)}getElapsedMinutes(e){return $(this,e)}getElapsedSeconds(e){return _(this,e)}getElapsedMs(e){return ee(this,e)}getElapsedString(e,t="about"){return te(this,e,t)}}export default ae;export{ae as DatePlus,L as addZeros,z as daysReference,j as daysToHours,Z as daysToHrs,w as daysToMins,O as daysToMinutes,T as daysToMs,v as daysToSeconds,k as daysToSecs,Q as formatDate,R as getDateValues,X as getElapsedDays,Y as getElapsedHours,$ as getElapsedMinutes,ee as getElapsedMs,_ as getElapsedSeconds,te as getElapsedString,se as getUtcTime,U as getWordDay,V as getWordMonth,H as hoursToDays,A as hoursToMinutes,P as hoursToMs,J as hoursToSeconds,F as hrsToDays,W as hrsToMins,N as hrsToMs,x as hrsToSecs,E as minsToDays,D as minsToHrs,g as minsToMs,b as minsToSecs,S as minutesToDays,f as minutesToHours,l as minutesToMs,p as minutesToSeconds,B as monthsReference,o as msToDays,n as msToHours,a as msToHrs,r as msToMins,s as msToMinutes,t as msToSeconds,e as msToSecs,I as oneDay,G as oneHour,C as oneMinute,M as secondsToDays,m as secondsToHours,y as secondsToMinutes,d as secondsToMs,c as secsToDays,i as secsToHrs,h as secsToMins,u as secsToMs,re as utcToLocal,q as values};
//# sourceMappingURL=dateplus.min.js.map