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

jalaliday

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jalaliday - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

.circleci/config.yml

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Change Log

## [2.2.1](https://github.com/alibaba-aero/jalaliday/compare/v2.2.0...v2.2.1) (2019-03-10)
### Bug Fixes
* **plugin:** refactor add and startOf functionality ([8435a56](https://github.com/alibaba-aero/jalaliday/commit/8435a56)), closes [#8](https://github.com/alibaba-aero/jalaliday/issues/8)
* **plugin:** support dayjs^1.8.9 ([31bd189](https://github.com/alibaba-aero/jalaliday/commit/31bd189)), closes [#6](https://github.com/alibaba-aero/jalaliday/issues/6)
<a name="2.2.0"></a>

@@ -7,0 +17,0 @@ # [2.2.0](https://github.com/alibaba-aero/jalaliday/compare/v2.1.1...v2.2.0) (2019-02-27)

2

dist/jalaliday.cjs.min.js

@@ -1,2 +0,2 @@

"use strict";function _slicedToArray(t,r){return _arrayWithHoles(t)||_iterableToArrayLimit(t,r)||_nonIterableRest()}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArrayLimit(t,r){var i=[],a=!0,n=!1,e=void 0;try{for(var s,o=t[Symbol.iterator]();!(a=(s=o.next()).done)&&(i.push(s.value),!r||i.length!==r);a=!0);}catch(t){n=!0,e=t}finally{try{a||null==o.return||o.return()}finally{if(n)throw e}}return i}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function mod(t,r){return t-r*Math.floor(t/r)}function leap_gregorian(t){return t%4==0&&!(t%100==0&&t%400!=0)}var GREGORIAN_EPOCH=1721425.5;function gregorian_to_jd(t,r,i){return GREGORIAN_EPOCH-1+365*(t-1)+Math.floor((t-1)/4)+-Math.floor((t-1)/100)+Math.floor((t-1)/400)+Math.floor((367*r-362)/12+(r<=2?0:leap_gregorian(t)?-1:-2)+i)}function jd_to_gregorian(t){var r,i,a,n,e,s,o,h,l,d,u,f;i=(r=Math.floor(t-.5)+.5)-GREGORIAN_EPOCH,a=Math.floor(i/146097),n=mod(i,146097),e=Math.floor(n/36524),s=mod(n,36524),o=Math.floor(s/1461),h=mod(s,1461),d=400*a+100*e+4*o+(l=Math.floor(h/365)),4!=e&&4!=l&&d++,u=r-gregorian_to_jd(d,1,1),f=r<gregorian_to_jd(d,3,1)?0:leap_gregorian(d)?1:2;var _=Math.floor((12*(u+f)+373)/367);return[d,_,r-gregorian_to_jd(d,_,1)+1]}var PERSIAN_EPOCH=1948320.5;function persian_to_jd(t,r,i){var a,n;return n=474+mod(a=t-(t>=0?474:473),2820),i+(r<=7?31*(r-1):30*(r-1)+6)+Math.floor((682*n-110)/2816)+365*(n-1)+1029983*Math.floor(a/2820)+(PERSIAN_EPOCH-1)}function jd_to_persian(t){var r,i,a,n,e,s,o,h,l;return a=(t=Math.floor(t)+.5)-persian_to_jd(475,1,1),n=Math.floor(a/1029983),1029982==(e=mod(a,1029983))?s=2820:(o=Math.floor(e/366),h=mod(e,366),s=Math.floor((2134*o+2816*h+2815)/1028522)+o+1),(r=s+2820*n+474)<=0&&r--,[r,i=(l=t-persian_to_jd(r,1,1)+1)<=186?Math.ceil(l/31):Math.ceil((l-6)/30),t-persian_to_jd(r,i,1)+1]}function toJalaali(t,r,i){return jd_to_persian(gregorian_to_jd(t,r,i))}function toGregorian(t,r,i){return jd_to_gregorian(persian_to_jd(t,r,i))}var jdate={toJalaali:toJalaali,toGregorian:toGregorian},REGEX_PARSE=/^(\d{4})[-\/]?(\d{1,2})[-\/]?(\d{0,2})(.*)?$/,REGEX_FORMAT=/\[.*?\]|jY{2,4}|jM{1,4}|jD{1,2}|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,DATE="date",D="day",M="month",Y="year",W="week",FORMAT_DEFAULT="YYYY-MM-DDTHH:mm:ssZ",fa={name:"fa",weekdays:"یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"),months:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),jmonths:"فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند".split("_"),ordinal:function(t){return t},relativeTime:{future:"در %s ثانیه‌ی آتی",past:"%s پیش",s:"چند ثانیه پیش",m:"یک دقیقه",mm:"%d دقیقه",h:"یک ساعت",hh:"%d ساعت",d:"یک روز",dd:"%d روز",M:"یک ماه",MM:"%d ماه",y:"یک سال",yy:"%d سال"}},plugin=function(t,r,i){var a=r.prototype,n=a.$utils(),e=function(t){return function(){var r=t.bind(this).apply(void 0,arguments);return r.$C=this.$C,r.isJalali()&&r.InitJalali(),r}};a.startOf=e(a.startOf),a.endOf=e(a.endOf),a.add=e(a.add),a.subtract=e(a.subtract),a.set=e(a.set);var s=a.parse,o=a.init,h=a.startOf,l=a.$set,d=a.add,u=a.format,f=a.diff,_=a.year,c=a.month,$=a.date,j=a.daysInMonth,y=a.toArray;i.$C="gregory",i.$fdow=6,i.calendar=function(t){return i.$C=t,i},a.calendar=function(t){var r=this.clone();return r.$C=t,r.isJalali()&&r.InitJalali(),r},a.isJalali=function(){return"jalali"===this.$C},i.en.jmonths="Farvardin_Ordibehesht_Khordaad_Tir_Mordaad_Shahrivar_Mehr_Aabaan_Aazar_Dey_Bahman_Esfand".split("_"),i.locale("fa",fa,!0);var g=function(t,r){return i(t,{locale:r.$L,calendar:r.$C})};a.init=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o.bind(this)(t),this.$C=t.calendar||this.$C||i.$C,this.isJalali()&&this.InitJalali()},a.parse=function(t){var r;if(t.jalali&&"string"==typeof t.date&&/.*[^Z]$/i.test(t.date)&&(r=t.date.match(REGEX_PARSE))){var i=_slicedToArray(jdate.toGregorian(parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3]||1,10)),3),a=i[0],n=i[1],e=i[2];t.date="".concat(a,"-").concat(n,"-").concat(e).concat(r[4]||"")}return s.bind(this)(t)},a.InitJalali=function(){var t=_slicedToArray(jdate.toJalaali(this.$y,this.$M+1,this.$D),3),r=t[0],i=t[1],a=t[2];this.$jy=r,this.$jM=i-1,this.$jD=a},a.startOf=function(t,r){var a=this;if(!this.isJalali())return h.bind(this)(t,r);var e=!!n.isUndefined(r)||r,s=n.prettyUnit(t),o=function(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a.$jy,n=_slicedToArray(jdate.toGregorian(i,r+1,t),3),s=n[0],o=n[1],h=n[2],l=g(new Date(s,o-1,h),a);return e?l:l.endOf(D)},l=(this.$W+(7-i.$fdow))%7;switch(s){case Y:return e?o(1,0):o(0,0,this.$jy+1);case M:return e?o(1,this.$jM):o(0,this.$jM+1);case W:return o(e?this.$jD-l:this.$jD+(6-l),this.$jM);default:return h.bind(this)(t,r)}},a.$set=function(t,r){var i=this;if(!this.isJalali())return l.bind(this)(t,r);var a=function(t,r){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:i.$jy,n=_slicedToArray(jdate.toGregorian(a,r+1,t),3),e=n[0],s=n[1],o=n[2];return i.$d.setDate(o),i.$d.setMonth(s-1),i.$d.setFullYear(e),i};switch(n.prettyUnit(t)){case DATE:a(r,this.$jM);break;case M:a(this.$jD,r);break;case Y:a(this.$jD,this.$jM,r);break;default:return l.bind(this)(t,r)}return this.init(),this},a.add=function(t,r){var i=this;if(!this.isJalali())return d.bind(this)(t,r);t=Number(t);var a=!r||1!==r.length&&"ms"!==r?n.prettyUnit(r):r,e=function(r,a){var n=i.set(DATE,1).set(r,a+t);return n.set(DATE,Math.min(i.$jD,n.daysInMonth()))};if(["M",M].indexOf(a)>-1)return e(M,this.$jM);if(["y",Y].indexOf(a)>-1)return e(Y,this.$jy);if(["d",D].indexOf(a)>-1){var s=new Date(this.$d);return s.setDate(s.getDate()+t),g(s,this)}return d.bind(this)(t,r)},a.format=function(t,r){var i=this;if(!this.isJalali())return u.bind(this)(t,r);var a=t||FORMAT_DEFAULT,e=(r||this.$locale()).jmonths;return a.replace(REGEX_FORMAT,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(i.$jy).slice(-2);case"YYYY":return String(i.$jy);case"M":return String(i.$jM+1);case"MM":return n.padStart(i.$jM+1,2,"0");case"MMM":return e[i.$jM].slice(0,3);case"MMMM":return e[i.$jM];case"D":return String(i.$jD);case"DD":return n.padStart(i.$jD,2,"0");default:return u.bind(i)(t,r)}})},a.diff=function(t,r,a){if(!this.isJalali())return f.bind(this)(t,r,a);var e=n.prettyUnit(r),s=i(t),o=n.monthDiff(this,s);switch(e){case Y:o/=12;break;case M:break;default:return f.bind(this)(t,r,a)}return a?o:n.absFloor(o)},a.year=function(){return this.isJalali()?this.$jy:_.bind(this)()},a.month=function(){return this.isJalali()?this.$jM:c.bind(this)()},a.date=function(){return this.isJalali()?this.$jD:$.bind(this)()},a.daysInMonth=function(){return this.isJalali()?this.endOf(M).$jD:j.bind(this)()},a.toArray=function(){return this.isJalali()?[this.$jy,this.$jM,this.$jD,this.$H,this.$m,this.$s,this.$ms]:y.bind(this)()},a.clone=function(){return g(this.toDate(),this)}};module.exports=plugin;
"use strict";function _slicedToArray(t,r){return _arrayWithHoles(t)||_iterableToArrayLimit(t,r)||_nonIterableRest()}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArrayLimit(t,r){var n=[],i=!0,e=!1,a=void 0;try{for(var s,o=t[Symbol.iterator]();!(i=(s=o.next()).done)&&(n.push(s.value),!r||n.length!==r);i=!0);}catch(t){e=!0,a=t}finally{try{i||null==o.return||o.return()}finally{if(e)throw a}}return n}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var $floor=Math.floor;function mod(t,r){return t-r*$floor(t/r)}function lg(t){return t%4==0&&!(t%100==0&&t%400!=0)}var GE=1721425.5;function g2j(t,r,n){return GE-1+365*(t-1)+$floor((t-1)/4)+-$floor((t-1)/100)+$floor((t-1)/400)+$floor((367*r-362)/12+(r<=2?0:lg(t)?-1:-2)+n)}function j2g(t){var r,n,i,e,a,s,o,h,u,d,f,l;r=$floor(t-.5)+.5,i=$floor((n=r-GE)/146097),e=mod(n,146097),a=$floor(e/36524),s=mod(e,36524),o=$floor(s/1461),h=mod(s,1461),d=400*i+100*a+4*o+(u=$floor(h/365)),4!=a&&4!=u&&d++,f=r-g2j(d,1,1),l=r<g2j(d,3,1)?0:lg(d)?1:2;var c=$floor((12*(f+l)+373)/367);return[d,c,r-g2j(d,c,1)+1]}var PE=1948320.5;function p2j(t,r,n){var i,e;return e=474+mod(i=t-(t>=0?474:473),2820),n+(r<=7?31*(r-1):30*(r-1)+6)+$floor((682*e-110)/2816)+365*(e-1)+1029983*$floor(i/2820)+(PE-1)}function j2p(t){var r,n,i,e,a,s,o,h,u;return i=(t=$floor(t)+.5)-p2j(475,1,1),e=$floor(i/1029983),1029982==(a=mod(i,1029983))?s=2820:(o=$floor(a/366),h=mod(a,366),s=$floor((2134*o+2816*h+2815)/1028522)+o+1),(r=s+2820*e+474)<=0&&r--,[r,n=(u=t-p2j(r,1,1)+1)<=186?Math.ceil(u/31):Math.ceil((u-6)/30),t-p2j(r,n,1)+1]}var jdate={J:function(t,r,n){return j2p(g2j(t,r,n))},G:function(t,r,n){return j2g(p2j(t,r,n))}},REGEX_PARSE=/^(\d{4})[-/]?(\d{1,2})[-/]?(\d{0,2})(.*)?$/,REGEX_FORMAT=/\[.*?\]|jY{2,4}|jM{1,4}|jD{1,2}|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,DATE="date",D="day",M="month",Y="year",W="week",FORMAT_DEFAULT="YYYY-MM-DDTHH:mm:ssZ",fa={name:"fa",weekdays:"یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"),months:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),jmonths:"فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند".split("_"),ordinal:function(t){return t},relativeTime:{future:"در %s ثانیه‌ی آتی",past:"%s پیش",s:"چند ثانیه پیش",m:"یک دقیقه",mm:"%d دقیقه",h:"یک ساعت",hh:"%d ساعت",d:"یک روز",dd:"%d روز",M:"یک ماه",MM:"%d ماه",y:"یک سال",yy:"%d سال"}},plugin=function(t,r,n){var i=r.prototype,e=i.$utils(),a=function(t){return"jalali"===t.$C},s=e.prettyUnit,o=e.isUndefined,h=e.padStart,u=e.monthDiff,d=e.absFloor,f=function(t){return function(){var r=t.bind(this).apply(void 0,arguments);return r.$C=this.$C,r.isJalali()&&r.InitJalali(),r}};i.startOf=f(i.startOf),i.endOf=f(i.endOf),i.add=f(i.add),i.subtract=f(i.subtract),i.set=f(i.set);var l=i.parse,c=i.init,$=i.startOf,j=i.$set,_=i.add,y=i.format,v=i.diff,m=i.year,b=i.month,p=i.date,g=i.daysInMonth,A=i.toArray;n.$C="gregory",n.$fdow=6,n.calendar=function(t){return n.$C=t,n},i.calendar=function(t){var r=this.clone();return r.$C=t,r.isJalali()&&r.InitJalali(),r},i.isJalali=function(){return a(this)},n.en.jmonths="Farvardin_Ordibehesht_Khordaad_Tir_Mordaad_Shahrivar_Mehr_Aabaan_Aazar_Dey_Bahman_Esfand".split("_"),n.locale("fa",fa,!0);var E=function(t,r){return n(t,{locale:r.$L,calendar:r.$C})};i.init=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};c.bind(this)(t),this.isJalali()&&this.InitJalali()},i.parse=function(t){var r;if(this.$C=t.calendar||this.$C||n.$C,t.jalali&&"string"==typeof t.date&&/.*[^Z]$/i.test(t.date)&&(r=t.date.match(REGEX_PARSE))){var i=_slicedToArray(jdate.G(parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3]||1,10)),3),e=i[0],a=i[1],s=i[2];t.date="".concat(e,"-").concat(a,"-").concat(s).concat(r[4]||"")}return l.bind(this)(t)},i.InitJalali=function(){var t=_slicedToArray(jdate.J(this.$y,this.$M+1,this.$D),3),r=t[0],n=t[1],i=t[2];this.$jy=r,this.$jM=n-1,this.$jD=i},i.startOf=function(t,r){var i=this;if(!a(this))return $.bind(this)(t,r);var e=!!o(r)||r,h=s(t),u=function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:i.$jy,a=_slicedToArray(jdate.G(n,r+1,t),3),s=a[0],o=a[1],h=a[2],u=E(new Date(s,o-1,h),i);return e?u:u.endOf(D)},d=(this.$W+(7-n.$fdow))%7;switch(h){case Y:return e?u(1,0):u(0,0,this.$jy+1);case M:return e?u(1,this.$jM):u(0,(this.$jM+1)%12,this.$jy+parseInt((this.$jM+1)/12,10));case W:return u(e?this.$jD-d:this.$jD+(6-d),this.$jM);default:return $.bind(this)(t,r)}},i.$set=function(t,r){var n=this;if(!a(this))return j.bind(this)(t,r);var i=function(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n.$jy,e=_slicedToArray(jdate.G(i,r+1,t),3),a=e[0],s=e[1],o=e[2];return n.$d.setDate(o),n.$d.setMonth(s-1),n.$d.setFullYear(a),n};switch(s(t)){case DATE:case D:i(r,this.$jM);break;case M:i(this.$jD,r);break;case Y:i(this.$jD,this.$jM,r);break;default:return j.bind(this)(t,r)}return this.init(),this},i.add=function(t,r){var n=this;if(!a(this))return _.bind(this)(t,r);t=Number(t);var i=!r||1!==r.length&&"ms"!==r?s(r):r;if(["M",M].indexOf(i)>-1){var e=this.$jM+t,o=e<0?-Math.ceil(-e/12):parseInt(e/12,10);return this.add(o,Y).set(M,e-12*o)}if(["y",Y].indexOf(i)>-1)return function(r,i){var e=n.set(DATE,1).set(r,i+t);return e.set(DATE,Math.min(n.$jD,e.daysInMonth()))}(Y,this.$jy);if(["d",D].indexOf(i)>-1){var h=new Date(this.$d);return h.setDate(h.getDate()+t),E(h,this)}return _.bind(this)(t,r)},i.format=function(t,r){var n=this;if(!a(this))return y.bind(this)(t,r);var i=t||FORMAT_DEFAULT,e=(r||this.$locale()).jmonths;return i.replace(REGEX_FORMAT,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(n.$jy).slice(-2);case"YYYY":return String(n.$jy);case"M":return String(n.$jM+1);case"MM":return h(n.$jM+1,2,"0");case"MMM":return e[n.$jM].slice(0,3);case"MMMM":return e[n.$jM];case"D":return String(n.$jD);case"DD":return h(n.$jD,2,"0");default:return y.bind(n)(t,r)}})},i.diff=function(t,r,i){if(!a(this))return v.bind(this)(t,r,i);var e=s(r),o=n(t),h=u(this,o);switch(e){case Y:h/=12;break;case M:break;default:return v.bind(this)(t,r,i)}return i?h:d(h)},i.year=function(){return a(this)?this.$jy:m.bind(this)()},i.month=function(){return a(this)?this.$jM:b.bind(this)()},i.date=function(){return a(this)?this.$jD:p.bind(this)()},i.daysInMonth=function(){return a(this)?this.endOf(M).$jD:g.bind(this)()},i.toArray=function(){return a(this)?[this.$jy,this.$jM,this.$jD,this.$H,this.$m,this.$s,this.$ms]:A.bind(this)()},i.clone=function(){return E(this.toDate(),this)}};module.exports=plugin;
//# sourceMappingURL=jalaliday.cjs.min.js.map

