Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aio-date

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aio-date - npm Package Compare versions

Comparing version 4.1.0 to 5.0.0

index.d.ts

58

index.js

@@ -1,57 +0,1 @@

export default function e(){let e={isMatch(t){if(!t||!Array.isArray(t.matchers)||void 0===t.date)return console.error("AIODate().isMatch should get an object as parameter. {*date:number | string | array,*matchers:array}",t),!1;let{date:r,matchers:a}=t;if(!r)return!1;if(!0===a)return!0;if(!1===a)return!1;r=e.convertToArray({date:r});let{isLess:n,isGreater:o,isEqual:i}=e;for(let g=0;g<a.length;g++){let l=a[g],s,$;try{let _=l.split(",");s=_[0],$=_.slice(1,_.length)}catch{break}if("<"===s){for(let d=0;d<$.length;d++)if(n(r,$[d]))return!0}else if(">"===s){for(let u=0;u<$.length;u++)if(o(r,$[u]))return!0}else if("<="===s){for(let y=0;y<$.length;y++)if(i(r,$[y])||n(r,$[y]))return!0}else if(">="===s){for(let f=0;f<$.length;f++)if(i(r,$[f])||o(r,$[f]))return!0}else if("="===s){for(let D=0;D<$.length;D++)if(i(r,$[D]))return!0}else if("!="===s){for(let h=0;h<$.length;h++)if(!i(r,$[h]))return!0}else if("<>"===s){if($[0]&&$[1]){let p,c;if(n($[0],$[1])?(p=$[0],c=$[1]):(p=$[1],c=$[0]),o(r,p)&&n(r,c))return!0}}else if("<=>"===s){if($[0]&&$[1]){let m,T;if(n($[0],$[1])?(m=$[0],T=$[1]):(m=$[1],T=$[0]),o(r,m)&&n(r,T)||i(r,m)||i(r,T))return!0}}else if("!<>"===s){if($[0]&&$[1]){let A,M;if(n($[0],$[1])?(A=$[0],M=$[1]):(A=$[1],M=$[0]),!o(r,A)||!n(r,M))return!0}}else if("!<=>"===s){if($[0]&&$[1]){let b,v;if(n($[0],$[1])?(b=$[0],v=$[1]):(b=$[1],v=$[0]),!i(r,b)&&!i(r,v)&&(n(r,b)||o(r,v)))return!0}}else if("w"===s){let O=e.getWeekDay({date:r}).index;for(let j=0;j<$.length;j++)if(O===+$[j])return!0}else if("!w"===s){let x=e.getWeekDay({date:r}).index;for(let L=0;L<$.length;L++)if(x!==+$[L])return!0}}return!1},getSplitter(e){for(let t=0;t<e.length;t++)if(isNaN(parseInt(e[t])))return e[t];return"/"},convertToArray(t){if(!t||void 0===t.date)return console.error(`
AIODate().convertToArray should get an object as parameter.
{
*date:number | string | array
}`,t),!1;let{date:r,jalali:a}=t;if(!r)return!1;let n;if(Array.isArray(r))n=[...r];else if("string"==typeof r){if(-1!==r.indexOf("T")){let[o,i]=r.split("T");i=(i=i.split(".")[0]).split(":"),n=(o=o.split("-")).concat(i,0)}else n=r.split(e.getSplitter(r));n=n.map(e=>parseInt(e))}else if("number"==typeof r){let g=new Date(r),l=g.getFullYear(),s=g.getMonth()+1,$=g.getDate(),_=g.getHours(),d=g.getMinutes(),u=g.getSeconds(),y;n=[l,s,$,_,d,u,Math.round(g.getMilliseconds()/100)]}else{if("object"!=typeof r)return!1;if("number"==typeof r.year)return[r.year,r.month,r.day,r.hour];{let f=r.getFullYear(),D=r.getMonth()+1,h=r.getDate(),p=r.getHours(),c=r.getMinutes(),m=r.getSeconds(),T;n=[f,D,h,p,c,m,Math.round(r.getMilliseconds()/100)]}}if(a){let[A,M,b]=e.toJalali({date:[n[0],n[1],n[2]]});n[0]=A,n[1]=M,n[2]=b}return n},toJalali(t){var r,a,n,o,i,g;if(!t||void 0===t.date)return console.error(`
AIODate().toJalali should get an object as parameter.
{
*date:number | string | array ,
pattern:string (example: {year}/{month}/{day})
}`,t),!1;if(!t.date)return;let l=e.convertToArray({date:t.date});if("jalali"===e.getCalendarType(l))return l;let[s,$,_]=l;return(r=[0,31,59,90,120,151,181,212,243,273,304,334],i=$>2?s+1:s,a=-1595+33*~~((g=355666+365*s+~~((i+3)/4)-~~((i+99)/100)+~~((i+399)/400)+_+r[$-1])/12053),g%=12053,a+=4*~~(g/1461),(g%=1461)>365&&(a+=~~((g-1)/365),g=(g-1)%365),g<186?(n=1+~~(g/31),o=1+g%31):(n=7+~~((g-186)/30),o=1+(g-186)%30),l[0]=a,l[1]=n,l[2]=o,t.pattern)?e.pattern(l,t.pattern):l},toGregorian(t){var r,a,n,o,i;if(!t||void 0===t.date)return console.error(`
AIODate().toGregorian should get an object as parameter.
{
*date:number | string | array ,
pattern:string (example: {year}/{month}/{day})
}`,t),!1;if(!t.date)return;let g=e.convertToArray({date:t.date});if("gregorian"===e.getCalendarType(g))return g;let[l,s,$]=g;for(l+=1595,a=400*~~((i=-355668+365*l+8*~~(l/33)+~~((l%33+3)/4)+$+(s<7?(s-1)*31:(s-7)*30+186))/146097),(i%=146097)>36524&&(a+=100*~~(--i/36524),(i%=36524)>=365&&i++),a+=4*~~(i/1461),(i%=1461)>365&&(a+=~~((i-1)/365),i=(i-1)%365),o=i+1,r=[0,31,a%4==0&&a%100!=0||a%400==0?29:28,31,30,31,30,31,31,30,31,30,31],n=0;n<13&&o>r[n];n++)o-=r[n];return(g[0]=a,g[1]=n,g[2]=o,t.pattern)?e.pattern(g,t.pattern):g},compaire(t){if(!t||void 0===t.date||void 0===t.otherDate)return console.error(`
AIODate().compaire should get an object as parameter.
{
*date:number | string | array ,
*otherDate:number | string | array ,
}
and returns 'greater' | 'less' | 'equal'
`,t),!1;let{date:r,otherDate:a}=t;if(!r||!a)return;let n=e.convertToArray({date:r}),o=e.convertToArray({date:a});for(let i=0;i<n.length;i++){let g=n[i],l=o[i]||0;if(g<l)return"less";if(g>l)return"greater"}return"equal"},getToCompaire(t,r){t=e.convertToArray({date:t}),r=e.convertToArray({date:r});for(let a=0;a<t.length;a++)isNaN(r[a])&&(r[a]=t[a]);return{date:t,otherDate:r}},isLess:(t,r)=>!!t&&!!r&&"less"===e.compaire(e.getToCompaire(t,r)),isEqual:(t,r)=>!!t&&!!r&&"equal"===e.compaire(e.getToCompaire(t,r)),isGreater:(t,r)=>!!t&&!!r&&"greater"===e.compaire(e.getToCompaire(t,r)),isBetween:(t,[r,a])=>!!t&&!!r&&!!a&&e.isGreater(t,r)&&e.isLess(t,a),getTime(t){if(!t||void 0===t.date)return console.error(`
AIODate().getTime should get an object as parameter.
{
*date:number | string | array ,
}`,t),!1;let{date:r,calendarType:a}=t;if(!r)return;if(a=a||e.getCalendarType(r),"number"==typeof r)return r;let[n,o=1,i=1,g=0,l=0,s=0,$=0]=r=e.convertToArray({date:r});"jalali"===a&&(r=e.toGregorian({date:[n,o,i,g,l,s,$]}));let _=new Date(r[0],r[1]-1,r[2]).getTime();return _+=36e5*g,_+=6e4*l,_+=1e3*s,_+=100*$},getNextTime(t){if(!t||void 0===t.date||isNaN(t.offset))return console.error(`
AIODate().getNextTime should get an object as parameter.
{
*date:number | string | array ,
*offset : number(miliseconds) ,
jalali : boolean(return result by jalali date),
pattern:string (example: {year}/{month}/{day})
}`,t),!1;let{date:r,offset:a,pattern:n}=t;if(!a||!r)return r;let o=e.getCalendarType(r),i=e.getTime({date:r,calendarType:o});if(i+=a,i=e.convertToArray({date:i}),"jalali"===o||t.jalali){let[g,l,s]=e.toJalali({date:i});i[0]=g,i[1]=l,i[2]=s}return n?e.pattern(i,n):i},GetMonthDaysLength:{jalali:(e,t)=>t<=6?31:t<=11?30:-1===[1,5,9,13,17,22,26,30].indexOf(e%33)?29:30,gregorian:(e,t)=>new Date(e,t-1,0).getDate()},getMonthDaysLength(t){if(!t||void 0===t.date)return console.error(`
AIODate().getMonthDaysLength should get an object as parameter.
{
*date:number | string | array
}
`,t),!1;let{date:r}=t;if(!r)return;let[a,n]=e.convertToArray({date:r});return e.GetMonthDaysLength[e.getCalendarType([a,n])](a,n)},getYearDaysLength(t){if(!t||void 0===t.date)return console.error(`
AIODate().getYearDaysLength should get an object as parameter.
{
*date:number | string | array
}
`,t),!1;let{date:r}=t;if(!r)return;let[a]=e.convertToArray({date:r}),n=0;for(let o=1;o<=12;o++)n+=e.getMonthDaysLength({date:[a,o]});return n},getCalendarType:t=>e.convertToArray({date:t})[0]<1700?"jalali":"gregorian",getWeekDay(t){if(!t||!t.date)return console.error("AIODate().getWeekDay should get an object as parameter. {*date:string | array}",t),!1;let r=e.convertToArray({date:t.date}),a=e.getCalendarType(r);r=e.toGregorian({date:r});let n=new Date(r[0],r[1]-1,r[2]).getDay();return"jalali"===a&&(n+=1,n%=7),{weekDay:e.getWeekDays({calendarType:a})[n],index:n}},getDaysOfWeek(t){if(!t||!t.date)return console.error("AIODate().getDaysOfWeek should get an object as parameter. {*date:string | array}",t),!1;let{index:r}=e.getWeekDay({date:t.date}),a=e.getNextTime({date:[t.date[0],t.date[1],t.date[2]],offset:-(864e5*(r+1))}),n=e.getNextTime({date:[t.date[0],t.date[1],t.date[2]],offset:(7-r)*864e5});return e.getDatesBetween({date:a,otherDate:n,pattern:t.pattern,step:864e5})},getDaysOfMonth(t){if(!t||!t.date)return console.error("AIODate().getLastDayOfMonth should get an object as parameter. {*date:string | array}",t),!1;let r=e.convertToArray({date:t.date}),a=[r[0],r[1],1],n=e.getLastDayOfMonth({date:r}),o=e.getDatesBetween({date:a,otherDate:n,step:864e5}),i=[a];return((i=i.concat(o)).push(n),t.pattern)?i.map(r=>e.getDateByPattern({date:r,pattern:t.pattern})):i},getLastDayOfMonth(t){if(!t||!t.date)return console.error("AIODate().getLastDayOfMonth should get an object as parameter. {*date:string | array}",t),!1;let r=e.convertToArray({date:t.date}),a=e.getMonthDaysLength({date:r}),n=[r[0],r[1],a];return t.pattern?e.getDateByPattern({date:n,pattern:t.pattern}):n},getWeekDays:({calendarType:e})=>({jalali:["شنبه","یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه"],gregorian:["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]})[e],getMonths:({calendarType:e})=>({jalali:["فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند",],gregorian:["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"]})[e],getDatesBetween(t){if(!t||void 0===t.date||void 0===t.otherDate)return console.error(`
AIODate().getDatesBetween should get an object as parameter.
{
*date:number | array | string,
*otherDate:number | array | string,
*step:number(miliseconds. default is 24 * 60 * 60 * 1000),
pattern:string (example '{year/{month}/{day}}')
}`),!1;let{date:r,otherDate:a,step:n=864e5,pattern:o}=t;if(r=e.convertToArray({date:r}),a=e.convertToArray({date:a}),!e.isGreater(a,r))return[];let i=e.getDelta({date:r,otherDate:a}).miliseconds/n;if(isNaN(i)||i>1e3){console.error("AIODate().getDatesBetween() => too many dates");return}let g=e.getNextTime({date:r,offset:n}),l=[];for(;e.isLess(g,a);)o?l.push(e.pattern(g,o)):l.push(g),g=e.getNextTime({date:g,offset:n});return l},getToday(t){if(!t||-1===["jalali","gregorian"].indexOf(t.calendarType))return console.error("AIODate().getToday should get an object as parameter. {*calendarType:'gregorian' | 'jalali',pattern:string}"),!1;let r=new Date;return(r=[r.getFullYear(),r.getMonth()+1,r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds(),Math.round(r.getMilliseconds()/100)],"jalali"===t.calendarType&&(r=e.toJalali({date:r})),t.pattern)?e.pattern(r,t.pattern):r},getDateByPattern(t){if(!t||!t.date||"string"!=typeof t.pattern)return console.error("AIODate().getDateByPattern should get an object as parameter. {*date:number | string | array,*pattern:string}"),!1;let{date:r,pattern:a,jalali:n}=t;return e.pattern(r,a,n)},pattern(t,r,a){let[n,o,i,g,l,s,$]=t=e.convertToArray({date:t,jalali:a}),_=e.getCalendarType(t);if(r=r.replace("{year}",n),"number"==typeof o&&(r=r.replace("{month}",e.get2Digit(o))),"number"==typeof i&&(r=r.replace("{day}",e.get2Digit(i))),"number"==typeof g&&(r=r.replace("{hour}",e.get2Digit(g))),"number"==typeof l&&(r=r.replace("{minute}",e.get2Digit(l))),"number"==typeof s&&(r=r.replace("{second}",e.get2Digit(s))),"number"==typeof $&&(r=r.replace("{tenthsecond}",e.get2Digit($))),-1!==r.indexOf("{monthString}")&&(r=r.replace("{monthString}",e.getMonths({calendarType:_})[o-1])),-1!==r.indexOf("{weekDay}")){let d=e.getWeekDays({calendarType:_}),{index:u}=e.getWeekDay({date:t});r=r.replace("{weekDay}",d[u])}return r},convertMiliseconds({miliseconds:t=0,unit:r="day",pattern:a}){let n;t<0?(n="passed",t=-t):n=t>0?"remaining":"now";let o=["day","hour","minute","second","tenthsecond","milisecond"].indexOf(r),i=0,g=0,l=0,s=0,$=0,_=t;return(o<=0&&(i=Math.floor(_/864e5),_-=864e5*i),o<=1&&(g=Math.floor(_/36e5),_-=36e5*g),o<=2&&(l=Math.floor(_/6e4),_-=6e4*l),o<=3&&(s=Math.floor(_/1e3),_-=1e3*s),o<=4&&($=Math.floor(_/100)),a)?e.pattern([0,0,i,g,l,s,$],a):{day:i,hour:g,minute:l,second:s,tenthsecond:$,miliseconds:t,type:n}},getDelta(t){if(!t||!t.date)return console.error(`
AIODate().getDelta should get an object as parameter.
{
*date:number | string | array,
otherDate:number | string | array, (default is now),
pattern:string (example: '{year}/{month}/{day}'),
unit:'day' | 'hour' | 'minute' | 'second' | 'tenthsecond' | 'milisecond'
}`),!1;let{date:r,otherDate:a=new Date().getTime(),pattern:n,unit:o}=t,i=e.getTime({date:r})-e.getTime({date:a});return e.convertMiliseconds({miliseconds:-i,unit:o,pattern:n})},getByOffset({date:t,offset:r,unit:a="day",calendarType:n="gregorian"}){if(!r)return t;let o=e["get"+(r>0?"Next":"Prev")+({hour:"Hour",day:"Day",month:"Month",year:"Year"})[a]],i=Math.abs(r);for(let g=0;g<i;g++)t=o(t,n);return t},getNextYear:([e,t])=>[e+1,t,1,0],getPrevYear:([e,t])=>[e-1,t,1,0],getNextHour([t,r,a,n],o){if(n<23)return[t,r,a,n+1];let i=e.getNextDay([t,r,a],o);return[i[0],i[1],i[2],0]},getPrevHour([t,r,a,n],o){if(n>0)return[t,r,a,n-1];let i=e.getPrevDay([t,r,a],o);return[i[0],i[1],i[2],23]},getNextDay:([t,r,a,n])=>a<e.getMonthDaysLength({date:[t,r]})?[t,r,a+1,n]:r<12?[t,r+1,1,n]:[t+1,1,1,n],getPrevDay:([t,r,a,n],o)=>a>1?[t,r,a-1]:r>1?(r-=1,a=e.getMonthDaysLength({date:[t,r]}),[t,r,a,n]):(t-=1,r=12,a=e.getMonthDaysLength({date:[t,r]}),[t,r,a,n]),getDayIndex({date:t,unit:r}){if(t=e.convertToArray({date:t}),"week"===r){let a=e.getDaysOfWeek({date:t});for(let n=0;n<a.length;n++){let[o,i,g]=a[n];if(o===t[0]&&i===t[1]&&g===t[2])return n}}if("month"===r)return t[2]-1;if("year"===r){let l=0;for(let s=0;s<t[1]-1;s++)l+=e.getMonthDaysLength({date:t});return(l+=t[1])-1}},getNextMonth:([e,t,r,a])=>t<12?[e,t+1,r,a]:[e+1,1,1],getPrevMonth:([e,t,r,a])=>t>1?[e,t-1,r,a]:[e-1,12,1],get2Digit(e){let t;try{t=e.toString()}catch{return e}return 1===t.length&&(t="0"+e),t}};return{getDaysOfWeek:e.getDaysOfWeek,getDaysOfMonth:e.getDaysOfMonth,getLastDayOfMonth:e.getLastDayOfMonth,getByOffset:e.getByOffset,getDayIndex:e.getDayIndex,toJalali:e.toJalali,toGregorian:e.toGregorian,getTime:e.getTime,getSplitter:e.getSplitter,convertToArray:e.convertToArray,compaire:e.compaire,isEqual:e.isEqual,isGreater:e.isGreater,getDelta:e.getDelta,convertMiliseconds:e.convertMiliseconds,isLess:e.isLess,isBetween:e.isBetween,getMonthDaysLength:e.getMonthDaysLength,getYearDaysLength:e.getYearDaysLength,getWeekDay:e.getWeekDay,getWeekDays:e.getWeekDays,getMonths:e.getMonths,getToday:e.getToday,isMatch:e.isMatch,getNextTime:e.getNextTime,getDatesBetween:e.getDatesBetween,getDateByPattern:e.getDateByPattern,get2Digit:e.get2Digit}};
"use strict";function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:t+""}function _toPrimitive(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.AIODate=void 0;class AIODate{constructor(){_defineProperty(this,"isMatch",void 0),_defineProperty(this,"convertToArray",void 0),_defineProperty(this,"isLess",void 0),_defineProperty(this,"isGreater",void 0),_defineProperty(this,"isEqual",void 0),_defineProperty(this,"isBetween",void 0),_defineProperty(this,"compaire",void 0),_defineProperty(this,"getWeekDay",void 0),_defineProperty(this,"isToday",void 0),_defineProperty(this,"isJalali",void 0),_defineProperty(this,"getWeekDays",void 0),_defineProperty(this,"toGregorian",void 0),_defineProperty(this,"toJalali",void 0),_defineProperty(this,"pattern",void 0),_defineProperty(this,"get2Digit",void 0),_defineProperty(this,"getMonths",void 0),_defineProperty(this,"getSplitter",void 0),_defineProperty(this,"getTime",void 0),_defineProperty(this,"getNextTime",void 0),_defineProperty(this,"getMonthDaysLength",void 0),_defineProperty(this,"getYearDaysLength",void 0),_defineProperty(this,"getDaysOfWeek",void 0),_defineProperty(this,"getDatesBetween",void 0),_defineProperty(this,"getDelta",void 0),_defineProperty(this,"convertMiliseconds",void 0),_defineProperty(this,"getDaysOfMonth",void 0),_defineProperty(this,"getLastDayOfMonth",void 0),_defineProperty(this,"getDateByPattern",void 0),_defineProperty(this,"getToday",void 0),_defineProperty(this,"getDayIndex",void 0),_defineProperty(this,"getYesterday",void 0),_defineProperty(this,"getTomarrow",void 0),_defineProperty(this,"toMiliseconds",void 0),_defineProperty(this,"getDateByDeltaMiliseconds",void 0),this.toMiliseconds=e=>{let{day:t=0,hour:i=0,minute:r=0,second:s=0}=e,o=0;return o+=864e5*t,o+=36e5*i,o+=6e4*r,o+=1e3*s},this.isMatch=(e,t)=>{e=this.convertToArray(e);for(let i=0;i<t.length;i++){let r=t[i],s,o;try{let n=r.split(",");s=n[0],o=n.slice(1,n.length)}catch{break}if("<"===s){for(let $=0;$<o.length;$++)if(this.isLess(e,o[$]))return!0}else if(">"===s){for(let h=0;h<o.length;h++)if(this.isGreater(e,o[h]))return!0}else if("<="===s){for(let a=0;a<o.length;a++)if(this.isEqual(e,o[a])||this.isLess(e,o[a]))return!0}else if(">="===s){for(let l=0;l<o.length;l++)if(this.isEqual(e,o[l])||this.isGreater(e,o[l]))return!0}else if("="===s){for(let f=0;f<o.length;f++)if(this.isEqual(e,o[f]))return!0}else if("!="===s){for(let g=0;g<o.length;g++)if(!this.isEqual(e,o[g]))return!0}else if("<>"===s){if(o[0]&&o[1]){let y,_;if(this.isLess(o[0],o[1])?(y=o[0],_=o[1]):(y=o[1],_=o[0]),this.isGreater(e,y)&&this.isLess(e,_))return!0}}else if("<=>"===s){if(o[0]&&o[1]){let d,u;if(this.isLess(o[0],o[1])?(d=o[0],u=o[1]):(d=o[1],u=o[0]),this.isGreater(e,d)&&this.isLess(e,u)||this.isEqual(e,d)||this.isEqual(e,u))return!0}}else if("!<>"===s){if(o[0]&&o[1]){let p,c;if(this.isLess(o[0],o[1])?(p=o[0],c=o[1]):(p=o[1],c=o[0]),!this.isGreater(e,p)||!this.isLess(e,c))return!0}}else if("!<=>"===s){if(o[0]&&o[1]){let v,D;if(this.isLess(o[0],o[1])?(v=o[0],D=o[1]):(v=o[1],D=o[0]),!this.isEqual(e,v)&&!this.isEqual(e,D)&&(this.isLess(e,v)||this.isGreater(e,D)))return!0}}else if("w"===s){let m=this.getWeekDay(e).index;for(let T=0;T<o.length;T++)if(m===+o[T])return!0}else if("!w"===s){let P=this.getWeekDay(e).index;for(let A=0;A<o.length;A++)if(P!==+o[A])return!0}}return!1},this.convertToArray=(e,t)=>{if(!e)return[];let i;if(Array.isArray(e))i=[...e];else if("string"==typeof e){if(-1!==e.indexOf("T")){let[r,s]=e.split("T"),o=s.split(".")[0].split(":");i=[...r.split("-").map(e=>+e),...o.map(e=>+e),0]}else i=e.split(this.getSplitter(e)).map(e=>+e)}else if("number"==typeof e){let n=new Date(e),$=n.getFullYear(),h=n.getMonth()+1,a=n.getDate(),l=n.getHours(),f=n.getMinutes(),g;i=[$,h,a,l,f,n.getSeconds(),Math.round(n.getMilliseconds()/100)]}else if("object"!=typeof e)return[];else if("function"==typeof e.getMonth){let y=e,_=y.getFullYear(),d=y.getMonth()+1,u=y.getDate(),p=y.getHours(),c=y.getMinutes(),v;i=[_,d,u,p,c,y.getSeconds(),Math.round(y.getMilliseconds()/100)]}else{let D=this.getToday(t),m=e;return[void 0===m.year?D[0]:m.year,void 0===m.month?D[1]:m.month,void 0===m.day?D[2]:m.day,void 0===m.hour?D[3]:m.hour,void 0===m.minute?D[4]:m.minute,void 0===m.second?D[5]:m.second]}if(t){let[T,P,A]=this.toJalali([i[0],i[1],i[2]]);i[0]=T,i[1]=P,i[2]=A}return i},this.compaire=(e,t)=>{e=this.convertToArray(e),t=this.convertToArray(t);let i="equal";for(let r=0;r<e.length;r++){isNaN(t[r])&&(t[r]=e[r]);let s=e[r],o=t[r]||0;if(s<o){i="less";break}if(s>o){i="greater";break}}return i},this.isLess=(e,t)=>"less"===this.compaire(e,t),this.isEqual=(e,t)=>"equal"===this.compaire(e,t),this.isGreater=(e,t)=>"greater"===this.compaire(e,t),this.isBetween=(e,[t,i])=>"greater"===this.compaire(e,t)&&"less"===this.compaire(e,t),this.isToday=e=>this.isEqual(e,this.getToday(this.isJalali(e))),this.getDateByDeltaMiliseconds=(e,t)=>this.convertToArray(this.getTime(e)+t),this.getWeekDay=e=>{let t=this.convertToArray(e),i=this.isJalali(t);t=this.toGregorian(e);let r=new Date(t[0],t[1]-1,t[2]).getDay();return i&&(r+=1,r%=7),{weekDay:this.getWeekDays(i)[r],index:r}},this.isJalali=e=>this.convertToArray(e)[0]<1700,this.getWeekDays=e=>[["شنبه","یکشنبه","دوشنبه","سه شنبه","چهارشنبه","پنجشنبه","جمعه"],["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]][e?0:1],this.toGregorian=e=>{var t,i,r,s,o;if(!e)return[];let n=this.convertToArray(e);if(!this.isJalali(n))return n;let[$,h,a]=n;for($+=1595,i=400*~~((o=-355668+365*$+8*~~($/33)+~~(($%33+3)/4)+a+(h<7?(h-1)*31:(h-7)*30+186))/146097),(o%=146097)>36524&&(i+=100*~~(--o/36524),(o%=36524)>=365&&o++),i+=4*~~(o/1461),(o%=1461)>365&&(i+=~~((o-1)/365),o=(o-1)%365),s=o+1,t=[0,31,i%4==0&&i%100!=0||i%400==0?29:28,31,30,31,30,31,31,30,31,30,31],r=0;r<13&&s>t[r];r++)s-=t[r];return n[0]=i,n[1]=r,n[2]=s,n},this.pattern=(e,t,i=this.isJalali(e))=>{let[r,s,o,n,$,h,a]=e=this.convertToArray(e,i);if(t=t.replace("{year}",r.toString()),"number"==typeof s&&(t=t.replace("{month}",this.get2Digit(s))),"number"==typeof o&&(t=t.replace("{day}",this.get2Digit(o))),"number"==typeof n&&(t=t.replace("{hour}",this.get2Digit(n))),"number"==typeof $&&(t=t.replace("{minute}",this.get2Digit($))),"number"==typeof h&&(t=t.replace("{second}",this.get2Digit(h))),"number"==typeof a&&(t=t.replace("{tenthsecond}",this.get2Digit(a))),-1!==t.indexOf("{monthString}")&&(t=t.replace("{monthString}",this.getMonths(i)[s-1])),-1!==t.indexOf("{weekDay}")){let l=this.getWeekDays(i),{index:f}=this.getWeekDay(e);t=t.replace("{weekDay}",l[f])}return t},this.get2Digit=e=>{let t;try{t=e.toString()}catch{return e.toString()}return 1===t.length&&(t="0"+e),t},this.getMonths=e=>[["فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"],["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"]][e?0:1],this.toJalali=e=>{var t,i,r,s,o,n;let $=this.convertToArray(e);if(this.isJalali($))return $;let[h,a,l]=$;return t=[0,31,59,90,120,151,181,212,243,273,304,334],o=a>2?h+1:h,i=-1595+33*~~((n=355666+365*h+~~((o+3)/4)-~~((o+99)/100)+~~((o+399)/400)+l+t[a-1])/12053),n%=12053,i+=4*~~(n/1461),(n%=1461)>365&&(i+=~~((n-1)/365),n=(n-1)%365),n<186?(r=1+~~(n/31),s=1+n%31):(r=7+~~((n-186)/30),s=1+(n-186)%30),$[0]=i,$[1]=r,$[2]=s,$},this.getSplitter=e=>{let t="/";for(let i=0;i<e.length;i++)if(isNaN(parseInt(e[i])))return e[i];return t},this.getTime=(e,t=this.isJalali(e))=>{if(!e)return 0;if("number"==typeof e)return e;let[i,r=1,s=1,o=0,n=0,$=0,h=0]=e=this.convertToArray(e);t&&(e=this.toGregorian([i,r,s,o,n,$,h]));let a=new Date(e[0],e[1]-1,e[2]).getTime();return a+=36e5*o,a+=6e4*n,a+=1e3*$,a+=100*h},this.getNextTime=(e,t,i=this.isJalali(e))=>{if(!t)return this.convertToArray(e);let r=this.getTime(e,i);r+=t;let s=this.convertToArray(r);if(i){let[o,n,$]=this.toJalali(s);s[0]=o,s[1]=n,s[2]=$}return s},this.getMonthDaysLength=e=>{if(!e)return 0;let[t,i]=this.convertToArray(e);return this.isJalali([t,i])?[31,31,31,31,31,31,30,30,30,30,30,-1===[1,5,9,13,17,22,26,30].indexOf(t%33)?29:30][i-1]:new Date(t,i-1,0).getDate()},this.getYearDaysLength=e=>{if(!e)return 0;let[t]=this.convertToArray(e),i=0;for(let r=1;r<=12;r++)i+=this.getMonthDaysLength([t,r]);return i},this.getYesterday=e=>{let[t,i,r]=this.convertToArray(e),s=t,o=i,n=r;return 1===r?1===i?(s-=1,o=12,n=this.getMonthDaysLength([s,o])):(o-=1,n=this.getMonthDaysLength([s,o])):n-=1,[s,o,n]},this.getTomarrow=e=>{let[t,i,r]=this.convertToArray(e),s=t,o=i,n=r,$=this.getMonthDaysLength(e);return r===$?12===i?(s+=1,o=1,n=1):(o+=1,n=1):n+=1,[s,o,n]},this.getDaysOfWeek=(e,t)=>{if(!e)return[];let i=this.convertToArray(e),{index:r}=this.getWeekDay(i),s=[...i];for(let o=0;o<r;o++)s=this.getYesterday(s);let n=[];for(let $=0;$<7;$++)n.push(s),s=this.getTomarrow(s);return t?n.map(e=>this.getDateByPattern(e,t)):n},this.getDatesBetween=(e,t,i=864e5)=>{if(!e||!t||(e=this.convertToArray(e),t=this.convertToArray(t),!this.isGreater(t,e)))return[];let r=this.getDelta(e,t).miliseconds/i;if(isNaN(r)||r>1e3)return console.error("AIODate().getDatesBetween() => too many dates"),[];let s=this.getNextTime(e,i),o=[];for(;this.isLess(s,t);)o.push(s),s=this.getNextTime(s,i);return o},this.getDelta=(e,t,i)=>{let r=this.getTime(e)-this.getTime(t||this.getToday());return this.convertMiliseconds(-r,i)},this.convertMiliseconds=(e=0,t="day")=>{let i;e<0?(i="passed",e=-e):i=e>0?"remaining":"now";let r=["day","hour","minute","second","tenthsecond","milisecond"].indexOf(t),s=0,o=0,n=0,$=0,h=0,a=e;return r<=0&&(s=Math.floor(a/864e5),a-=864e5*s),r<=1&&(o=Math.floor(a/36e5),a-=36e5*o),r<=2&&(n=Math.floor(a/6e4),a-=6e4*n),r<=3&&($=Math.floor(a/1e3),a-=1e3*$),r<=4&&(h=Math.floor(a/100)),{day:s,hour:o,minute:n,second:$,tenthsecond:h,miliseconds:e,type:i}},this.getDaysOfMonth=(e,t)=>{if(!e)return[];let i=this.convertToArray(e),r=this.getMonthDaysLength(e),s=[i[0],i[1],1],o=[];for(let n=0;n<r;n++)o.push(s),s=this.getTomarrow(s);return t?o.map(e=>this.getDateByPattern(e,t)):o},this.getLastDayOfMonth=e=>{let t=this.convertToArray(e),i=this.getMonthDaysLength(t);return[t[0],t[1],i]},this.getDateByPattern=(e,t)=>this.pattern(e,t),this.getToday=e=>{let t=new Date,i=[t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),Math.round(t.getMilliseconds()/100)];return e&&(i=this.toJalali(i)),i},this.getDayIndex=(e,t)=>{if(e=this.convertToArray(e),"week"===t){let i=this.getDaysOfWeek(e);for(let r=0;r<i.length;r++){let[s,o,n]=i[r];if(s===e[0]&&o===e[1]&&n===e[2])return r}}if("month"===t)return e[2]-1;if("year"===t){let $=0;for(let h=0;h<e[1]-1;h++)$+=this.getMonthDaysLength(e);return($+=e[1])-1}return 0}}}exports.AIODate=AIODate;
{
"name": "aio-date",
"version": "4.1.0",
"version": "5.0.0",
"description": "",
"types":"index.d.ts",
"main": "index.js",

@@ -6,0 +7,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc