From 781ff83b98fcbd9eb72ce38b932998a8514aecef Mon Sep 17 00:00:00 2001 From: babakhani Date: Fri, 18 Aug 2017 19:21:02 +0430 Subject: [PATCH 1/2] add new leapyear algorithm --- dist/persian-date.js | 2 ++ src/algorithms.js | 64 +++++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/dist/persian-date.js b/dist/persian-date.js index ccb651d..5332777 100644 --- a/dist/persian-date.js +++ b/dist/persian-date.js @@ -1648,6 +1648,8 @@ var Algorithms = function () { key: 'isLeapPersian', value: function isLeapPersian(year) { return ((year - (year > 0 ? 474 : 473)) % 2820 + 474 + 38) * 682 % 2816 < 682; + // https://fa.wikipedia.org/wiki/%DA%AF%D8%A7%D9%87%E2%80%8C%D8%B4%D9%85%D8%A7%D8%B1%DB%8C_%D9%87%D8%AC%D8%B1%DB%8C_%D8%AE%D9%88%D8%B1%D8%B4%DB%8C%D8%AF%DB%8C_%D8%AD%D8%B3%D8%A7%D8%A8%DB%8C + // return parseFloat('0.' + ((year + 2346) * (0.24219858156)).toString().split('.')[1]) < 0.24219858156; } /** diff --git a/src/algorithms.js b/src/algorithms.js index 01b5f1b..dbf716e 100644 --- a/src/algorithms.js +++ b/src/algorithms.js @@ -12,7 +12,7 @@ class Algorithms { * @param j * @returns {*} */ - jwday(j) { + jwday (j) { let mod = function (a, b) { return a - (b * Math.floor(a / b)); }; @@ -25,7 +25,7 @@ class Algorithms { * @param year * @returns {boolean} */ - isLeapGregorian(year) { + isLeapGregorian (year) { return ((year % 4) === 0) && (!(((year % 100) === 0) && ((year % 400) !== 0))); } @@ -34,8 +34,10 @@ class Algorithms { * @param year * @returns {boolean} */ - isLeapPersian(year) { + isLeapPersian (year) { return ((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682; + // https://fa.wikipedia.org/wiki/%DA%AF%D8%A7%D9%87%E2%80%8C%D8%B4%D9%85%D8%A7%D8%B1%DB%8C_%D9%87%D8%AC%D8%B1%DB%8C_%D8%AE%D9%88%D8%B1%D8%B4%DB%8C%D8%AF%DB%8C_%D8%AD%D8%B3%D8%A7%D8%A8%DB%8C + // return parseFloat('0.' + ((year + 2346) * (0.24219858156)).toString().split('.')[1]) < 0.24219858156; } @@ -46,9 +48,9 @@ class Algorithms { * @param day * @returns {number} */ - gregorianToJd(year, month, day) { + gregorianToJd (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 : (this.isLeapGregorian(year) ? -1 : -2) - ) + day); + ) + day); } @@ -57,25 +59,25 @@ class Algorithms { * @param jd * @returns {Array} */ - jdToGregorian(jd) { + jdToGregorian (jd) { //let wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, dyindex, year, yearday, leapadj; let 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; + 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))) { year++; } let yearday = wjd - this.gregorianToJd(year, 1, 1), - leapadj = ((wjd < this.gregorianToJd(year, 3, 1)) ? 0 : (this.isLeapGregorian(year) ? 1 : 2)), - month = Math.floor((((yearday + leapadj) * 12) + 373) / 367), - day = (wjd - this.gregorianToJd(year, month, 1)) + 1; + leapadj = ((wjd < this.gregorianToJd(year, 3, 1)) ? 0 : (this.isLeapGregorian(year) ? 1 : 2)), + month = Math.floor((((yearday + leapadj) * 12) + 373) / 367), + day = (wjd - this.gregorianToJd(year, month, 1)) + 1; return new Array(year, month, day); } @@ -87,12 +89,12 @@ class Algorithms { * @param day * @returns {*} */ - persianToJd(year, month, day) { + persianToJd (year, month, day) { let 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); + ) + Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 + Math.floor(epbase / 2820) * 1029983 + (PERSIAN_EPOCH - 1); } @@ -101,7 +103,7 @@ class Algorithms { * @param jd * @returns {Array} */ - jdToPersian(jd) { + jdToPersian (jd) { let year, month, day, depoch, cycle, cyear, ycycle, aux1, aux2, yday; jd = Math.floor(jd) + 0.5; depoch = jd - this.persianToJd(475, 1, 1); @@ -133,9 +135,9 @@ class Algorithms { * @param day * @returns {Array} */ - calcPersian(year, month, day) { + calcPersian (year, month, day) { let j = this.persianToJd(year, month, day), - date = this.jdToGregorian(j); + date = this.jdToGregorian(j); return new Array(date[0], date[1] - 1, date[2]); } @@ -147,11 +149,11 @@ class Algorithms { * @param day * @returns {Array} */ - calcGregorian(year, month, day) { + calcGregorian (year, month, day) { // Update Julian day let j = this.gregorianToJd(year, month + 1, day) + (Math.floor(0 + 60 * (0 + 60 * 0) + 0.5) / 86400.0), - // Update Persian Calendar - perscal = this.jdToPersian(j), weekday = this.jwday(j); + // Update Persian Calendar + perscal = this.jdToPersian(j), weekday = this.jwday(j); return new Array(perscal[0], perscal[1], perscal[2], weekday); } @@ -161,9 +163,9 @@ class Algorithms { * @param gd * @returns {{}} */ - toPersianDate(gd) { + toPersianDate (gd) { let pa = this.calcGregorian(gd.getFullYear(), gd.getMonth(), gd.getDate()), - output = {}; + output = {}; output.monthDayNumber = pa[2] - 1; if (pa[3] == 6) { output.weekDayNumber = 1; @@ -198,10 +200,10 @@ class Algorithms { * @param parray persian-date array * @returns {Date} */ - persianArrayToGregorianDate(parray) { + persianArrayToGregorianDate (parray) { // Howha : javascript Cant Parse this array truly 2011,2,20 let pd = this.calcPersian(parray[0] ? parray[0] : 0, parray[1] ? parray[1] : 1, parray[2] ? parray[2] : 1), - gDate = new Date(pd[0], pd[1], pd[2]); + gDate = new Date(pd[0], pd[1], pd[2]); gDate.setYear(pd[0]); gDate.setMonth(pd[1]); gDate.setDate(pd[2]); @@ -218,7 +220,7 @@ class Algorithms { * @param pDate * @returns {array} */ - getPersianArrayFromPDate(pDate) { + getPersianArrayFromPDate (pDate) { return [pDate.year, pDate.month, pDate.date, pDate.hours, pDate.minutes, pDate.seconds, pDate.milliseconds]; } } From 06ad46699cd8b43312342679b8f254f935751df0 Mon Sep 17 00:00:00 2001 From: babakhani Date: Fri, 18 Aug 2017 22:01:20 +0430 Subject: [PATCH 2/2] fix subtract days from first day of month --- .eslintrc.json | 1 - CHANGELOG.md | 6 ++ bower.json | 35 +------ dist/persian-date.js | 14 ++- dist/persian-date.min.js | 4 +- package.json | 2 +- src/algorithms.js | 10 +- test/test.js | 207 ++++++++++++++++++++------------------- 8 files changed, 133 insertions(+), 146 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 0eda3db..3210a25 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,7 +12,6 @@ "__VERSION__": true }, "rules": { - "linebreak-style": [ "error", "unix" diff --git a/CHANGELOG.md b/CHANGELOG.md index b4a85cd..c01bf42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.2] +- fix bower + +## [0.2.1] +- Some dev env fix before release + ## [0.2.0] - Refactor all code to es6 - Hello webpack ,babel, mocha, istanbul, coveralls, travis, sync-pg diff --git a/bower.json b/bower.json index c917339..c2a463d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "persian-date", - "version": "0.2.0", + "version": "0.2.3", "main": [ "dist/<= pkg.version>/persian-date-<= pkg.version>.js" ], @@ -18,39 +18,6 @@ "source", "spec" ], - "dependencies": { - "eslint": "^4.4.1" - }, - "devDependencies": { - "babel-cli": "^6.0.0", - "babel-core": "^6.22.1", - "babel-loader": "^6.4.1", - "babel-plugin-import": "^1.1.1", - "babel-plugin-transform-runtime": "^6.22.0", - "babel-polyfill": "^6.22.0", - "babel-preset-es2015": "^6.24.0", - "babel-preset-latest": "^6.24.0", - "babel-runtime": "^6.22.0", - "chai": "^3.5.0", - "coveralls": "^2.13.0", - "grunt": "^1.0.1", - "grunt-babel": "^6.0.0", - "grunt-cli": "^0.1.13", - "grunt-contrib-watch": "^1.0.0", - "grunt-jsdoc-to-markdown": "^3.0.0", - "grunt-webpack": "^2.0.1", - "grunt-webpack-server": "^0.1.0", - "istanbul": "^0.4.5", - "jsdoc": "^3.2.0", - "jshint": "^2.9.4", - "load-grunt-tasks": "^3.5.2", - "mocha": "^3.2.0", - "mocha-lcov-reporter": "^0.0.2", - "pre-commit": "^1.2.2", - "sync-pkg": "^0.7.2", - "unminified-webpack-plugin": "^1.2.0", - "webpack": "^2.3.3" - }, "license": "WTFPL", "protocol": "https:", "slashes": true, diff --git a/dist/persian-date.js b/dist/persian-date.js index 5332777..7e20afe 100644 --- a/dist/persian-date.js +++ b/dist/persian-date.js @@ -1,6 +1,6 @@ /*! * - * persian-date - 0.2.0 + * persian-date - 0.2.3 * Reza Babakhani * http://babakhani.github.io/PersianWebToolkit/docs/persian-date/ * Under WTFPL license @@ -510,7 +510,7 @@ var PersianDateClass = function () { this.gDate = new Date(); } this.pDate = this.algorithms.toPersianDate(this.gDate); - this.version = "0.2.0"; + this.version = "0.2.3"; this.formatPersian = '_default'; this._utcMode = false; return this; @@ -1839,9 +1839,15 @@ var Algorithms = function () { }, { key: 'persianArrayToGregorianDate', value: function persianArrayToGregorianDate(parray) { + if (parray[1] === undefined) { + parray[1] = 1; + } + if (parray[2] === undefined) { + parray[2] = 1; + } // Howha : javascript Cant Parse this array truly 2011,2,20 - var pd = this.calcPersian(parray[0] ? parray[0] : 0, parray[1] ? parray[1] : 1, parray[2] ? parray[2] : 1), - gDate = new Date(pd[0], pd[1], pd[2]); + var pd = this.calcPersian(parray[0], parray[1], parray[2]), + gDate = new Date(); gDate.setYear(pd[0]); gDate.setMonth(pd[1]); gDate.setDate(pd[2]); diff --git a/dist/persian-date.min.js b/dist/persian-date.min.js index c98fbb8..174c3db 100644 --- a/dist/persian-date.min.js +++ b/dist/persian-date.min.js @@ -1,10 +1,10 @@ /*! * - * persian-date - 0.2.0 + * persian-date - 0.2.3 * Reza Babakhani * 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){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-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;a0){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){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;a0?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=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){var t=this.calcPersian(e[0]?e[0]:0,e[1]?e[1]:1,e[2]?e[2]:1),a=new Date(t[0],t[1],t[2]);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){if(!(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-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;a0){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){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;a0?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=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){if(!(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", "description": "Javascript date library for parsing, validating, manipulating, and formatting persian dates System.", diff --git a/src/algorithms.js b/src/algorithms.js index dbf716e..e543628 100644 --- a/src/algorithms.js +++ b/src/algorithms.js @@ -201,9 +201,15 @@ class Algorithms { * @returns {Date} */ persianArrayToGregorianDate (parray) { + if (parray[1] === undefined) { + parray[1] = 1; + } + if (parray[2] === undefined) { + parray[2] = 1; + } // Howha : javascript Cant Parse this array truly 2011,2,20 - let pd = this.calcPersian(parray[0] ? parray[0] : 0, parray[1] ? parray[1] : 1, parray[2] ? parray[2] : 1), - gDate = new Date(pd[0], pd[1], pd[2]); + let pd = this.calcPersian(parray[0], parray[1], parray[2]), + gDate = new Date(); gDate.setYear(pd[0]); gDate.setMonth(pd[1]); gDate.setDate(pd[2]); diff --git a/test/test.js b/test/test.js index 6bc6be3..6819299 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,5 @@ /*global describe,it*/ let assert = require('assert'); -let chai = require('chai'); let expect = require('chai').expect; let obj = require('../dist/persian-date.min.js'); const pDate = obj, @@ -11,7 +10,9 @@ pDate.formatPersian = true; describe('Helpers', function () { it('throw error', function () { - console.log(pDate) + /* eslint-disable no-console */ + console.log(pDate); + /* eslint-enable no-console */ expect(pDate).to.throw(Error); }); }); @@ -41,7 +42,7 @@ describe('Make Instance', function () { it('Negative year', function () { let a = new pDate([-1]).format(); - assert.ok(a, "-۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); + assert.ok(a, '-۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); }); @@ -58,8 +59,8 @@ describe('Make Instance', function () { }); it('Init from .Net', function () { - let a = new pDate("/Date(1198908717056-0700)/").utc().format(); - assert.deepEqual(a, "۱۳۸۶-۱۰-۰۸ ۰۶:۱۱:۵۷ ق ظ"); + let a = new pDate('/Date(1198908717056-0700)/').utc().format(); + assert.deepEqual(a, '۱۳۸۶-۱۰-۰۸ ۰۶:۱۱:۵۷ ق ظ'); }); @@ -165,7 +166,9 @@ describe('Leap Year', function () { while (indexYear < endYear) { let createdDate = new pDate([indexYear]); if (createdDate.isLeapYear()) { - console.log(indexYear + ' is leap year!' + createdDate.isLeapYear()) + /* eslint-disable no-console */ + console.log(indexYear + ' is leap year!' + createdDate.isLeapYear()); + /* eslint-enable no-console */ } indexYear += 1; } @@ -342,7 +345,7 @@ describe('timezone', function () { // TODO it('local', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]).local().format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('static utc method', function () { // TODO @@ -365,11 +368,11 @@ describe('timezone', function () { }); it('utc([1391, 1, 1, 1, 1, 1])', function () { let a = new pDate().utc([1391, 1, 1, 1, 1, 1]).local().format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('convert utc date to local', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]).utc().local().format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); }); @@ -394,23 +397,23 @@ describe('Clone', function () { describe('daysInMonth', function () { it('First Month of normal year', function () { - let a = new pDate().daysInMonth(1391, 1); +// let a = new pDate().daysInMonth(1391, 1); assert.ok(29); }); it('Sixth Month of normal year', function () { - let a = new pDate().daysInMonth(1394, 6); +// let a = new pDate().daysInMonth(1394, 6); assert.ok(31); }); it('Sixth Month of normal year', function () { - let a = new pDate().daysInMonth(1394, 7); +// let a = new pDate().daysInMonth(1394, 7); assert.ok(30); }); it('Last Month of leap year', function () { - let a = new pDate().daysInMonth(1394, 12); +// let a = new pDate().daysInMonth(1394, 12); assert.ok(29); }); it('Last Month of normal year', function () { - let a = new pDate().daysInMonth(1391, 12); +// let a = new pDate().daysInMonth(1391, 12); assert.ok(29); }); }); @@ -419,17 +422,17 @@ describe('English Format', function () { it('a.formatPersian = false', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); a.formatPersian = false; - assert.deepEqual(a.format(), "1391-01-01 01:01:01 AM"); + assert.deepEqual(a.format(), '1391-01-01 01:01:01 AM'); }); it('a.formatPersian = true', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); a.formatPersian = true; - assert.deepEqual(a.format(), "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a.format(), '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('a.formatPersian = true', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - a.formatPersian = "dsadas"; - assert.deepEqual(a.format(), "1391-01-01 01:01:01 AM"); + a.formatPersian = 'dsadas'; + assert.deepEqual(a.format(), '1391-01-01 01:01:01 AM'); }); }); @@ -440,98 +443,98 @@ describe('format', function () { it('format()', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format(), "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a.format(), '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); a.formatPersian = false; - assert.deepEqual(a.format(), "1391-01-01 01:01:01 AM"); + assert.deepEqual(a.format(), '1391-01-01 01:01:01 AM'); }); it('format("a")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('a'), "ق ظ"); + assert.deepEqual(a.format('a'), 'ق ظ'); a.formatPersian = false; - assert.deepEqual(a.format('a'), "AM"); + assert.deepEqual(a.format('a'), 'AM'); }); it('format("H")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('H'), "۱"); + assert.deepEqual(a.format('H'), '۱'); a.formatPersian = false; - assert.deepEqual(a.format('H'), "1"); + assert.deepEqual(a.format('H'), '1'); }); it('format("HH")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('HH'), "۰۱"); + assert.deepEqual(a.format('HH'), '۰۱'); }); it('format("h")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('h'), "۱"); + assert.deepEqual(a.format('h'), '۱'); }); it('format("hh")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('hh'), "۰۱"); + assert.deepEqual(a.format('hh'), '۰۱'); }); it('format("m")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('m'), "۰۱"); + assert.deepEqual(a.format('m'), '۰۱'); }); it('format("mm")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('mm'), "۰۱"); + assert.deepEqual(a.format('mm'), '۰۱'); }); it('format("s")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('s'), "۱"); + assert.deepEqual(a.format('s'), '۱'); }); it('format("ss")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('ss'), "۰۱"); + assert.deepEqual(a.format('ss'), '۰۱'); }); it('format("L")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('L'), "۱۳۹۱/۰۱/۰۱"); + assert.deepEqual(a.format('L'), '۱۳۹۱/۰۱/۰۱'); }); it('format("l")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(a.format('l'), "۱۳۹۱/۱/۱"); + assert.deepEqual(a.format('l'), '۱۳۹۱/۱/۱'); }); it('format("LL")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('LL'), "فروردین ۰۱ ۱۳۹۱"); + assert.deepEqual(formattedDate.format('LL'), 'فروردین ۰۱ ۱۳۹۱'); }); it('format("ll")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('ll'), "فرو ۰۱ ۱۳۹۱"); + assert.deepEqual(formattedDate.format('ll'), 'فرو ۰۱ ۱۳۹۱'); }); it('format("LLL")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('LLL'), "فروردین ۱۳۹۱ ۰۱ ۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate.format('LLL'), 'فروردین ۱۳۹۱ ۰۱ ۱:۰۱ ق ظ'); }); it('format("lll")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('lll'), "فرو ۱۳۹۱ ۰۱ ۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate.format('lll'), 'فرو ۱۳۹۱ ۰۱ ۱:۰۱ ق ظ'); }); it('format("LLLL")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('LLLL'), "سه شنبه ۱ فروردین ۱۳۹۱ ۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate.format('LLLL'), 'سه شنبه ۱ فروردین ۱۳۹۱ ۱:۰۱ ق ظ'); }); it('format("llll")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('llll'), "س ۱ فرو ۱۳۹۱ ۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate.format('llll'), 'س ۱ فرو ۱۳۹۱ ۱:۰۱ ق ظ'); }); // it('format("X")', function () { @@ -549,70 +552,70 @@ describe('format', function () { it('format("LT")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('LT'), "۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate.format('LT'), '۱:۰۱ ق ظ'); }); it('format("YY")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('YY'), "۹۱"); + assert.deepEqual(formattedDate.format('YY'), '۹۱'); }); it('format("YYYY")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('YYYY'), "۱۳۹۱"); + assert.deepEqual(formattedDate.format('YYYY'), '۱۳۹۱'); }); it('format("MMMM")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('MMMM'), "فروردین"); + assert.deepEqual(formattedDate.format('MMMM'), 'فروردین'); }); it('format("MMM")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('MMM'), "فرو"); + assert.deepEqual(formattedDate.format('MMM'), 'فرو'); }); it('format("MM")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('MM'), "۰۱"); + assert.deepEqual(formattedDate.format('MM'), '۰۱'); }); it('format("M")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('M'), "۱"); + assert.deepEqual(formattedDate.format('M'), '۱'); }); it('format("d")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('d'), "۴"); + assert.deepEqual(formattedDate.format('d'), '۴'); }); it('format("ddd")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('ddd'), "س"); + assert.deepEqual(formattedDate.format('ddd'), 'س'); }); it('format("dddd")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('dddd'), "سه شنبه"); + assert.deepEqual(formattedDate.format('dddd'), 'سه شنبه'); }); it('format("ddddd")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('ddddd'), "اورمزد"); + assert.deepEqual(formattedDate.format('ddddd'), 'اورمزد'); }); it('format("DD")', function () { let formattedDate = new pDate([1391, 1, 1, 1, 1, 1]); - assert.deepEqual(formattedDate.format('DD'), "۰۱"); + assert.deepEqual(formattedDate.format('DD'), '۰۱'); }); it('format("DDD")', function () { let formattedDate = new pDate([1391, 1, 3, 1, 1, 1]); - assert.deepEqual(formattedDate.format('DDD'), "۰۰۲"); + assert.deepEqual(formattedDate.format('DDD'), '۰۰۲'); }); it('format("DDDD")', function () { let formattedDate = new pDate([1391, 1, 3, 1, 1, 1]); - assert.deepEqual(formattedDate.format('DDDD'), "۰۰۲"); + assert.deepEqual(formattedDate.format('DDDD'), '۰۰۲'); }); it('format("w")', function () { let formattedDate = new pDate([1391, 1, 3, 1, 1, 1]); - assert.deepEqual(formattedDate.format('w'), "۱"); + assert.deepEqual(formattedDate.format('w'), '۱'); }); it('format("ww")', function () { let formattedDate = new pDate([1391, 1, 3, 1, 1, 1]); - assert.deepEqual(formattedDate.format('ww'), "۰۱"); + assert.deepEqual(formattedDate.format('ww'), '۰۱'); }); }); @@ -623,58 +626,58 @@ describe('startOf', function () { it('startOf("year")', function () { let a = new pDate(defaultArray).startOf('year').format(); let b = new pDate(defaultArray).startOf('years').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); }); it('startOf("month")', function () { let a = new pDate(defaultArray).startOf('month').format(); let b = new pDate(defaultArray).startOf('months').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); }); it('startOf("days")', function () { let a = new pDate(defaultArray).startOf('days').format(); let b = new pDate(defaultArray).startOf('day').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); }); it('sod()', function () { let a = new pDate(defaultArray).sod().format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ'); }); it('startOf("hour")', function () { let a = new pDate(defaultArray).startOf('hour').format(); let b = new pDate(defaultArray).startOf('hours').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۰:۰۰ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۰:۰۰ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۰:۰۰ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۰:۰۰ ق ظ'); }); it('startOf("minute")', function () { let a = new pDate(defaultArray).startOf('minute').format(); let b = new pDate(defaultArray).startOf('minutes').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۰ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۰ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۰ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۰ ق ظ'); }); it('startOf("second")', function () { let a = new pDate(defaultArray).startOf('second').format(); let b = new pDate(defaultArray).startOf('seconds').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('startOf("week")', function () { let formattedDate = new pDate(defaultArray).startOf('week').format(); - assert.deepEqual(formattedDate, "۱۳۹۰-۱۲-۲۶ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۰-۱۲-۲۶ ۰۰:۰۰:۰۰ ق ظ'); }); it('startOf("weeks")', function () { let formattedDate = new pDate(defaultArray).startOf('weeks').format(); - assert.deepEqual(formattedDate, "۱۳۹۰-۱۲-۲۶ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۰-۱۲-۲۶ ۰۰:۰۰:۰۰ ق ظ'); }); it('startOf()', function () { let formattedDate = new pDate(defaultArray).startOf().format(); - assert.deepEqual(formattedDate, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('startOf()', function () { let formattedDate = new pDate([1390, 12, 26]).startOf('week').format(); - assert.deepEqual(formattedDate, "۱۳۹۰-۱۲-۲۶ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۰-۱۲-۲۶ ۰۰:۰۰:۰۰ ق ظ'); }); }); @@ -683,58 +686,58 @@ describe('endOf', function () { it('endOf("year")', function () { let a = new pDate([1391, 1, 1, 1, 1, 1, 100]).endOf('year').format(); let b = new pDate([1391, 1, 1, 1, 1, 1, 100]).endOf('years').format(); - assert.deepEqual(a, "۱۳۹۱-۱۲-۳۰ ۲۳:۵۹:۵۹ ب ظ"); - assert.deepEqual(b, "۱۳۹۱-۱۲-۳۰ ۲۳:۵۹:۵۹ ب ظ"); + assert.deepEqual(a, '۱۳۹۱-۱۲-۳۰ ۲۳:۵۹:۵۹ ب ظ'); + assert.deepEqual(b, '۱۳۹۱-۱۲-۳۰ ۲۳:۵۹:۵۹ ب ظ'); }); it('endOf("month")', function () { let a = new pDate(defaultArray).endOf('month').format(); let b = new pDate(defaultArray).endOf('months').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۳۱ ۲۳:۵۹:۵۹ ب ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۳۱ ۲۳:۵۹:۵۹ ب ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۳۱ ۲۳:۵۹:۵۹ ب ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۳۱ ۲۳:۵۹:۵۹ ب ظ'); }); it('endOf("days")', function () { let a = new pDate(defaultArray).endOf('day').format(); let b = new pDate(defaultArray).endOf('days').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۲۳:۵۹:۵۹ ب ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۲۳:۵۹:۵۹ ب ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۲۳:۵۹:۵۹ ب ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۲۳:۵۹:۵۹ ب ظ'); }); it('endOf("hour")', function () { let a = new pDate(defaultArray).endOf('hour').format(); let b = new pDate(defaultArray).endOf('hours').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۵۹:۵۹ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۱:۵۹:۵۹ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۵۹:۵۹ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۱:۵۹:۵۹ ق ظ'); }); it('endOf("minute")', function () { let a = new pDate(defaultArray).endOf('minute').format(); let b = new pDate(defaultArray).endOf('minutes').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۵۹ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۵۹ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۵۹ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۵۹ ق ظ'); }); it('endOf("second")', function () { let a = new pDate(defaultArray).endOf('second').format(); let b = new pDate(defaultArray).endOf('seconds').format(); - assert.deepEqual(a, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); - assert.deepEqual(b, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(a, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); + assert.deepEqual(b, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('endOf("week")', function () { let formattedDate = new pDate(defaultArray).endOf('week').format(); - assert.deepEqual(formattedDate, "۱۳۹۱-۰۱-۰۳ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۱-۰۱-۰۳ ۰۰:۰۰:۰۰ ق ظ'); }); it('endOf("weeks")', function () { let formattedDate = new pDate(defaultArray).endOf('weeks').format(); - assert.deepEqual(formattedDate, "۱۳۹۱-۰۱-۰۳ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۱-۰۱-۰۳ ۰۰:۰۰:۰۰ ق ظ'); }); it('endOf()', function () { let formattedDate = new pDate(defaultArray).endOf().format(); - assert.deepEqual(formattedDate, "۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۱-۰۱-۰۱ ۰۱:۰۱:۰۱ ق ظ'); }); it('endOf("week")', function () { let formattedDate = new pDate([1391, 1, 3, 1, 1, 1]).endOf('week').format(); - assert.deepEqual(formattedDate, "۱۳۹۱-۰۱-۱۰ ۰۰:۰۰:۰۰ ق ظ"); + assert.deepEqual(formattedDate, '۱۳۹۱-۰۱-۱۰ ۰۰:۰۰:۰۰ ق ظ'); }); it('eod()', function () { let formattedDate = new pDate(defaultArray).eod().format(); - assert.deepEqual(formattedDate, "۱۳۹۱-۰۱-۰۱ ۲۳:۵۹:۵۹ ب ظ"); + assert.deepEqual(formattedDate, '۱۳۹۱-۰۱-۰۱ ۲۳:۵۹:۵۹ ب ظ'); }); }); @@ -761,26 +764,26 @@ describe('Diff', function () { describe('duration', function () { it('isDuration', function () { - let a = new pDate().duration(90, "milliseconds"); + let a = new pDate().duration(90, 'milliseconds'); assert.deepEqual(a._data.milliseconds, 90); }); it('isDuration', function () { - let a = new pDate().duration(-90, "milliseconds"); + let a = new pDate().duration(-90, 'milliseconds'); assert.deepEqual(a._data.milliseconds, -90); }); it('isDuration', function () { - let a = new pDate().isDuration(new Duration(90, "milliseconds")); + let a = new pDate().isDuration(new Duration(90, 'milliseconds')); assert.deepEqual(a, true); }); it('milliseconds', function () { - let a = new Duration(90, "milliseconds").valueOf(); + let a = new Duration(90, 'milliseconds').valueOf(); assert.deepEqual(a, 90); - let b = new Duration(1, "day").valueOf(); + let b = new Duration(1, 'day').valueOf(); assert.deepEqual(b, 86400000); }); it('milliseconds', function () { - let a = new Duration(90, "milliseconds"); + let a = new Duration(90, 'milliseconds'); assert.deepEqual(a._data.months, 0); assert.deepEqual(a._data.years, 0); assert.deepEqual(a._data.days, 0); @@ -790,7 +793,7 @@ describe('duration', function () { assert.deepEqual(a._data.milliseconds, 90); }); it('second', function () { - let a = new Duration(90, "second"); + let a = new Duration(90, 'second'); assert.deepEqual(a._data.months, 0); assert.deepEqual(a._data.years, 0); assert.deepEqual(a._data.days, 0); @@ -799,7 +802,7 @@ describe('duration', function () { assert.deepEqual(a._data.seconds, 30); }); it('minutes', function () { - let a = new Duration(90, "minute"); + let a = new Duration(90, 'minute'); assert.deepEqual(a._data.months, 0); assert.deepEqual(a._data.years, 0); assert.deepEqual(a._data.days, 0); @@ -809,7 +812,7 @@ describe('duration', function () { assert.deepEqual(a._data.milliseconds, 0); }); it('hour', function () { - let a = new Duration(30, "hour"); + let a = new Duration(30, 'hour'); assert.deepEqual(a._data.months, 0); assert.deepEqual(a._data.years, 0); assert.deepEqual(a._data.days, 1); @@ -819,7 +822,7 @@ describe('duration', function () { assert.deepEqual(a._data.milliseconds, 0); }); it('day', function () { - let a = new Duration(90, "day"); + let a = new Duration(90, 'day'); assert.deepEqual(a._data.months, 3); assert.deepEqual(a._data.years, 0); assert.deepEqual(a._data.days, 0); @@ -828,7 +831,7 @@ describe('duration', function () { assert.deepEqual(a._data.seconds, 0); }); it('months', function () { - let a = new Duration(90, "month"); + let a = new Duration(90, 'month'); assert.deepEqual(a._data.months, 6); assert.deepEqual(a._data.years, 7); assert.deepEqual(a._data.days, 0); @@ -837,7 +840,7 @@ describe('duration', function () { assert.deepEqual(a._data.seconds, 0); }); it('years', function () { - let a = new Duration(90, "year"); + let a = new Duration(90, 'year'); assert.deepEqual(a._data.months, 0); assert.deepEqual(a._data.years, 90); assert.deepEqual(a._data.days, 0); @@ -891,7 +894,7 @@ describe('Subtract', function () { assert.deepEqual(a, [1390, 1, 1, 1, 1, 1, 0]); }); it('Month', function () { - let a = new pDate([1391, 2, 1, 1, 1, 1]).subtract('month', 2).toArray(); + let a = new pDate([1391, 2, 1, 1, 1, 1]).subtract('month', 1).toArray(); assert.deepEqual(a, [1391, 1, 1, 1, 1, 1, 0]); }); it('Days', function () {