@@ -49,30 +49,33 @@ function _slicedToArray(arr, i) {

/* MOD -- Modulus function which works for non-integers. */
var $floor = Math.floor;
function mod(a, b) {
return a - b * Math.floor(a / b);
return a - b * $floor(a / b);
} // LEAP_GREGORIAN -- Is a given year in the Gregorian calendar a leap year ?
function leap_gregorian(year) {
function lg(year) {
return year % 4 == 0 && !(year % 100 == 0 && year % 400 != 0);
} // GREGORIAN_TO_JD -- Determine Julian day number from Gregorian calendar date
// GREGORIAN_EPOCH
var GREGORIAN_EPOCH = 1721425.5;
var GE = 1721425.5;
function gregorian_to_jd(year, month, day) {
return GREGORIAN_EPOCH - 1 + 365 * (year - 1) + Math.floor((year - 1) / 4) + -Math.floor((year - 1) / 100) + Math.floor((year - 1) / 400) + Math.floor((367 * month - 362) / 12 + (month <= 2 ? 0 : leap_gregorian(year) ? -1 : -2) + day);
function g2j(year, month, day) {
return GE - 1 + 365 * (year - 1) + $floor((year - 1) / 4) + -$floor((year - 1) / 100) + $floor((year - 1) / 400) + $floor((367 * month - 362) / 12 + (month <= 2 ? 0 : lg(year) ? -1 : -2) + day);
} // JD_TO_GREGORIAN -- Calculate Gregorian calendar date from Julian day
function jd_to_gregorian(jd) {
function j2g(jd) {
var wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, year, yearday, leapadj;
wjd = Math.floor(jd - 0.5) + 0.5;
depoch = wjd - GREGORIAN_EPOCH;
quadricent = Math.floor(depoch / 146097);
wjd = $floor(jd - 0.5) + 0.5;
depoch = wjd - GE;
quadricent = $floor(depoch / 146097);
dqc = mod(depoch, 146097);
cent = Math.floor(dqc / 36524);
cent = $floor(dqc / 36524);
dcent = mod(dqc, 36524);
quad = Math.floor(dcent / 1461);
quad = $floor(dcent / 1461);
dquad = mod(dcent, 1461);
yindex = Math.floor(dquad / 365);
yindex = $floor(dquad / 365);
year = quadricent * 400 + cent * 100 + quad * 4 + yindex;

@@ -84,24 +87,25 @@

yearday = wjd - gregorian_to_jd(year, 1, 1);
leapadj = wjd < gregorian_to_jd(year, 3, 1) ? 0 : leap_gregorian(year) ? 1 : 2;
var month = Math.floor(((yearday + leapadj) * 12 + 373) / 367),
day = wjd - gregorian_to_jd(year, month, 1) + 1;
yearday = wjd - g2j(year, 1, 1);
leapadj = wjd < g2j(year, 3, 1) ? 0 : lg(year) ? 1 : 2;
var month = $floor(((yearday + leapadj) * 12 + 373) / 367),
day = wjd - g2j(year, month, 1) + 1;
return [year, month, day];
}
} // PERSIAN_EPOCH
var PERSIAN_EPOCH = 1948320.5; // PERSIAN_TO_JD -- Determine Julian day from Persian date
function persian_to_jd(year, month, day) {
var PE = 1948320.5; // PERSIAN_TO_JD -- Determine Julian day from Persian date
function p2j(year, month, day) {
var epbase, epyear;
epbase = year - (year >= 0 ? 474 : 473);
epyear = 474 + mod(epbase, 2820);
return day + (month <= 7 ? (month - 1) * 31 : (month - 1) * 30 + 6) + Math.floor((epyear * 682 - 110) / 2816) + (epyear - 1) * 365 + Math.floor(epbase / 2820) * 1029983 + (PERSIAN_EPOCH - 1);
return day + (month <= 7 ? (month - 1) * 31 : (month - 1) * 30 + 6) + $floor((epyear * 682 - 110) / 2816) + (epyear - 1) * 365 + $floor(epbase / 2820) * 1029983 + (PE - 1);
} // JD_TO_PERSIAN -- Calculate Persian date from Julian day
function jd_to_persian(jd) {
function j2p(jd) {
var year, month, day, depoch, cycle, cyear, ycycle, aux1, aux2, yday;
jd = Math.floor(jd) + 0.5;
depoch = jd - persian_to_jd(475, 1, 1);
cycle = Math.floor(depoch / 1029983);
jd = $floor(jd) + 0.5;
depoch = jd - p2j(475, 1, 1);
cycle = $floor(depoch / 1029983);
cyear = mod(depoch, 1029983);

@@ -112,5 +116,5 @@

} else {
aux1 = Math.floor(cyear / 366);
aux1 = $floor(cyear / 366);
aux2 = mod(cyear, 366);
ycycle = Math.floor((2134 * aux1 + 2816 * aux2 + 2815) / 1028522) + aux1 + 1;
ycycle = $floor((2134 * aux1 + 2816 * aux2 + 2815) / 1028522) + aux1 + 1;
}

@@ -124,19 +128,15 @@

yday = jd - persian_to_jd(year, 1, 1) + 1;
yday = jd - p2j(year, 1, 1) + 1;
month = yday <= 186 ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30);
day = jd - persian_to_jd(year, month, 1) + 1;
day = jd - p2j(year, month, 1) + 1;
return [year, month, day];
}
function toJalaali(y, m, d) {
return jd_to_persian(gregorian_to_jd(y, m, d));
}
function toGregorian(y, m, d) {
return jd_to_gregorian(persian_to_jd(y, m, d));
}
var jdate = {
toJalaali: toJalaali,
toGregorian: toGregorian
J: function J(y, m, d) {
return j2p(g2j(y, m, d));
},
G: function G(y, m, d) {
return j2g(p2j(y, m, d));
}
};

@@ -181,2 +181,12 @@

var $isJalali = function $isJalali(v) {
return v.$C === 'jalali';
};
var $prettyUnit = U.prettyUnit;
var $isUndefined = U.isUndefined;
var $padStart = U.padStart;
var $monthDiff = U.monthDiff;
var $absFloor = U.absFloor;
var wrapperOfTruth = function wrapperOfTruth(action) {

@@ -234,3 +244,3 @@ return function () {

proto.isJalali = function () {
return this.$C === 'jalali';
return $isJalali(this);
};

@@ -251,3 +261,2 @@

oldInit.bind(this)(cfg);
this.$C = cfg.calendar || this.$C || dayjs.$C;

@@ -260,3 +269,4 @@ if (this.isJalali()) {

proto.parse = function (cfg) {
var reg; // eslint-disable-next-line no-cond-assign
var reg;
this.$C = cfg.calendar || this.$C || dayjs.$C; // eslint-disable-next-line no-cond-assign

@@ -266,7 +276,7 @@ if (cfg.jalali && typeof cfg.date === 'string' && /.*[^Z]$/i.test(cfg.date) && ( // looking for a better way

// 1397-08-08 or 13970808
var _jdate$toGregorian = jdate.toGregorian(parseInt(reg[1], 10), parseInt(reg[2], 10), parseInt(reg[3] || 1, 10)),
_jdate$toGregorian2 = _slicedToArray(_jdate$toGregorian, 3),
y = _jdate$toGregorian2[0],
m = _jdate$toGregorian2[1],
d = _jdate$toGregorian2[2];
var _jdate$G = jdate.G(parseInt(reg[1], 10), parseInt(reg[2], 10), parseInt(reg[3] || 1, 10)),
_jdate$G2 = _slicedToArray(_jdate$G, 3),
y = _jdate$G2[0],
m = _jdate$G2[1],
d = _jdate$G2[2];

@@ -280,7 +290,7 @@ cfg.date = "".concat(y, "-").concat(m, "-").concat(d).concat(reg[4] || '');

proto.InitJalali = function () {
var _jdate$toJalaali = jdate.toJalaali(this.$y, this.$M + 1, this.$D),
_jdate$toJalaali2 = _slicedToArray(_jdate$toJalaali, 3),
jy = _jdate$toJalaali2[0],
jm = _jdate$toJalaali2[1],
jd = _jdate$toJalaali2[2];
var _jdate$J = jdate.J(this.$y, this.$M + 1, this.$D),
_jdate$J2 = _slicedToArray(_jdate$J, 3),
jy = _jdate$J2[0],
jm = _jdate$J2[1],
jd = _jdate$J2[2];

@@ -296,8 +306,8 @@ this.$jy = jy;

// startOf -> endOf
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldStartOf.bind(this)(units, startOf);
}
var isStartOf = !U.isUndefined(startOf) ? startOf : true;
var unit = U.prettyUnit(units);
var isStartOf = !$isUndefined(startOf) ? startOf : true;
var unit = $prettyUnit(units);

@@ -307,7 +317,7 @@ var instanceFactory = function instanceFactory(d, m) {

var _jdate$toGregorian3 = jdate.toGregorian(y, m + 1, d),
_jdate$toGregorian4 = _slicedToArray(_jdate$toGregorian3, 3),
gy = _jdate$toGregorian4[0],
gm = _jdate$toGregorian4[1],
gd = _jdate$toGregorian4[2];
var _jdate$G3 = jdate.G(y, m + 1, d),
_jdate$G4 = _slicedToArray(_jdate$G3, 3),
gy = _jdate$G4[0],
gm = _jdate$G4[1],
gd = _jdate$G4[2];

@@ -325,3 +335,3 @@ var ins = wrapper(new Date(gy, gm - 1, gd), _this);

case M:
return isStartOf ? instanceFactory(1, this.$jM) : instanceFactory(0, this.$jM + 1);
return isStartOf ? instanceFactory(1, this.$jM) : instanceFactory(0, (this.$jM + 1) % 12, this.$jy + parseInt((this.$jM + 1) / 12, 10));

@@ -339,8 +349,7 @@ case W:

// private set
if (!this.isJalali()) {
if (!$isJalali(this)) {
return old$Set.bind(this)(units, int);
}
var unit = U.prettyUnit(units);
var unit = $prettyUnit(units);

@@ -350,7 +359,7 @@ var instanceFactory = function instanceFactory(d, m) {

var _jdate$toGregorian5 = jdate.toGregorian(y, m + 1, d),
_jdate$toGregorian6 = _slicedToArray(_jdate$toGregorian5, 3),
gy = _jdate$toGregorian6[0],
gm = _jdate$toGregorian6[1],
gd = _jdate$toGregorian6[2];
var _jdate$G5 = jdate.G(y, m + 1, d),
_jdate$G6 = _slicedToArray(_jdate$G5, 3),
gy = _jdate$G6[0],
gm = _jdate$G6[1],
gd = _jdate$G6[2];

@@ -368,2 +377,3 @@ _this2.$d.setDate(gd);

case DATE:
case D:
instanceFactory(int, this.$jM);

@@ -391,3 +401,3 @@ break;

if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldAdd.bind(this)(number, units);

@@ -399,3 +409,3 @@ }

var unit = units && (units.length === 1 || units === 'ms') ? units : U.prettyUnit(units);
var unit = units && (units.length === 1 || units === 'ms') ? units : $prettyUnit(units);

@@ -409,3 +419,5 @@ var instanceFactory = function instanceFactory(u, n) {

if (['M', M].indexOf(unit) > -1) {
return instanceFactory(M, this.$jM);
var n = this.$jM + number;
var y = n < 0 ? -Math.ceil(-n / 12) : parseInt(n / 12, 10);
return this.add(y, Y).set(M, n - y * 12);
}

@@ -429,3 +441,3 @@

if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldFormat.bind(this)(formatStr, localeObject);

@@ -451,3 +463,3 @@ }

case 'MM':
return U.padStart(_this4.$jM + 1, 2, '0');
return $padStart(_this4.$jM + 1, 2, '0');

@@ -464,3 +476,3 @@ case 'MMM':

case 'DD':
return U.padStart(_this4.$jD, 2, '0');
return $padStart(_this4.$jD, 2, '0');

@@ -474,9 +486,9 @@ default:

proto.diff = function (input, units, float) {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldDiff.bind(this)(input, units, float);
}
var unit = U.prettyUnit(units);
var unit = $prettyUnit(units);
var that = dayjs(input);
var result = U.monthDiff(this, that);
var result = $monthDiff(this, that);

@@ -496,7 +508,7 @@ switch (unit) {

return float ? result : U.absFloor(result);
return float ? result : $absFloor(result);
};
proto.year = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldYear.bind(this)();

@@ -509,3 +521,3 @@ }

proto.month = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldMonth.bind(this)();

@@ -518,3 +530,3 @@ }

proto.date = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldDate.bind(this)();

@@ -527,3 +539,3 @@ }

proto.daysInMonth = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldDaysInMonth.bind(this)();

@@ -536,3 +548,3 @@ }

proto.toArray = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldToArray.bind(this)();

@@ -539,0 +551,0 @@ }

@@ -1,2 +0,2 @@

!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.jalaliday=i()}(this,function(){"use strict";function t(t,i){return function(t){if(Array.isArray(t))return t}(t)||function(t,i){var r=[],n=!0,a=!1,e=void 0;try{for(var s,o=t[Symbol.iterator]();!(n=(s=o.next()).done)&&(r.push(s.value),!i||r.length!==i);n=!0);}catch(t){a=!0,e=t}finally{try{n||null==o.return||o.return()}finally{if(a)throw e}}return r}(t,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(t,i){return t-i*Math.floor(t/i)}function r(t){return t%4==0&&!(t%100==0&&t%400!=0)}var n=1721425.5;function a(t,i,a){return n-1+365*(t-1)+Math.floor((t-1)/4)+-Math.floor((t-1)/100)+Math.floor((t-1)/400)+Math.floor((367*i-362)/12+(i<=2?0:r(t)?-1:-2)+a)}var e=1948320.5;function s(t,r,n){var a,s;return s=474+i(a=t-(t>=0?474:473),2820),n+(r<=7?31*(r-1):30*(r-1)+6)+Math.floor((682*s-110)/2816)+365*(s-1)+1029983*Math.floor(a/2820)+(e-1)}var o={toJalaali:function(t,r,n){return e=a(t,r,n),u=(e=Math.floor(e)+.5)-s(475,1,1),l=Math.floor(u/1029983),1029982==(f=i(u,1029983))?d=2820:(c=Math.floor(f/366),$=i(f,366),d=Math.floor((2134*c+2816*$+2815)/1028522)+c+1),(o=d+2820*l+474)<=0&&o--,[o,h=(M=e-s(o,1,1)+1)<=186?Math.ceil(M/31):Math.ceil((M-6)/30),e-s(o,h,1)+1];var e,o,h,u,l,f,d,c,$,M},toGregorian:function(t,e,o){return function(t){var e,s,o,h,u,l,f,d,c,$,M,y;s=(e=Math.floor(t-.5)+.5)-n,o=Math.floor(s/146097),h=i(s,146097),u=Math.floor(h/36524),l=i(h,36524),f=Math.floor(l/1461),d=i(l,1461),$=400*o+100*u+4*f+(c=Math.floor(d/365)),4!=u&&4!=c&&$++,M=e-a($,1,1),y=e<a($,3,1)?0:r($)?1:2;var j=Math.floor((12*(M+y)+373)/367);return[$,j,e-a($,j,1)+1]}(s(t,e,o))}},h=/^(\d{4})[-\/]?(\d{1,2})[-\/]?(\d{0,2})(.*)?$/,u=/\[.*?\]|jY{2,4}|jM{1,4}|jD{1,2}|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,l="day",f="month",d="year",c={name:"fa",weekdays:"یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"),months:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),jmonths:"فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند".split("_"),ordinal:function(t){return t},relativeTime:{future:"در %s ثانیه‌ی آتی",past:"%s پیش",s:"چند ثانیه پیش",m:"یک دقیقه",mm:"%d دقیقه",h:"یک ساعت",hh:"%d ساعت",d:"یک روز",dd:"%d روز",M:"یک ماه",MM:"%d ماه",y:"یک سال",yy:"%d سال"}};return function(i,r,n){var a=r.prototype,e=a.$utils(),s=function(t){return function(){var i=t.bind(this).apply(void 0,arguments);return i.$C=this.$C,i.isJalali()&&i.InitJalali(),i}};a.startOf=s(a.startOf),a.endOf=s(a.endOf),a.add=s(a.add),a.subtract=s(a.subtract),a.set=s(a.set);var $=a.parse,M=a.init,y=a.startOf,j=a.$set,_=a.add,v=a.format,b=a.diff,p=a.year,m=a.month,D=a.date,J=a.daysInMonth,g=a.toArray;n.$C="gregory",n.$fdow=6,n.calendar=function(t){return n.$C=t,n},a.calendar=function(t){var i=this.clone();return i.$C=t,i.isJalali()&&i.InitJalali(),i},a.isJalali=function(){return"jalali"===this.$C},n.en.jmonths="Farvardin_Ordibehesht_Khordaad_Tir_Mordaad_Shahrivar_Mehr_Aabaan_Aazar_Dey_Bahman_Esfand".split("_"),n.locale("fa",c,!0);var w=function(t,i){return n(t,{locale:i.$L,calendar:i.$C})};a.init=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};M.bind(this)(t),this.$C=t.calendar||this.$C||n.$C,this.isJalali()&&this.InitJalali()},a.parse=function(i){var r;if(i.jalali&&"string"==typeof i.date&&/.*[^Z]$/i.test(i.date)&&(r=i.date.match(h))){var n=t(o.toGregorian(parseInt(r[1],10),parseInt(r[2],10),parseInt(r[3]||1,10)),3),a=n[0],e=n[1],s=n[2];i.date="".concat(a,"-").concat(e,"-").concat(s).concat(r[4]||"")}return $.bind(this)(i)},a.InitJalali=function(){var i=t(o.toJalaali(this.$y,this.$M+1,this.$D),3),r=i[0],n=i[1],a=i[2];this.$jy=r,this.$jM=n-1,this.$jD=a},a.startOf=function(i,r){var a=this;if(!this.isJalali())return y.bind(this)(i,r);var s=!!e.isUndefined(r)||r,h=e.prettyUnit(i),u=function(i,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a.$jy,e=t(o.toGregorian(n,r+1,i),3),h=e[0],u=e[1],f=e[2],d=w(new Date(h,u-1,f),a);return s?d:d.endOf(l)},c=(this.$W+(7-n.$fdow))%7;switch(h){case d:return s?u(1,0):u(0,0,this.$jy+1);case f:return s?u(1,this.$jM):u(0,this.$jM+1);case"week":return u(s?this.$jD-c:this.$jD+(6-c),this.$jM);default:return y.bind(this)(i,r)}},a.$set=function(i,r){var n=this;if(!this.isJalali())return j.bind(this)(i,r);var a=function(i,r){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:n.$jy,e=t(o.toGregorian(a,r+1,i),3),s=e[0],h=e[1],u=e[2];return n.$d.setDate(u),n.$d.setMonth(h-1),n.$d.setFullYear(s),n};switch(e.prettyUnit(i)){case"date":a(r,this.$jM);break;case f:a(this.$jD,r);break;case d:a(this.$jD,this.$jM,r);break;default:return j.bind(this)(i,r)}return this.init(),this},a.add=function(t,i){var r=this;if(!this.isJalali())return _.bind(this)(t,i);t=Number(t);var n=!i||1!==i.length&&"ms"!==i?e.prettyUnit(i):i,a=function(i,n){var a=r.set("date",1).set(i,n+t);return a.set("date",Math.min(r.$jD,a.daysInMonth()))};if(["M",f].indexOf(n)>-1)return a(f,this.$jM);if(["y",d].indexOf(n)>-1)return a(d,this.$jy);if(["d",l].indexOf(n)>-1){var s=new Date(this.$d);return s.setDate(s.getDate()+t),w(s,this)}return _.bind(this)(t,i)},a.format=function(t,i){var r=this;if(!this.isJalali())return v.bind(this)(t,i);var n=t||"YYYY-MM-DDTHH:mm:ssZ",a=(i||this.$locale()).jmonths;return n.replace(u,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(r.$jy).slice(-2);case"YYYY":return String(r.$jy);case"M":return String(r.$jM+1);case"MM":return e.padStart(r.$jM+1,2,"0");case"MMM":return a[r.$jM].slice(0,3);case"MMMM":return a[r.$jM];case"D":return String(r.$jD);case"DD":return e.padStart(r.$jD,2,"0");default:return v.bind(r)(t,i)}})},a.diff=function(t,i,r){if(!this.isJalali())return b.bind(this)(t,i,r);var a=e.prettyUnit(i),s=n(t),o=e.monthDiff(this,s);switch(a){case d:o/=12;break;case f:break;default:return b.bind(this)(t,i,r)}return r?o:e.absFloor(o)},a.year=function(){return this.isJalali()?this.$jy:p.bind(this)()},a.month=function(){return this.isJalali()?this.$jM:m.bind(this)()},a.date=function(){return this.isJalali()?this.$jD:D.bind(this)()},a.daysInMonth=function(){return this.isJalali()?this.endOf(f).$jD:J.bind(this)()},a.toArray=function(){return this.isJalali()?[this.$jy,this.$jM,this.$jD,this.$H,this.$m,this.$s,this.$ms]:g.bind(this)()},a.clone=function(){return w(this.toDate(),this)}}});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.jalaliday=n()}(this,function(){"use strict";function t(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var i=[],r=!0,e=!1,a=void 0;try{for(var s,h=t[Symbol.iterator]();!(r=(s=h.next()).done)&&(i.push(s.value),!n||i.length!==n);r=!0);}catch(t){e=!0,a=t}finally{try{r||null==h.return||h.return()}finally{if(e)throw a}}return i}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var n=Math.floor;function i(t,i){return t-i*n(t/i)}function r(t){return t%4==0&&!(t%100==0&&t%400!=0)}var e=1721425.5;function a(t,i,a){return e-1+365*(t-1)+n((t-1)/4)+-n((t-1)/100)+n((t-1)/400)+n((367*i-362)/12+(i<=2?0:r(t)?-1:-2)+a)}var s=1948320.5;function h(t,r,e){var a,h;return h=474+i(a=t-(t>=0?474:473),2820),e+(r<=7?31*(r-1):30*(r-1)+6)+n((682*h-110)/2816)+365*(h-1)+1029983*n(a/2820)+(s-1)}var u=function(t,r,e){return s=a(t,r,e),o=(s=n(s)+.5)-h(475,1,1),f=n(o/1029983),1029982==(c=i(o,1029983))?l=2820:($=n(c/366),j=i(c,366),l=n((2134*$+2816*j+2815)/1028522)+$+1),(u=l+2820*f+474)<=0&&u--,[u,d=(M=s-h(u,1,1)+1)<=186?Math.ceil(M/31):Math.ceil((M-6)/30),s-h(u,d,1)+1];var s,u,d,o,f,c,l,$,j,M},d=function(t,s,u){return function(t){var s,h,u,d,o,f,c,l,$,j,M,v;s=n(t-.5)+.5,u=n((h=s-e)/146097),d=i(h,146097),o=n(d/36524),f=i(d,36524),c=n(f/1461),l=i(f,1461),j=400*u+100*o+4*c+($=n(l/365)),4!=o&&4!=$&&j++,M=s-a(j,1,1),v=s<a(j,3,1)?0:r(j)?1:2;var y=n((12*(M+v)+373)/367);return[j,y,s-a(j,y,1)+1]}(h(t,s,u))},o=/^(\d{4})[-/]?(\d{1,2})[-/]?(\d{0,2})(.*)?$/,f=/\[.*?\]|jY{2,4}|jM{1,4}|jD{1,2}|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c="day",l="month",$="year",j={name:"fa",weekdays:"یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"),months:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),jmonths:"فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند".split("_"),ordinal:function(t){return t},relativeTime:{future:"در %s ثانیه‌ی آتی",past:"%s پیش",s:"چند ثانیه پیش",m:"یک دقیقه",mm:"%d دقیقه",h:"یک ساعت",hh:"%d ساعت",d:"یک روز",dd:"%d روز",M:"یک ماه",MM:"%d ماه",y:"یک سال",yy:"%d سال"}};return function(n,i,r){var e=i.prototype,a=e.$utils(),s=function(t){return"jalali"===t.$C},h=a.prettyUnit,M=a.isUndefined,v=a.padStart,y=a.monthDiff,_=a.absFloor,b=function(t){return function(){var n=t.bind(this).apply(void 0,arguments);return n.$C=this.$C,n.isJalali()&&n.InitJalali(),n}};e.startOf=b(e.startOf),e.endOf=b(e.endOf),e.add=b(e.add),e.subtract=b(e.subtract),e.set=b(e.set);var m=e.parse,p=e.init,D=e.startOf,g=e.$set,w=e.add,I=e.format,O=e.diff,Y=e.year,C=e.month,S=e.date,J=e.daysInMonth,k=e.toArray;r.$C="gregory",r.$fdow=6,r.calendar=function(t){return r.$C=t,r},e.calendar=function(t){var n=this.clone();return n.$C=t,n.isJalali()&&n.InitJalali(),n},e.isJalali=function(){return s(this)},r.en.jmonths="Farvardin_Ordibehesht_Khordaad_Tir_Mordaad_Shahrivar_Mehr_Aabaan_Aazar_Dey_Bahman_Esfand".split("_"),r.locale("fa",j,!0);var x=function(t,n){return r(t,{locale:n.$L,calendar:n.$C})};e.init=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};p.bind(this)(t),this.isJalali()&&this.InitJalali()},e.parse=function(n){var i;if(this.$C=n.calendar||this.$C||r.$C,n.jalali&&"string"==typeof n.date&&/.*[^Z]$/i.test(n.date)&&(i=n.date.match(o))){var e=t(d(parseInt(i[1],10),parseInt(i[2],10),parseInt(i[3]||1,10)),3),a=e[0],s=e[1],h=e[2];n.date="".concat(a,"-").concat(s,"-").concat(h).concat(i[4]||"")}return m.bind(this)(n)},e.InitJalali=function(){var n=t(u(this.$y,this.$M+1,this.$D),3),i=n[0],r=n[1],e=n[2];this.$jy=i,this.$jM=r-1,this.$jD=e},e.startOf=function(n,i){var e=this;if(!s(this))return D.bind(this)(n,i);var a=!!M(i)||i,u=h(n),o=function(n,i){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.$jy,s=t(d(r,i+1,n),3),h=s[0],u=s[1],o=s[2],f=x(new Date(h,u-1,o),e);return a?f:f.endOf(c)},f=(this.$W+(7-r.$fdow))%7;switch(u){case $:return a?o(1,0):o(0,0,this.$jy+1);case l:return a?o(1,this.$jM):o(0,(this.$jM+1)%12,this.$jy+parseInt((this.$jM+1)/12,10));case"week":return o(a?this.$jD-f:this.$jD+(6-f),this.$jM);default:return D.bind(this)(n,i)}},e.$set=function(n,i){var r=this;if(!s(this))return g.bind(this)(n,i);var e=function(n,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r.$jy,a=t(d(e,i+1,n),3),s=a[0],h=a[1],u=a[2];return r.$d.setDate(u),r.$d.setMonth(h-1),r.$d.setFullYear(s),r};switch(h(n)){case"date":case c:e(i,this.$jM);break;case l:e(this.$jD,i);break;case $:e(this.$jD,this.$jM,i);break;default:return g.bind(this)(n,i)}return this.init(),this},e.add=function(t,n){var i=this;if(!s(this))return w.bind(this)(t,n);t=Number(t);var r=!n||1!==n.length&&"ms"!==n?h(n):n;if(["M",l].indexOf(r)>-1){var e=this.$jM+t,a=e<0?-Math.ceil(-e/12):parseInt(e/12,10);return this.add(a,$).set(l,e-12*a)}if(["y",$].indexOf(r)>-1)return function(n,r){var e=i.set("date",1).set(n,r+t);return e.set("date",Math.min(i.$jD,e.daysInMonth()))}($,this.$jy);if(["d",c].indexOf(r)>-1){var u=new Date(this.$d);return u.setDate(u.getDate()+t),x(u,this)}return w.bind(this)(t,n)},e.format=function(t,n){var i=this;if(!s(this))return I.bind(this)(t,n);var r=t||"YYYY-MM-DDTHH:mm:ssZ",e=(n||this.$locale()).jmonths;return r.replace(f,function(t){if(t.indexOf("[")>-1)return t.replace(/\[|\]/g,"");switch(t){case"YY":return String(i.$jy).slice(-2);case"YYYY":return String(i.$jy);case"M":return String(i.$jM+1);case"MM":return v(i.$jM+1,2,"0");case"MMM":return e[i.$jM].slice(0,3);case"MMMM":return e[i.$jM];case"D":return String(i.$jD);case"DD":return v(i.$jD,2,"0");default:return I.bind(i)(t,n)}})},e.diff=function(t,n,i){if(!s(this))return O.bind(this)(t,n,i);var e=h(n),a=r(t),u=y(this,a);switch(e){case $:u/=12;break;case l:break;default:return O.bind(this)(t,n,i)}return i?u:_(u)},e.year=function(){return s(this)?this.$jy:Y.bind(this)()},e.month=function(){return s(this)?this.$jM:C.bind(this)()},e.date=function(){return s(this)?this.$jD:S.bind(this)()},e.daysInMonth=function(){return s(this)?this.endOf(l).$jD:J.bind(this)()},e.toArray=function(){return s(this)?[this.$jy,this.$jM,this.$jD,this.$H,this.$m,this.$s,this.$ms]:k.bind(this)()},e.clone=function(){return x(this.toDate(),this)}}});
//# sourceMappingURL=jalaliday.min.js.map

