aio-date
all calculations of dates (gregorian and jalali)
instalation
npm install aio-date
use
import AIODate from 'aio-date';
date property of all functions can be:
-
string ('2022/4/5/12/30/40/3') ('year/month/day/hour/minute/second/tenthsecond') (from year to any next value)
-
iso date ('2015-03-25T12:00:00Z')
-
array ([2022,4,5,12,30,40,3]) ([year,month,day,hour,minute,second,tenthsecond]) (from year to any next value)
-
miliseconds date (16765675665656)
toJalali
let result = AIODate().toJalali({date:'2022/4/4'});
let result = AIODate().toJalali({date:'2022/4/4',pattern:'{year}/{month}/{day}'});
let result = AIODate().toJalali({date:'2022/4/4',pattern:'{weekDay} {day} {monthString} {year}'});
let result = AIODate().toJalali({date:'2022/4/4/22/30',pattern:'{weekDay} {day} {monthString} {year} ساعت {hour}:{minute}'});
-
date is required (string | array | number)
-
pattern is optional(if set pattern result will be string else result will be array)
toGregorian
let result = AIODate().toGregorian({date:'1400/2/2'});
let result = AIODate().toGregorian({date:'1400/2/2',pattern:'{year}/{month}/{day}'});
let result = AIODate().toGregorian({date:'1400/2/2',pattern:'{weekDay} {day} {monthString} {year}'});
let result = AIODate().toGregorian({date:'1400/2/2/22/30',pattern:'{weekDay} {day} {monthString} {year} {hour}:{minute}'});
-
date is required (string | array | number)
-
pattern is optional (if set pattern result will be string else result will be array)
getToday
let result = AIODate().getToday({calendarType:'gregorian'});
let result = AIODate().getToday({calendarType:'gregorian',pattern:'{year}/{month}/{day} {hour}:{minute}'});
let result = AIODate().getToday({calendarType:'jalali'});
let result = AIODate().getToday({calendarType:'jalali',pattern:'{year}/{month}/{day} {hour}:{minute}'});
-
calendarType is required ('gregorian' | 'jalali')
-
pattern is optional (if set pattern result will be string else result will be array)
getWeekDay
let {weekDay,index} = AIODate().getWeekDay({date:'1401/5/7'});
let {weekDay,index} = AIODate().getWeekDay({date:'2023/6/6'});
-
date is required (string | array | number)
getDateByPattern
let result = AIODate().getDateByPattern({
{date:'2023/4/5',pattern:'{year}/{month}/{day} {weekDay}'}
});
let result = AIODate().getDateByPattern({
date:'2023/4/5',pattern:'{day} {monthString} {year} {weekDay}'
});
let result = AIODate().getDateByPattern({
date:'2023/4/5/10/30',pattern:'{year}/{month}/{day} {hour}:{minute}'
});
let result = AIODate().getDateByPattern({
date:[2023,4,5,10,30],pattern:'{year}/{month}/{day} {hour}:{minute}'
});
-
date is required (string | array | number)
-
pattern is required (string)
-
result is an string
convertToArray
let result = AIODate().convertToArray({date:'2022/4/4'});
let result = AIODate().convertToArray({date:1432445566787});
-
date is required (string | number)
-
result is an array
getTime
let result = AIODate().getTime({date:'2022/4/5'});
let result = AIODate().getTime({date:'2022/4/5/10/30'});
let result = AIODate().getTime({date:[2022,4,5,10,30]});
let result = AIODate().getTime({date:'2015-03-25T12:00:00Z'});
let result = AIODate().getTime({date:1755555656665});
let result = AIODate().getTime({date:'1402/3/3'});
-
date is required (string | number | array)
-
result is a miliseconds date(number)
compaire
let result = AIODate().compaire({date:'2022/4/4',otherDate:'2022/7/10'});
let result = AIODate().compaire({date:'2022/4/4',otherDate:'2022/2/10'})
let result = AIODate().compaire({date:'2022/4/4',otherDate:'2022/4/4'})
let result = AIODate().compaire({date:'2022/4/4',otherDate:1700000000000})
let result = AIODate().compaire({date:'2022/4/4',otherDate:[2022,2,10]})
-
date is required (string | array | number)
-
otherDate is required (string | array | number)
-
result is 'less' or 'greater' or 'equal'
getMonthDaysLength
let result = AIODate().getMonthDaysLength({date:'2022/4'});
let result = AIODate().getMonthDaysLength({date:'2022/7/5'});
let result = AIODate().getMonthDaysLength({date:'1400/12'});
let result = AIODate().getMonthDaysLength({date:'1399/12'});
-
date is required (string | array | number)
-
result is an number
getDelta
this function get 2 dates as parameter and return deffrence of those by object
let result = AIODate().getDelta({date:'2023/4/5',otherDate:new Date().getTime()});
let result = AIODate().getDelta({
date:'2023/4/5',
otherDate:new Date().getTime(),
pattern:'{day} : {hour} : {minute} : {second}'
});
let result = AIODate().getDelta({date:new Date().getTime() + 23000,otherDate:new Date().getTime()});
let result = AIODate().getDelta({date:new Date().getTime() - 23000,otherDate:new Date().getTime()});
let res = AIODate().getDelta({date:'1401/12/12',otherDate:new Date().getTime()});
-
date is required (string | array | number)
-
otherDate is required (string | array | number)
-
pattern is optional (if set pattern result will be an string)
getNextTime
let result = AIODate().getNextTime({
date:'1400/2/2/22/30',
offset:1.5 * 60 * 60 * 1000
});
let result = AIODate().getNextTime({
date:'1400/2/2/22/30',
offset:1.5 * 60 * 60 * 1000,
pattern:'{year}/{month}/{day} {hour}:{minute}'
});
-
date is required (string | array | number)
-
offset is required (number) (miliseconds)
-
pattern is optional (string)
getDatesBetween
let result = AIODate().getdatesBetween({
date:'2022/4/4',
otherDate:'2022/7/10',
step:48 * 60 * 60 * 1000,
pattern:'{day} {monthString} {year}'
});
-
date is required (string | array | number)
-
otherDate is required (string | array | number)
-
step is required (number) (miliseconds)
-
pattern is optional (string)