| 1
2
3
4
5
6
7
8
9
10 |
5149x | /*!
*
* persian-date - 0.2.3
* Reza Babakhani <babakhani.reza@gmail.com>
* http://babakhani.github.io/PersianWebToolkit/docs/persian-date/
* Under WTFPL license
*
*
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.persianDate=t():e.persianDate=t()}(this,function(){return function(e){function t(r){if(a[r])return a[r].exports;var n=a[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var a={};return t.m=e,t.c=a,t.i=function(e){return e},t.d=function(e,a,r){t.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(a,"a",a),a},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t,a){"use strict";e.exports={durationUnit:{year:["y","years","year"],month:["M","months","month"],day:["d","days","day"],hour:["h","hours","hour"],minute:["m","minutes","minute"],second:["s","second","seconds"],millisecond:["ms","milliseconds","millisecond"],week:["w","","weeks","week"]},GREGORIAN_EPOCH:1721425.5,PERSIAN_EPOCH:1948320.5,monthRange:{1:{name:{fa:"فروردین"},abbr:{fa:"فرو"}},2:{name:{fa:"اردیبهشت"},abbr:{fa:"ارد"}},3:{name:{fa:"خرداد"},abbr:{fa:"خرد"}},4:{name:{fa:"تیر"},abbr:{fa:"تیر"}},5:{name:{fa:"مرداد"},abbr:{fa:"مرد"}},6:{name:{fa:"شهریور"},abbr:{fa:"شهر"}},7:{name:{fa:"مهر"},abbr:{fa:"مهر"}},8:{name:{fa:"آبان"},abbr:{fa:"آبا"}},9:{name:{fa:"آذر"},abbr:{fa:"آذر"}},10:{name:{fa:"دی"},abbr:{fa:"دی"}},11:{name:{fa:"بهمن"},abbr:{fa:"بهم"}},12:{name:{fa:"اسفند"},abbr:{fa:"اسف"}}},weekRange:{1:{name:{fa:"شنبه"},abbr:{fa:"ش"}},2:{name:{fa:"یکشنبه"},abbr:{fa:"ی"}},3:{name:{fa:"دوشنبه"},abbr:{fa:"د"}},4:{name:{fa:"سه شنبه"},abbr:{fa:"س"}},5:{name:{fa:"چهار شنبه"},abbr:{fa:"چ"}},6:{name:{fa:"پنج شنبه"},abbr:{fa:"پ"}},0:{name:{fa:"جمعه"},abbr:{fa:"ج"}}},persianDaysName:["اورمزد","بهمن","اوردیبهشت","شهریور","سپندارمذ","خورداد","امرداد","دی به آذز","آذز","آبان","خورشید","ماه","تیر","گوش","دی به مهر","مهر","سروش","رشن","فروردین","بهرام","رام","باد","دی به دین","دین","ارد","اشتاد","آسمان","زامیاد","مانتره سپند","انارام","زیادی"]}},function(e,t,a){"use strict";function r(e,t){Iif(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n=function(){function e(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,a,r){return a&&e(t.prototype,a),r&&e(t,r),t}}(),i=a(0).durationUnit,s=function(){function e(){r(this,e)}return n(e,[{key:"toPersianDigit",value:function(e){return e.toString().toPersianDigit()}},{key:"isArray",value:function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{key:"isNumber",value:function(e){return"number"==typeof e}},{key:"isDate",value:function(e){return e instanceof Date}},{key:"isUndefined",value:function(e){return void 0===e}},{key:"leftZeroFill",value:function(e,t){for(var a=e+"";a.length<t;)a="0"+a;return a}},{key:"normalizeDuration",value:function(){var e=void 0,t=void 0;return"string"==typeof arguments[0]?(e=arguments[0],t=arguments[1]):(t=arguments[0],e=arguments[1]),i.year.indexOf(e)>-1?e="year":i.month.indexOf(e)>-1?e="month":i.day.indexOf(e)>-1?e="day":i.hour.indexOf(e)>-1?e="hour":i.minute.indexOf(e)>-1?e="minute":i.second.indexOf(e)>-1&&(e="second"),{unit:e,value:t}}},{key:"absRound",value:function(e){return e<0?Math.ceil(e):Math.floor(e)}},{key:"mod",value:function(e,t){return e-t*Math.floor(e/t)}}]),e}();e.exports=s},function(e,t,a){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n=function(){function e(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,a,r){return a&&e(t.prototype,a),r&&e(t,r),t}}(),i=a(3),s=a(1),o=a(4),u=(new s).toPersianDigit,h=(new s).leftZeroFill,c=a(0).weekRange,f=a(0).persianDaysName,d=a(0).monthRange,l=function(){function t(e){r(this,t),this.algorithms=new i;var a=new s;if(a.isUndefined(e))this.gDate=new Date;else if(a.isDate(e))this.gDate=e;else if(a.isArray(e)){var n=e.slice();this.gDate=this.algorithms.persianArrayToGregorianDate(n)}else a.isNumber(e)?this.gDate=new Date(e):e instanceof t?this.gDate=e.gDate:"/Date("===e.substring(0,6)?this.gDate=new Date(parseInt(e.substr(6))):this.gDate=new Date;return this.pDate=this.algorithms.toPersianDate(this.gDate),this.version="0.2.3",this.formatPersian="_default",this._utcMode=!1,this}return n(t,[{key:"duration",value:function(e,t){return new o(e,t)}},{key:"isDuration",value:function(e){return e instanceof o}},{key:"add",value:function(e,a){var r=new o(e,a)._data;if(r.years>0){var n=this.year()+r.years;this.year(n)}if(r.months>0){var i=this.month()+r.months;this.month(i)}if(r.days>0){var s=this.date()+r.days;this.date(s)}if(r.hours>0){var u=this.hour()+r.hours;this.hour(u)}if(r.minutes>0){var h=this.minute()+r.minutes;this.minute(h)}if(r.seconds>0){var c=this.second()+r.seconds;this.second(c)}if(r.milliseconds>0){var f=this.milliseconds()+r.milliseconds;this.milliseconds(f)}return new t(this.valueOf())}},{key:"subtract",value:function(e,a){var r=new o(e,a)._data;if(r.years>0){var n=this.year()-r.years;this.year(n)}if(r.months>0){var i=this.month()-r.months;this.month(i)}if(r.days>0){var s=this.date()-r.days;this.date(s)}if(r.hours>0){var u=this.hour()-r.hours;this.hour(u)}if(r.minutes>0){var h=this.minute()-r.minutes;this.minute(h)}if(r.seconds>0){var c=this.second()-r.seconds;this.second(c)}if(r.milliseconds>0){var f=this.milliseconds()-r.milliseconds;this.milliseconds(f)}return new t(this.valueOf())}},{key:"formatNumber",value:function(){var t=void 0,a=this;return"_default"===this.formatPersian?t=void 0!==e&&void 0!==e.exports?a.formatPersian!==!1:window.formatPersian!==!1:this.formatPersian===!0?t=!0:this.formatPersian===!1?t=!1:Error('Invalid Config "formatPersian" !!'),t}},{key:"format",value:function(e){function t(e){switch(e){case"a":return i?n.hour>=12?"ب ظ":"ق ظ":n.hour>=12?"PM":"AM";case"H":return s(n.hour);case"HH":return s(h(n.hour,2));case"h":return s(n.hour%12);case"hh":return s(h(n.hour%12,2));case"m":case"mm":return s(h(n.minute,2));case"s":return s(n.second);case"ss":return s(h(n.second,2));case"D":return s(h(n.date));case"DD":return s(h(n.date,2));case"DDD":var t=a.startOf("year");return s(h(a.diff(t,"days"),3));case"DDDD":var r=a.startOf("year");return s(h(a.diff(r,"days"),3));case"d":return s(a.pDate.weekDayNumber);case"ddd":return c[a.pDate.weekDayNumber].abbr.fa;case"dddd":return c[a.pDate.weekDayNumber].name.fa;case"ddddd":return f[a.pDate.monthDayNumber];case"w":var o=a.startOf("year"),u=parseInt(a.diff(o,"days")/7)+1;return s(u);case"ww":var l=a.startOf("year"),m=h(parseInt(a.diff(l,"days")/7)+1,2);return s(m);case"M":return s(n.month);case"MM":return s(h(n.month,2));case"MMM":return d[n.month].abbr.fa;case"MMMM":return d[n.month].name.fa;case"YY":var y=n.year.toString().split("");return s(y[2]+y[3]);case"YYYY":return s(n.year);case"Z":var v="+",D=Math.round(n.timezone/60),p=n.timezone%60;p<0&&(p*=-1),D<0&&(v="-",D*=-1);var g=v+h(D,2)+":"+h(p,2);return s(g);case"ZZ":var w="+",k=Math.round(n.timezone/60),b=n.timezone%60;b<0&&(b*=-1),k<0&&(w="-",k*=-1);var M=w+h(k,2)+""+h(b,2);return s(M);case"X":return a.unix();case"LT":return a.format("h:m a");case"L":return a.format("YYYY/MM/DD");case"l":return a.format("YYYY/M/D");case"LL":return a.format("MMMM DD YYYY");case"ll":return a.format("MMM DD YYYY");case"LLL":return a.format("MMMM YYYY DD h:m a");case"lll":return a.format("MMM YYYY DD h:m a");case"LLLL":return a.format("dddd D MMMM YYYY h:m a");case"llll":return a.format("ddd D MMM YYYY h:m a")}}var a=this,r=/([[^[]*])|(\\)?(Mo|MM?M?M?|Do|DD?D?D?|ddddd|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|X|LT|ll?l?l?|LL?L?L?)/g,n={year:a.year(),month:a.month(),hour:a.hours(),minute:a.minutes(),second:a.seconds(),date:a.date(),timezone:a.zone(),unix:a.unix()},i=a.formatNumber(),s=function(e){return i?u(e):e};return e?e.replace(r,t):"YYYY-MM-DD HH:mm:ss a".replace(r,t)}},{key:"diff",value:function(e,t,a){var r=this,n=e,i=r.gDate-n.gDate-0,s=r.year()-n.year(),o=r.month()-n.month(),u=(r.date()-n.date())*-1,h=void 0;return h="months"===t||"month"===t?12*s+o+u/30:"years"===t||"year"===t?s+(o+u/30)/12:"seconds"===t||"second"===t?i/1e3:"minutes"===t||"minute"===t?i/6e4:"hours"===t||"hour"===t?i/36e5:"days"===t||"day"===t?i/864e5:"weeks"===t||"week"===t?i/6048e5:i,h<0&&(h*=-1),a?h:Math.round(h)}},{key:"startOf",value:function(e){switch(e){case"years":case"year":return new t([this.year(),1,1]);case"months":case"month":return new t([this.year(),this.month(),1]);case"days":case"day":return new t([this.year(),this.month(),this.date(),0,0,0]);case"hours":case"hour":return new t([this.year(),this.month(),this.date(),this.hours(),0,0]);case"minutes":case"minute":return new t([this.year(),this.month(),this.date(),this.hours(),this.minutes(),0]);case"seconds":case"second":return new t([this.year(),this.month(),this.date(),this.hours(),this.minutes(),this.seconds()]);case"weeks":case"week":var a=this.pDate.weekDayNumber;return 0===a?new t([this.year(),this.month(),this.date()]):new t([this.year(),this.month(),this.date()]).subtract("days",a);default:return this}}},{key:"endOf",value:function(e){switch(e){case"years":case"year":var a=this.isLeapYear()?30:29;return new t([this.year(),12,a,23,59,59]);case"months":case"month":var r=this.daysInMonth(this.year(),this.month());return new t([this.year(),this.month(),r,23,59,59]);case"days":case"day":return new t([this.year(),this.month(),this.date(),23,59,59]);case"hours":case"hour":return new t([this.year(),this.month(),this.date(),this.hours(),59,59]);case"minutes":case"minute":return new t([this.year(),this.month(),this.date(),this.hours(),this.minutes(),59]);case"seconds":case"second":return new t([this.year(),this.month(),this.date(),this.hours(),this.minutes(),this.seconds()]);case"weeks":case"week":var n=this.pDate.weekDayNumber;return n=6===n?7:6-n,new t([this.year(),this.month(),this.date()]).add("days",n);default:return this}}},{key:"sod",value:function(){return this.startOf("day")}},{key:"eod",value:function(){return this.endOf("day")}},{key:"zone",value:function(){return this.pDate.timeZoneOffset}},{key:"local",value:function(){var e=void 0;if(this._utcMode){var t=60*this.pDate.timeZoneOffset*1e3;return e=this.pDate.timeZoneOffset<0?this.valueOf()-t:this.valueOf()+t,this.gDate=new Date(e),this._updatePDate(),this._utcMode=!1,this}return this}},{key:"utc",value:function(e){var a=void 0;if(e)return new t(e).utc();if(this._utcMode)return this;var r=60*this.pDate.timeZoneOffset*1e3;return a=this.pDate.timeZoneOffset<0?this.valueOf()+r:this.valueOf()-r,this.gDate=new Date(a),this._updatePDate(),this._utcMode=!0,this}},{key:"isUtc",value:function(){return this._utcMode}},{key:"isDST",value:function(){var e=this.month(),t=this.date();return!(e<7)&&(7==e&&t>=2||e>=7||void 0)}},{key:"isLeapYear",value:function(){return this.algorithms.isLeapPersian(this.year())}},{key:"daysInMonth",value:function(e,t){var a=e||this.year(),r=t||this.month();return r<1||r>12?0:r<7?31:r<12?30:this.algorithms.isLeapPersian(a)?30:29}},{key:"toDate",value:function(){return this.gDate}},{key:"toArray",value:function(){return[this.year(),this.month(),this.date(),this.hour(),this.minute(),this.second(),this.millisecond()]}},{key:"_valueOf",value:function(){return this.gDate.valueOf()}},{key:"unix",value:function(e){var a=void 0;if(e)return new t(1e3*e);var r=this.gDate.valueOf().toString();return a=r.substring(0,r.length-3),parseInt(a)}},{key:"isPersianDate",value:function(e){return e instanceof t}},{key:"millisecond",value:function(e){return this.milliseconds(e)}},{key:"milliseconds",value:function(e){return e?(this.gDate.setMilliseconds(e),this._updatePDate(),this):this.pDate.milliseconds}},{key:"second",value:function(e){return this.seconds(e)}},{key:"seconds",value:function(e){return e|0===e?(this.gDate.setSeconds(e),this._updatePDate(),this):this.pDate.seconds}},{key:"minute",value:function(e){return this.minutes(e)}},{key:"minutes",value:function(e){return e||0===e?(this.gDate.setMinutes(e),this._updatePDate(),this):parseInt(this.pDate.minutes)}},{key:"hour",value:function(e){return this.hours(e)}},{key:"hours",value:function(e){return e|0===e?(this.gDate.setHours(e),this._updatePDate(),this):this.pDate.hours}},{key:"dates",value:function(e){return this.date(e)}},{key:"date",value:function(e){if(e||0===e){var t=this.algorithms.getPersianArrayFromPDate(this.pDate);return t[2]=e,this.gDate=this.algorithms.persianArrayToGregorianDate(t),this._updatePDate(),this}return this.pDate.date}},{key:"days",value:function(){return this.day()}},{key:"day",value:function(){return this.pDate.day}},{key:"month",value:function(e){if(e|0===e){var t=this.algorithms.getPersianArrayFromPDate(this.pDate);return t[1]=e,this.gDate=this.algorithms.persianArrayToGregorianDate(t),this._updatePDate(),this}return this.pDate.month}},{key:"years",value:function(e){return this.year(e)}},{key:"year",value:function(e){if(e|0===e){var t=this.algorithms.getPersianArrayFromPDate(this.pDate);return t[0]=e,this.gDate=this.algorithms.persianArrayToGregorianDate(t),this._updatePDate(),this}return this.pDate.year}},{key:"getFirstWeekDayOfMonth",value:function(e,t){var a=this.algorithms.calcPersian(e,t,1),r=this.algorithms.calcGregorian(a[0],a[1],a[2]);return r[3]+2===8?1:r[3]+2===7?7:r[3]+2}},{key:"clone",value:function(){return new t(this.gDate)}},{key:"_updatePDate",value:function(){this.pDate=this.algorithms.toPersianDate(this.gDate)}},{key:"valueOf",value:function(){return this._valueOf()}}],[{key:"_utc",value:function(e){return e?new t(e).utc():(new t).utc()}},{key:"_unix",value:function(e){return e?new t(1e3*e).unix():(new t).unix()}}]),t}();e.exports=l},function(e,t,a){"use strict";function r(e,t){Iif(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n=function(){function e(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,a,r){return a&&e(t.prototype,a),r&&e(t,r),t}}(),i=a(0).GREGORIAN_EPOCH,s=a(0).PERSIAN_EPOCH,o=a(1),u=(new o).mod,h=function(){function e(){r(this,e)}return n(e,[{key:"jwday",value:function(e){return function(e,t){return e-t*Math.floor(e/t)}(Math.floor(e+1.5),7)}},{key:"isLeapGregorian",value:function(e){return e%4==0&&!(e%100==0&&e%400!=0)}},{key:"isLeapPersian",value:function(e){return 682*((e-(e>0?474:473))%2820+474+38)%2816<682}},{key:"gregorianToJd",value:function(e,t,a){return i-1+365*(e-1)+Math.floor((e-1)/4)+-Math.floor((e-1)/100)+Math.floor((e-1)/400)+Math.floor((367*t-362)/12+(t<=2?0:this.isLeapGregorian(e)?-1:-2)+a)}},{key:"jdToGregorian",value:function(e){var t=Math.floor(e-.5)+.5,a=t-i,r=Math.floor(a/146097),n=u(a,146097),s=Math.floor(n/36524),o=u(n,36524),h=Math.floor(o/1461),c=u(o,1461),f=Math.floor(c/365),d=400*r+100*s+4*h+f;4!=s&&4!=f&&d++;var l=t-this.gregorianToJd(d,1,1),m=t<this.gregorianToJd(d,3,1)?0:this.isLeapGregorian(d)?1:2,y=Math.floor((12*(l+m)+373)/367),v=t-this.gregorianToJd(d,y,1)+1;return new Array(d,y,v)}},{key:"persianToJd",value:function(e,t,a){var r=void 0,n=void 0;return r=e-(e>=0?474:473),n=474+u(r,2820),a+(t<=7?31*(t-1):30*(t-1)+6)+Math.floor((682*n-110)/2816)+365*(n-1)+1029983*Math.floor(r/2820)+(s-1)}},{key:"jdToPersian",value:function(e){var t=void 0,a=void 0,r=void 0,n=void 0,i=void 0,s=void 0,o=void 0,h=void 0,c=void 0,f=void 0;return e=Math.floor(e)+.5,n=e-this.persianToJd(475,1,1),i=Math.floor(n/1029983),s=u(n,1029983),1029982===s?o=2820:(h=Math.floor(s/366),c=u(s,366),o=Math.floor((2134*h+2816*c+2815)/1028522)+h+1),t=o+2820*i+474,t<=0&&(t-=1),f=e-this.persianToJd(t,1,1)+1,a=f<=186?Math.ceil(f/31):Math.ceil((f-6)/30),r=e-this.persianToJd(t,a,1)+1,new Array(t,a,r)}},{key:"calcPersian",value:function(e,t,a){var r=this.persianToJd(e,t,a),n=this.jdToGregorian(r);return new Array(n[0],n[1]-1,n[2])}},{key:"calcGregorian",value:function(e,t,a){var r=this.gregorianToJd(e,t+1,a)+Math.floor(.5)/86400,n=this.jdToPersian(r),i=this.jwday(r);return new Array(n[0],n[1],n[2],i)}},{key:"toPersianDate",value:function(e){var t=this.calcGregorian(e.getFullYear(),e.getMonth(),e.getDate()),a={};return a.monthDayNumber=t[2]-1,6==t[3]?a.weekDayNumber=1:5===t[3]?a.weekDayNumber=0:4===t[3]?a.weekDayNumber=6:3===t[3]?a.weekDayNumber=5:2===t[3]?a.weekDayNumber=4:1===t[3]?a.weekDayNumber=3:0===t[3]&&(a.weekDayNumber=2),a.year=t[0],a.month=t[1],a.day=a.weekDayNumber,a.date=t[2],a.hours=e.getHours(),a.minutes=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes(),a.seconds=e.getSeconds(),a.milliseconds=e.getMilliseconds(),a.timeZoneOffset=e.getTimezoneOffset(),a}},{key:"persianArrayToGregorianDate",value:function(e){void 0===e[1]&&(e[1]=1),void 0===e[2]&&(e[2]=1);var t=this.calcPersian(e[0],e[1],e[2]),a=new Date;return a.setYear(t[0]),a.setMonth(t[1]),a.setDate(t[2]),a.setHours(e[3]?e[3]:0),a.setMinutes(e[4]?e[4]:0),a.setSeconds(e[5]?e[5]:0),a.setMilliseconds(e[6]?e[6]:0),a}},{key:"getPersianArrayFromPDate",value:function(e){return[e.year,e.month,e.date,e.hours,e.minutes,e.seconds,e.milliseconds]}}]),e}();e.exports=h},function(e,t,a){"use strict";function r(e,t){Iif(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n=a(1),i=(new n).normalizeDuration,s=(new n).absRound,o=function e(t,a){r(this,e);var n={},o=this._data={},u=0,h=i(t,a);n[h.unit]=h.value,u=n.milliseconds||n.millisecond||n.ms||0;var c=n.years||n.year||n.y||0,f=n.months||n.month||n.M||0,d=n.weeks||n.w||n.week||0,l=n.days||n.d||n.day||0,m=n.hours||n.hour||n.h||0,y=n.minutes||n.minute||n.m||0,v=n.seconds||n.second||n.s||0;return this._milliseconds=u+1e3*v+6e4*y+36e5*m,this._days=l+7*d,this._months=f+12*c,o.milliseconds=u%1e3,v+=u/1e3,o.seconds=v%60,y+=s(v/60),o.minutes=y%60,m+=s(y/60),o.hours=m%24,l+=s(m/24),l+=7*d,o.days=l%30,f+=s(l/30),o.months=f%12,c+=s(f/12),o.years=c,this};o.prototype={valueOf:function(){return this._milliseconds+864e5*this._days+2592e6*this._months}},e.exports=o},function(e,t,a){"use strict";var r=a(2);String.prototype.toPersianDigit=function(e){return this.replace(/\d+/g,function(t){var a=[],r=[],n=void 0,i=void 0;for(n=0;n<t.length;n+=1)a.push(t.charCodeAt(n));for(i=0;i<a.length;i+=1)r.push(String.fromCharCode(a[i]+(e&&e===!0?1584:1728)));return r.join("")})},r.unix=r._unix,r.utc=r._utc,e.exports=r}])}); |