@@ -5,3 +5,3 @@ // Custom Jest transform implementation that wraps babel-jest and injects our

module.exports = require('babel-jest').createTransformer({
presets: ['env'] // or whatever
presets: ['@babel/preset-env'] // or whatever
})
{
"name": "jalaliday",
"version": "2.2.0",
"version": "2.2.1",
"description": "Persian (Jalali, Khorshidi) Plugin for Day.js",

@@ -11,3 +11,3 @@ "main": "dist/jalaliday.cjs.min.js",

"test": "jest",
"lint": "eslint src/* test/* build/*",
"lint": "eslint src/* test/*",
"build": "bili",

@@ -50,16 +50,17 @@ "release": "standard-version $* && git push --follow-tags && npm publish",

"devDependencies": {
"babel-preset-env": "^1.7.0",
"bili": "^3.1.2",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-jest": "^21.15.0",
"jest": "^22.4.3",
"@babel/preset-env": "^7.3.4",
"bili": "^4.4.0",
"codecov": "^3.2.0",
"eslint": "^5.15.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.3.0",
"jest": "^24.3.1",
"mockdate": "^2.0.2",
"pre-commit": "^1.2.2",
"standard-version": "latest"
"standard-version": "5.0.1"
},
"dependencies": {
"dayjs": "^1.7.7"
"dayjs": "^1.8.9"
}
}

@@ -10,5 +10,5 @@ /* eslint-disable */

/* MOD -- Modulus function which works for non-integers. */
const $floor = Math.floor
function mod(a, b) {
return a - (b * Math.floor(a / b))
return a - (b * $floor(a / b))
}

@@ -18,5 +18,5 @@

function leap_gregorian(year) {
function lg(year) {
return ((year % 4) == 0) &&
(!(((year % 100) == 0) && ((year % 400) != 0)))
(!(((year % 100) == 0) && ((year % 400) != 0)))
}

@@ -26,15 +26,16 @@

let GREGORIAN_EPOCH = 1721425.5
// GREGORIAN_EPOCH
const GE = 1721425.5
function gregorian_to_jd(year, month, day) {
return (GREGORIAN_EPOCH - 1) +
(365 * (year - 1)) +
Math.floor((year - 1) / 4) +
(-Math.floor((year - 1) / 100)) +
Math.floor((year - 1) / 400) +
Math.floor((((367 * month) - 362) / 12) +
((month <= 2) ? 0 :
(leap_gregorian(year) ? -1 : -2)
) +
day)
function g2j(year, month, day) {
return (GE - 1) +
(365 * (year - 1)) +
$floor((year - 1) / 4) +
(-$floor((year - 1) / 100)) +
$floor((year - 1) / 400) +
$floor((((367 * month) - 362) / 12) +
((month <= 2) ? 0 :
(lg(year) ? -1 : -2)
) +
day)
}

@@ -44,53 +45,52 @@

function jd_to_gregorian(jd) {
let wjd,
depoch,
quadricent,
dqc,
cent,
dcent,
quad,
dquad,
yindex,
year,
yearday,
leapadj
function j2g(jd) {
let wjd,
depoch,
quadricent,
dqc,
cent,
dcent,
quad,
dquad,
yindex,
year,
yearday,
leapadj
wjd = Math.floor(jd - 0.5) + 0.5
depoch = wjd - GREGORIAN_EPOCH
quadricent = Math.floor(depoch / 146097)
dqc = mod(depoch, 146097)
cent = Math.floor(dqc / 36524)
dcent = mod(dqc, 36524)
quad = Math.floor(dcent / 1461)
dquad = mod(dcent, 1461)
yindex = Math.floor(dquad / 365)
year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex
if (!((cent == 4) || (yindex == 4))) {
wjd = $floor(jd - 0.5) + 0.5
depoch = wjd - GE
quadricent = $floor(depoch / 146097)
dqc = mod(depoch, 146097)
cent = $floor(dqc / 36524)
dcent = mod(dqc, 36524)
quad = $floor(dcent / 1461)
dquad = mod(dcent, 1461)
yindex = $floor(dquad / 365)
year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex
if (!((cent == 4) || (yindex == 4))) {
year++
}
yearday = wjd - gregorian_to_jd(year, 1, 1)
leapadj = ((wjd < gregorian_to_jd(year, 3, 1)) ? 0
}
yearday = wjd - g2j(year, 1, 1)
leapadj = ((wjd < g2j(year, 3, 1)) ? 0
:
(leap_gregorian(year) ? 1 : 2)
(lg(year) ? 1 : 2)
)
var month = Math.floor((((yearday + leapadj) * 12) + 373) / 367),
day = (wjd - gregorian_to_jd(year, month, 1)) + 1
let month = $floor((((yearday + leapadj) * 12) + 373) / 367),
day = (wjd - g2j(year, month, 1)) + 1
return [year, month, day]
return [year, month, day]
}
// PERSIAN_EPOCH
const PE = 1948320.5
let PERSIAN_EPOCH = 1948320.5
// PERSIAN_TO_JD -- Determine Julian day from Persian date
function persian_to_jd(year, month, day) {
let epbase,
epyear
function p2j(year, month, day) {
let epbase, epyear
epbase = year - ((year >= 0) ? 474 : 473)
epyear = 474 + mod(epbase, 2820)
epbase = year - ((year >= 0) ? 474 : 473)
epyear = 474 + mod(epbase, 2820)
return day +
return day +
((month <= 7) ?

@@ -100,6 +100,6 @@ ((month - 1) * 31) :

) +
Math.floor(((epyear * 682) - 110) / 2816) +
$floor(((epyear * 682) - 110) / 2816) +
(epyear - 1) * 365 +
Math.floor(epbase / 2820) * 1029983 +
(PERSIAN_EPOCH - 1)
$floor(epbase / 2820) * 1029983 +
(PE - 1)
}

@@ -109,50 +109,41 @@

function jd_to_persian(jd) {
let year,
month,
day,
depoch,
cycle,
cyear,
ycycle,
aux1,
aux2,
yday
function j2p(jd) {
let year,
month,
day,
depoch,
cycle,
cyear,
ycycle,
aux1,
aux2,
yday
jd = Math.floor(jd) + 0.5
jd = $floor(jd) + 0.5
depoch = jd - persian_to_jd(475, 1, 1)
cycle = Math.floor(depoch / 1029983)
cyear = mod(depoch, 1029983)
if (cyear == 1029982) {
depoch = jd - p2j(475, 1, 1)
cycle = $floor(depoch / 1029983)
cyear = mod(depoch, 1029983)
if (cyear == 1029982) {
ycycle = 2820
} else {
aux1 = Math.floor(cyear / 366)
aux2 = mod(cyear, 366)
ycycle = Math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) +
} else {
aux1 = $floor(cyear / 366)
aux2 = mod(cyear, 366)
ycycle = $floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) +
aux1 + 1
}
}
year = ycycle + (2820 * cycle) + 474
if (year <= 0) {
if (year <= 0) {
year--
}
yday = (jd - persian_to_jd(year, 1, 1)) + 1
month = (yday <= 186) ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30)
day = (jd - persian_to_jd(year, month, 1)) + 1
return [year, month, day]
}
yday = (jd - p2j(year, 1, 1)) + 1
month = (yday <= 186) ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30)
day = (jd - p2j(year, month, 1)) + 1
return [year, month, day]
}
function toJalaali(y, m, d) {
return jd_to_persian(gregorian_to_jd(y, m, d));
}
function toGregorian(y, m, d) {
return jd_to_gregorian(persian_to_jd(y, m, d));
}
export default {
toJalaali,
toGregorian
J: (y, m, d) => j2p(g2j(y, m, d)),
G: (y, m, d) => j2g(p2j(y, m, d))
}

@@ -7,3 +7,8 @@ import jdate from './calendar'

const U = proto.$utils()
const $isJalali = v => v.$C === 'jalali'
const $prettyUnit = U.prettyUnit || U.p
const $isUndefined = U.isUndefined || U.u
const $padStart = U.padStart || U.s
const $monthDiff = U.monthDiff || U.m
const $absFloor = U.absFloor || U.a
const wrapperOfTruth = action => function (...args) {

@@ -56,3 +61,3 @@ const unsure = action.bind(this)(...args)

proto.isJalali = function () {
return this.$C === 'jalali'
return $isJalali(this)
}

@@ -73,3 +78,2 @@

this.$C = cfg.calendar || this.$C || dayjs.$C
if (this.isJalali()) {

@@ -82,8 +86,9 @@ this.InitJalali()

let reg
this.$C = cfg.calendar || this.$C || dayjs.$C
// eslint-disable-next-line no-cond-assign
if (cfg.jalali && (typeof cfg.date === 'string') &&
(/.*[^Z]$/i.test(cfg.date)) && // looking for a better way
(reg = cfg.date.match(C.REGEX_PARSE))) {
if (cfg.jalali && (typeof cfg.date === 'string')
&& (/.*[^Z]$/i.test(cfg.date)) // looking for a better way
&& (reg = cfg.date.match(C.REGEX_PARSE))) {
// 1397-08-08 or 13970808
const [y, m, d] = jdate.toGregorian(
const [y, m, d] = jdate.G(
parseInt(reg[1], 10),

@@ -99,3 +104,3 @@ parseInt(reg[2], 10),

proto.InitJalali = function () {
const [jy, jm, jd] = jdate.toJalaali(this.$y, this.$M + 1, this.$D)
const [jy, jm, jd] = jdate.J(this.$y, this.$M + 1, this.$D)
this.$jy = jy

@@ -107,9 +112,9 @@ this.$jM = jm - 1

proto.startOf = function (units, startOf) { // startOf -> endOf
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldStartOf.bind(this)(units, startOf)
}
const isStartOf = !U.isUndefined(startOf) ? startOf : true
const unit = U.prettyUnit(units)
const isStartOf = !$isUndefined(startOf) ? startOf : true
const unit = $prettyUnit(units)
const instanceFactory = (d, m, y = this.$jy) => {
const [gy, gm, gd] = jdate.toGregorian(y, m + 1, d)
const [gy, gm, gd] = jdate.G(y, m + 1, d)
const ins = wrapper(new Date(gy, gm - 1, gd), this)

@@ -125,3 +130,7 @@ return isStartOf ? ins : ins.endOf(C.D)

return isStartOf ? instanceFactory(1, this.$jM)
: instanceFactory(0, this.$jM + 1)
: instanceFactory(
0,
(this.$jM + 1) % 12,
this.$jy + parseInt((this.$jM + 1) / 12, 10)
)
case C.W:

@@ -135,9 +144,9 @@ return isStartOf ? instanceFactory(this.$jD - WModifier, this.$jM)

proto.$set = function (units, int) { // private set
if (!this.isJalali()) {
proto.$set = function (units, int) {
if (!$isJalali(this)) {
return old$Set.bind(this)(units, int)
}
const unit = U.prettyUnit(units)
const unit = $prettyUnit(units)
const instanceFactory = (d, m, y = this.$jy) => {
const [gy, gm, gd] = jdate.toGregorian(y, m + 1, d)
const [gy, gm, gd] = jdate.G(y, m + 1, d)
this.$d.setDate(gd)

@@ -150,2 +159,3 @@ this.$d.setMonth(gm - 1)

case C.DATE:
case C.D:
instanceFactory(int, this.$jM)

@@ -167,3 +177,3 @@ break

proto.add = function (number, units) {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldAdd.bind(this)(number, units)

@@ -173,3 +183,3 @@ }

// units === 'ms' hard code here, will update in next release
const unit = (units && (units.length === 1 || units === 'ms')) ? units : U.prettyUnit(units)
const unit = (units && (units.length === 1 || units === 'ms')) ? units : $prettyUnit(units)
const instanceFactory = (u, n) => {

@@ -180,3 +190,5 @@ const date = this.set(C.DATE, 1).set(u, n + number)

if (['M', C.M].indexOf(unit) > -1) {
return instanceFactory(C.M, this.$jM)
const n = this.$jM + number
const y = n < 0 ? -Math.ceil(-n / 12) : parseInt(n / 12, 10)
return this.add(y, C.Y).set(C.M, n - (y * 12))
}

@@ -196,3 +208,3 @@ if (['y', C.Y].indexOf(unit) > -1) {

proto.format = function (formatStr, localeObject) {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldFormat.bind(this)(formatStr, localeObject)

@@ -213,3 +225,3 @@ }

case 'MM':
return U.padStart(this.$jM + 1, 2, '0')
return $padStart(this.$jM + 1, 2, '0')
case 'MMM':

@@ -222,3 +234,3 @@ return jmonths[this.$jM].slice(0, 3)

case 'DD':
return U.padStart(this.$jD, 2, '0')
return $padStart(this.$jD, 2, '0')
default:

@@ -231,8 +243,8 @@ return oldFormat.bind(this)(match, localeObject)

proto.diff = function (input, units, float) {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldDiff.bind(this)(input, units, float)
}
const unit = U.prettyUnit(units)
const unit = $prettyUnit(units)
const that = dayjs(input)
let result = U.monthDiff(this, that)
let result = $monthDiff(this, that)
switch (unit) {

@@ -247,7 +259,7 @@ case C.Y:

}
return float ? result : U.absFloor(result)
return float ? result : $absFloor(result)
}
proto.year = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldYear.bind(this)()

@@ -259,3 +271,3 @@ }

proto.month = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldMonth.bind(this)()

@@ -267,3 +279,3 @@ }

proto.date = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldDate.bind(this)()

@@ -275,3 +287,3 @@ }

proto.daysInMonth = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldDaysInMonth.bind(this)()

@@ -283,3 +295,3 @@ }

proto.toArray = function () {
if (!this.isJalali()) {
if (!$isJalali(this)) {
return oldToArray.bind(this)()

@@ -286,0 +298,0 @@ }

@@ -1,2 +0,1 @@

import MockDate from 'mockdate'

@@ -23,116 +22,20 @@ import dayjs from 'dayjs'

describe('Parse Valid String', () => {
// 2018-09-04
const date = dayjs('1397/06/13', { jalali: true })
it('Setting calendar converts date', () => {
const date = dayjs('1397/06/13', { jalali: true }).calendar('gregory')
expect(date.$y).toEqual(2018)
expect(date.$M).toEqual(8)
expect(date.$D).toEqual(4)
test('valid jalali date', () => {
expect(date.year()).toEqual(1397)
expect(date.month()).toEqual(5)
expect(date.date()).toEqual(13)
})
const gregory = date.calendar('gregory')
test('convert to gregory', () => {
expect(gregory.year()).toEqual(2018)
expect(gregory.month()).toEqual(8)
expect(gregory.date()).toEqual(4)
})
const date2 = dayjs('2018/09/04').calendar('jalali')
expect(date2.$jy).toEqual(1397)
expect(date2.$jM).toEqual(5)
expect(date2.$jD).toEqual(13)
})
it('Parse invalid String', () => {
const date = dayjs('', { jalali: true })
expect(date.year()).toBeNaN()
const date2 = dayjs(null, { jalali: true })
expect(date2.year()).toBeNaN()
test('keep instance calendar on manipulation', () => {
const date = dayjs().calendar('jalali')
expect(date.add(1, 'month').isJalali()).toEqual(true)
expect(dayjs(date).startOf('month').$C).toEqual('jalali')
expect(dayjs(date).add(1, 'month').$C).toEqual('jalali')
expect(dayjs(date).add(1, 'month').add(1, 'month').isJalali()).toEqual(true)
})
it('startOfMonth', () => {
const date = dayjs('1397/06/13', { jalali: true })
const date2 = date.startOf('month')
expect(date2.year()).toEqual(date.year())
expect(date2.month()).toEqual(date.month())
expect(date2.date()).toEqual(1)
})
it('startOfYear', () => {
const date = dayjs('1397/06/13', { jalali: true })
const date2 = date.startOf('year')
expect(date2.year()).toEqual(date.year())
expect(date2.month()).toEqual(0)
expect(date2.date()).toEqual(1)
})
it('startOfWeek', () => {
const date = dayjs('1397/06/13', { jalali: true })
const date2 = date.startOf('week')
expect(date2.day()).toEqual(6)
})
it('endOfWeek', () => {
const date = dayjs('1397/06/13', { jalali: true })
const date2 = date.endOf('week')
expect(date2.day()).toEqual(5)
})
it('dayInMonth', () => {
const date = dayjs('1397/06/13', { jalali: true })
expect(date.daysInMonth()).toEqual(31)
})
it('format', () => {
const date = dayjs('1397/06/13', { jalali: true })
expect(date.format('YY')).toEqual(String(97))
expect(date.format('YYYY')).toEqual(String(1397))
expect(date.format('M')).toEqual('6')
expect(date.format('MM')).toEqual('06')
expect(date.format('MMMM')).toEqual('Shahrivar')
expect(date.locale('fa').format('MMMM')).toEqual('شهریور')
expect(date.format('DD')).toEqual('13')
expect(date.format('D')).toEqual('13')
expect(date.format('W')).toEqual('W')
expect(date.format('HH')).toEqual('00')
})
describe('add two date', () => {
let a = null
let b = null
beforeEach(() => {
a = dayjs('1397/06/01', { jalali: true })
b = dayjs('1397/09/10', { jalali: true })
})
it('add date', () => {
expect(a.add(100, 'day')).toEqual(b)
})
})
describe('diff two date', () => {
let a = null
let b = null
beforeEach(() => {
a = dayjs('1397/06/01', { jalali: true })
b = dayjs('1397/09/10', { jalali: true })
})
it('diff(month)', () => {
expect(a.diff(b, 'month', false)).toEqual(-3)
})
it('diff(day)', () => {
expect(a.diff(b, 'day')).toEqual(-100)
})
it('diff(day): a gregory and jalali', () => {
expect(a.calendar('gregory').diff(b, 'day')).toEqual(-100)
})
it('diff(year)', () => {
expect(a.diff(b, 'year')).toEqual(0)
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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