From de001c7eae22f7b680de9a3c0ed7a94924275a9d Mon Sep 17 00:00:00 2001 From: Amin Mousavi Date: Sat, 8 Sep 2018 01:26:54 +0430 Subject: [PATCH 1/2] - Fixed bug where diff method did not return a negative value when the date was less than other. - Added some tests for diff method. Tests for when date is less than, greater than and equals to the other one. --- .gitignore | 1 + dist/persian-date.js | 211 +++++++++++++++++++-------------------- dist/persian-date.min.js | 2 +- src/pDate.js | 3 - test/test.js | 26 ++++- 5 files changed, 130 insertions(+), 113 deletions(-) diff --git a/.gitignore b/.gitignore index 630a118..e6286e1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ node_modules .idea .nyc_output +coverage \ No newline at end of file diff --git a/dist/persian-date.js b/dist/persian-date.js index da2a211..84b5c04 100644 --- a/dist/persian-date.js +++ b/dist/persian-date.js @@ -25,9 +25,9 @@ return /******/ (function(modules) { // webpackBootstrap /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) +/******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; -/******/ +/******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, @@ -923,9 +923,6 @@ var PersianDateClass = function () { val === 'weeks' || val === 'week' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7 diff; } - if (output < 0) { - output = output * -1; - } return asFloat ? output : Math.round(output); } @@ -1985,7 +1982,7 @@ var Algorithms = function () { astronomical calendar in which a given Julian day falls. Returns an array of two elements: - [0] Persian year + [0] Persian year [1] Julian day number containing equinox for this year. * @param {*} jd @@ -2532,11 +2529,11 @@ var ASTRO = function () { /* EQUINOX -- Determine the Julian Ephemeris Day of an equinox or solstice. The "which" argument selects the item to be computed: - 0 March equinox + 0 March equinox 1 June solstice 2 September equinox 3 December solstice - */ + */ /** * @desc Periodic terms to obtain true time * @type Array @@ -2697,8 +2694,8 @@ var ASTRO = function () { /* Calculate angles. The correspondence between the elements of our array and the terms cited in Meeus are: - ta[0] = D ta[0] = M ta[2] = M' ta[3] = F ta[4] = \Omega - */ + ta[0] = D ta[0] = M ta[2] = M' ta[3] = F ta[4] = \Omega + */ ta[0] = this.dtr(297.850363 + 445267.11148 * t - 0.0019142 * t2 + t3 / 189474.0); ta[1] = this.dtr(357.52772 + 35999.05034 * t - 0.0001603 * t2 - t3 / 300000.0); @@ -3101,114 +3098,114 @@ module.exports = PersianDateClass; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Container = function Container() { - _classCallCheck(this, Container); + _classCallCheck(this, Container); - this.gDate = null; - /** - * - * @type {number} - */ - this.modifiedjulianday = 0; + this.gDate = null; + /** + * + * @type {number} + */ + this.modifiedjulianday = 0; - /** - * - * @type {number} - */ - this.julianday = 0; + /** + * + * @type {number} + */ + this.julianday = 0; - /** - * - * @type {{day: number}} - */ - this.gregserial = { - day: 0 - }; + /** + * + * @type {{day: number}} + */ + this.gregserial = { + day: 0 + }; - this.zone = 0; + this.zone = 0; - /** - * - * @type {{year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, weekday: number, unix: number, leap: number}} - */ - this.gregorian = { - year: 0, - month: 0, - day: 0, - hour: 0, - minute: 0, - second: 0, - millisecond: 0, - weekday: 0, - unix: 0, - leap: 0 - }; + /** + * + * @type {{year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, weekday: number, unix: number, leap: number}} + */ + this.gregorian = { + year: 0, + month: 0, + day: 0, + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + weekday: 0, + unix: 0, + leap: 0 + }; - /** - * - * @type {{year: number, month: number, day: number, leap: number, weekday: number}} - */ - this.juliancalendar = { - year: 0, - month: 0, - day: 0, - leap: 0, - weekday: 0 - }; + /** + * + * @type {{year: number, month: number, day: number, leap: number, weekday: number}} + */ + this.juliancalendar = { + year: 0, + month: 0, + day: 0, + leap: 0, + weekday: 0 + }; - /** - * - * @type {{year: number, month: number, day: number, leap: number, weekday: number}} - */ - this.islamic = { - year: 0, - month: 0, - day: 0, - leap: 0, - weekday: 0 - }; + /** + * + * @type {{year: number, month: number, day: number, leap: number, weekday: number}} + */ + this.islamic = { + year: 0, + month: 0, + day: 0, + leap: 0, + weekday: 0 + }; - /** - * - * @type {{year: number, month: number, day: number, leap: number, weekday: number}} - */ - this.persianAlgo = this.persian = { - year: 0, - month: 0, - day: 0, - leap: 0, - weekday: 0 - }; + /** + * + * @type {{year: number, month: number, day: number, leap: number, weekday: number}} + */ + this.persianAlgo = this.persian = { + year: 0, + month: 0, + day: 0, + leap: 0, + weekday: 0 + }; - /** - * - * @type {{year: number, month: number, day: number, leap: number, weekday: number}} - */ - this.persianAstro = { - year: 0, - month: 0, - day: 0, - leap: 0, - weekday: 0 - }; + /** + * + * @type {{year: number, month: number, day: number, leap: number, weekday: number}} + */ + this.persianAstro = { + year: 0, + month: 0, + day: 0, + leap: 0, + weekday: 0 + }; - /** - * - * @type {{year: number, week: number, day: number}} - */ - this.isoweek = { - year: 0, - week: 0, - day: 0 - }; + /** + * + * @type {{year: number, week: number, day: number}} + */ + this.isoweek = { + year: 0, + week: 0, + day: 0 + }; - /** - * - * @type {{year: number, day: number}} - */ - this.isoday = { - year: 0, - day: 0 - }; + /** + * + * @type {{year: number, day: number}} + */ + this.isoday = { + year: 0, + day: 0 + }; }; module.exports = Container; diff --git a/dist/persian-date.min.js b/dist/persian-date.min.js index c651dc6..a97048c 100644 --- a/dist/persian-date.min.js +++ b/dist/persian-date.min.js @@ -7,4 +7,4 @@ * * */ -!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(i){if(a[i])return a[i].exports;var r=a[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var a={};return t.m=e,t.c=a,t.i=function(e){return e},t.d=function(e,a,i){t.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:i})},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=8)}([function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a1&&void 0!==arguments[1]&&arguments[1];return e.toString().replace(/\d+/g,function(e){var a=[],i=[],r=void 0,n=void 0;for(r=0;r-1?e="year":n.month.indexOf(e)>-1?e="month":n.day.indexOf(e)>-1?e="day":n.hour.indexOf(e)>-1?e="hour":n.minute.indexOf(e)>-1?e="minute":n.second.indexOf(e)>-1?e="second":n.millisecond.indexOf(e)>-1&&(e="millisecond"),{unit:e,value:t}}},{key:"absRound",value:function(e){return e<0?Math.ceil(e):Math.floor(e)}},{key:"absFloor",value:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)}}]),e}();e.exports=s},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a1||6==e&&t<31||e<6&&e>=2}},{key:"isLeapYear",value:function(e){return void 0===e&&(e=this.year()),"persian"==this.calendarType&&"algorithmic"===this.leapYearMode?this.algorithms.leap_persian(e):"persian"==this.calendarType&&"astronomical"===this.leapYearMode?this.algorithms.leap_persiana(e):"gregorian"==this.calendarType?this.algorithms.leap_gregorian(e):void 0}},{key:"daysInMonth",value:function(e,t){var a=e||this.year(),i=t||this.month();return"persian"===this.calendarType?i<1||i>12?0:i<7?31:i<12?30:this.isLeapYear(a)?30:29:"gregorian"===this.calendarType?new Date(a,i,0).getDate():void 0}},{key:"toDate",value:function(){return this.ON.gDate}},{key:"toArray",value:function(){return[this.year(),this.month(),this.date(),this.hour(),this.minute(),this.second(),this.millisecond()]}},{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 n?r.hour>=12?"ب ظ":"ق ظ":r.hour>=12?"PM":"AM";case"H":return s(r.hour);case"HH":return s(d(r.hour,2));case"h":return s(r.hour%12);case"hh":return s(d(r.hour%12,2));case"m":case"mm":return s(d(r.minute,2));case"s":return s(r.second);case"ss":return s(d(r.second,2));case"D":return s(d(r.date));case"DD":return s(d(r.date,2));case"DDD":var t=a.startOf("year");return s(d(a.diff(t,"days"),3));case"DDDD":var i=a.startOf("year");return s(d(a.diff(i,"days"),3));case"d":return s(a.calendar().weekday);case"ddd":return a._weekNameShort(a.calendar().weekday);case"dddd":return a._weekName(a.calendar().weekday);case"ddddd":return a._dayName(a.calendar().day);case"dddddd":return a._weekNameMin(a.calendar().weekday);case"w":var o=a.startOf("year"),h=parseInt(a.diff(o,"days")/7)+1;return s(h);case"ww":var u=a.startOf("year"),l=d(parseInt(a.diff(u,"days")/7)+1,2);return s(l);case"M":return s(r.month);case"MM":return s(d(r.month,2));case"MMM":return a._monthNameShort(r.month);case"MMMM":return a._monthName(r.month);case"YY":var c=r.year.toString().split("");return s(c[2]+c[3]);case"YYYY":return s(r.year);case"Z":var y="+",f=Math.round(r.timezone/60),v=r.timezone%60;v<0&&(v*=-1),f<0&&(y="-",f*=-1);var m=y+d(f,2)+":"+d(v,2);return s(m);case"ZZ":var p="+",g=Math.round(r.timezone/60),_=r.timezone%60;_<0&&(_*=-1),g<0&&(p="-",g*=-1);var M=p+d(g,2)+""+d(_,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,i=/([[^[]*])|(\\)?(Mo|MM?M?M?|Do|DD?D?D?|dddddd?|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,r={year:a.year(),month:a.month(),hour:a.hours(),minute:a.minutes(),second:a.seconds(),date:a.date(),timezone:a.zone(),unix:a.unix()},n=a.formatNumber(),s=function(e){return n?u(e):e};return e?e.replace(i,t):"YYYY-MM-DD HH:mm:ss a".replace(i,t)}},{key:"add",value:function(e,t){var a=new h(e,t)._data,i=l(e,t).unit;if(t=l(e,t).value,"year"===i||"month"===i){if(a.years>0){var r=this.year()+a.years;this.year(r)}if(a.months>0){var n=this.date(),s=this.month()+a.months,o=this.daysInMonth(this.year(),s);n>=o&&(n=o),this.date(n),this.month(s)}}if("day"===i){var u=this.hour(),d=this.valueOf()+24*t*60*60*1e3;return this.unix(d/1e3).hour(u)}if("hour"===i){var c=this.valueOf()+60*t*60*1e3;return this.unix(c/1e3)}if("minute"===i){var y=this.valueOf()+60*t*1e3;return this.unix(y/1e3)}if("second"===i){var f=this.valueOf()+1e3*t;return this.unix(f/1e3)}if("millisecond"===i){var v=this.valueOf()+t;return this.unix(v/1e3)}return this._getSyncedClass(this.valueOf())}},{key:"subtract",value:function(e,t){var a=new h(e,t)._data,i=l(e,t).unit;if(t=l(e,t).value,"year"===i||"month"===i){if(a.years>0){var r=this.year()-a.years;this.year(r)}if(a.months>0){var n=this.date(),s=this.month()-a.months;this.month(s);var o=this.daysInMonth(this.year(),this.month());n>o&&(n=o),this.date(n)}}if("day"===i){var u=this.hour(),d=this.valueOf()-24*t*60*60*1e3;return this.unix(d/1e3).hour(u)}if("hour"===i){var c=this.valueOf()-60*t*60*1e3;return this.unix(c/1e3)}if("minute"===i){var y=this.valueOf()-60*t*1e3;return this.unix(y/1e3)}if("second"===i){var f=this.valueOf()-1e3*t;return this.unix(f/1e3)}if("millisecond"===i){var v=this.valueOf()-t;return this.unix(v/1e3)}return this._getSyncedClass(this.valueOf())}},{key:"isSameDay",value:function(e){return this&&e&&this.date()==e.date()&&this.year()==e.year()&&this.month()==e.month()}},{key:"isSameMonth",value:function(e){return this&&e&&this.year()==this.year()&&this.month()==e.month()}}],[{key:"rangeName",value:function(){var e=t,a=e.calendarType;return"fa"===e.localType?"persian"===a?c.persian:c.gregorian:"persian"===a?y.persian:y.gregorian}},{key:"toLeapYearMode",value:function(e){var a=t;return a.leapYearMode=e,a}},{key:"toCalendar",value:function(e){var a=t;return a.calendarType=e,a}},{key:"toLocale",value:function(e){var a=t;return a.localType=e,"fa"!==a.localType?a.formatPersian=!1:a.formatPersian="_default",a}},{key:"isPersianDate",value:function(e){return e instanceof t}},{key:"duration",value:function(e,t){return new h(e,t)}},{key:"isDuration",value:function(e){return e instanceof h}},{key:"unix",value:function(e){return e?new t(1e3*e):(new t).unix()}},{key:"getFirstWeekDayOfMonth",value:function(e,a){return new t([e,a,1]).day()}},{key:"utc",value:function(e){return e?new t(e).utc():(new t).utc()}},{key:"isSameDay",value:function(e,t){return e&&t&&e.date()==t.date()&&e.year()==t.year()&&e.month()==t.month()}},{key:"isSameMonth",value:function(e,t){return e&&t&&e.year()==t.year()&&e.month()==t.month()}}]),t}();e.exports=f},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;ae;)t--,a=this.tehran_equinox_jd(t);for(i=a-1;!(a<=e&&e365}},{key:"leap_persian",value:function(e){return 682*((e-(e>0?474:473))%2820+474+38)%2816<682}},{key:"persian_to_jd",value:function(e,t,a){var i=void 0,r=void 0;return i=e-(e>=0?474:473),r=474+this.ASTRO.mod(i,2820),a+(t<=7?31*(t-1):30*(t-1)+6)+Math.floor((682*r-110)/2816)+365*(r-1)+1029983*Math.floor(i/2820)+(this.PERSIAN_EPOCH-1)}},{key:"jd_to_persian",value:function(e){var t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0,d=void 0;return e=Math.floor(e)+.5,r=e-this.persian_to_jd(475,1,1),n=Math.floor(r/1029983),s=this.ASTRO.mod(r,1029983),1029982===s?o=2820:(h=Math.floor(s/366),u=this.ASTRO.mod(s,366),o=Math.floor((2134*h+2816*u+2815)/1028522)+h+1),t=o+2820*n+474,t<=0&&t--,d=e-this.persian_to_jd(t,1,1)+1,a=d<=186?Math.ceil(d/31):Math.ceil((d-6)/30),i=e-this.persian_to_jd(t,a,1)+1,[t,a,i]}},{key:"gWeekDayToPersian",value:function(e){return e+2===8?1:e+2===7?7:e+2}},{key:"updateFromGregorian",value:function(){var e=void 0,t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0;t=this.ON.gregorian.year,a=this.ON.gregorian.month,i=this.ON.gregorian.day,r=0,n=0,s=0,this.ON.gDate=new Date(t,a,i,this.ON.gregorian.hour,this.ON.gregorian.minute,this.ON.gregorian.second,this.ON.gregorian.millisecond),this.parent._utcMode===!1&&(this.ON.zone=this.ON.gDate.getTimezoneOffset()),this.ON.gregorian.year=this.ON.gDate.getFullYear(),this.ON.gregorian.month=this.ON.gDate.getMonth(),this.ON.gregorian.day=this.ON.gDate.getDate(),e=this.gregorian_to_jd(t,a+1,i)+Math.floor(s+60*(n+60*r)+.5)/86400,this.ON.julianday=e,this.ON.modifiedjulianday=e-this.JMJD,o=this.ASTRO.jwday(e),this.ON.gregorian.weekday=o+1,this.ON.gregorian.leap=this.NormLeap[this.leap_gregorian(t)?1:0],o=this.ASTRO.jwday(e),"persian"==this.parent.calendarType&&"algorithmic"==this.parent.leapYearMode&&(u=this.jd_to_persian(e),this.ON.persian.year=u[0],this.ON.persian.month=u[1]-1,this.ON.persian.day=u[2],this.ON.persian.weekday=this.gWeekDayToPersian(o),this.ON.persian.leap=this.NormLeap[this.leap_persian(u[0])?1:0]),"persian"==this.parent.calendarType&&"astronomical"==this.parent.leapYearMode&&(u=this.jd_to_persiana(e),this.ON.persianAstro.year=u[0],this.ON.persianAstro.month=u[1]-1,this.ON.persianAstro.day=u[2],this.ON.persianAstro.weekday=this.gWeekDayToPersian(o),this.ON.persianAstro.leap=this.NormLeap[this.leap_persiana(u[0])?1:0]),null!==this.ON.gregserial.day&&(this.ON.gregserial.day=e-this.J0000),h=864e5*(e-this.J1970),this.ON.unixtime=Math.round(h/1e3)}},{key:"calcGregorian",value:function(e){(e[0]||0===e[0])&&(this.ON.gregorian.year=e[0]),(e[1]||0===e[1])&&(this.ON.gregorian.month=e[1]),(e[2]||0===e[2])&&(this.ON.gregorian.day=e[2]),(e[3]||0===e[3])&&(this.ON.gregorian.hour=e[3]),(e[4]||0===e[4])&&(this.ON.gregorian.minute=e[4]),(e[5]||0===e[5])&&(this.ON.gregorian.second=e[5]),(e[6]||0===e[6])&&(this.ON.gregorian.millisecond=e[6]),this.updateFromGregorian()}},{key:"calcJulian",value:function(){var e=void 0,t=void 0;e=this.ON.julianday,t=this.jd_to_gregorian(e),this.ON.gregorian.year=t[0],this.ON.gregorian.month=t[1]-1,this.ON.gregorian.day=t[2],this.updateFromGregorian()}},{key:"setJulian",value:function(e){this.ON.julianday=e,this.calcJulian()}},{key:"calcPersian",value:function(e){e[0]&&(this.ON.persian.year=e[0]),e[1]&&(this.ON.persian.month=e[1]),e[2]&&(this.ON.persian.day=e[2]),e[3]&&(this.ON.gregorian.hour=e[3]),e[4]&&(this.ON.gregorian.minute=e[4]),e[5]&&(this.ON.gregorian.second=e[5]),e[6]&&(this.ON.gregorian.millisecond=e[6]),this.setJulian(this.persian_to_jd(this.ON.persian.year,this.ON.persian.month,this.ON.persian.day))}},{key:"calcPersiana",value:function(e){e[0]&&(this.ON.persianAstro.year=e[0]),e[1]&&(this.ON.persianAstro.month=e[1]),e[2]&&(this.ON.persianAstro.day=e[2]),e[3]&&(this.ON.gregorian.hour=e[3]),e[4]&&(this.ON.gregorian.minute=e[4]),e[5]&&(this.ON.gregorian.second=e[5]),e[6]&&(this.ON.gregorian.millisecond=e[6]),this.setJulian(this.persiana_to_jd(this.ON.persianAstro.year,this.ON.persianAstro.month,this.ON.persianAstro.day+.5))}}]),e}();e.exports=o},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a=1620&&e<=2e3?(i=Math.floor((e-1620)/2),a=(e-1620)/2-i,t=this.deltaTtab[i]+(this.deltaTtab[i+1]-this.deltaTtab[i])*a):(r=(e-2e3)/100,e<948?t=2177+497*r+44.1*r*r:(t=102+102*r+25.3*r*r,e>2e3&&e<2100&&(t+=.37*(e-2100)))),t}},{key:"equinox",value:function(e,t){var a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0,d=void 0;for(e<1e3?(s=this.JDE0tab1000,d=e/1e3):(s=this.JDE0tab2000,d=(e-2e3)/1e3),n=s[t][0]+s[t][1]*d+s[t][2]*d*d+s[t][3]*d*d*d+s[t][4]*d*d*d*d,h=(n-2451545)/36525,u=35999.373*h-2.47,a=1+.0334*this.dcos(u)+7e-4*this.dcos(2*u),o=0,i=r=0;i<24;i++)o+=this.EquinoxpTerms[r]*this.dcos(this.EquinoxpTerms[r+1]+this.EquinoxpTerms[r+2]*h),r+=3;return n+1e-5*o/a}},{key:"sunpos",value:function(e){var t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0,d=void 0,l=void 0,c=void 0,y=void 0,f=void 0,v=void 0,m=void 0,p=void 0;return t=(e-this.J2000)/this.JulianCentury,a=t*t,i=280.46646+36000.76983*t+3032e-7*a,i=this.fixangle(i),r=357.52911+35999.05029*t+-1537e-7*a,r=this.fixangle(r),n=.016708634+-42037e-9*t+-1.267e-7*a,s=(1.914602+-.004817*t+-14e-6*a)*this.dsin(r)+(.019993-101e-6*t)*this.dsin(2*r)+289e-6*this.dsin(3*r),o=i+s,h=r+s,u=1.000001018*(1-n*n)/(1+n*this.dcos(h)),d=125.04-1934.136*t,l=o+-.00569+-.00478*this.dsin(d),y=this.obliqeq(e),c=y+.00256*this.dcos(d),f=this.rtd(Math.atan2(this.dcos(y)*this.dsin(o),this.dcos(o))),f=this.fixangle(f),v=this.rtd(Math.asin(this.dsin(y)*this.dsin(o))),m=this.rtd(Math.atan2(this.dcos(c)*this.dsin(l),this.dcos(l))),m=this.fixangle(m),p=this.rtd(Math.asin(this.dsin(c)*this.dsin(l))),[i,r,n,s,o,h,u,l,f,v,m,p]}},{key:"equationOfTime",value:function(e){var t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0;return s=(e-this.J2000)/this.JulianMillennium,n=280.4664567+360007.6982779*s+.03032028*s*s+s*s*s/49931+-(s*s*s*s)/15300+-(s*s*s*s*s)/2e6,n=this.fixangle(n),t=this.sunpos(e)[10],a=this.nutation(e)[0],r=this.obliqeq(e)+this.nutation(e)[1],i=n+-.0057183+-t+a*this.dcos(r),i-=20*Math.floor(i/20),i/=1440}}]),e}();e.exports=n},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"]}}},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a1&&void 0!==arguments[1]&&arguments[1];return e.toString().replace(/\d+/g,function(e){var a=[],i=[],r=void 0,n=void 0;for(r=0;r-1?e="year":n.month.indexOf(e)>-1?e="month":n.day.indexOf(e)>-1?e="day":n.hour.indexOf(e)>-1?e="hour":n.minute.indexOf(e)>-1?e="minute":n.second.indexOf(e)>-1?e="second":n.millisecond.indexOf(e)>-1&&(e="millisecond"),{unit:e,value:t}}},{key:"absRound",value:function(e){return e<0?Math.ceil(e):Math.floor(e)}},{key:"absFloor",value:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)}}]),e}();e.exports=s},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a1||6==e&&t<31||e<6&&e>=2}},{key:"isLeapYear",value:function(e){return void 0===e&&(e=this.year()),"persian"==this.calendarType&&"algorithmic"===this.leapYearMode?this.algorithms.leap_persian(e):"persian"==this.calendarType&&"astronomical"===this.leapYearMode?this.algorithms.leap_persiana(e):"gregorian"==this.calendarType?this.algorithms.leap_gregorian(e):void 0}},{key:"daysInMonth",value:function(e,t){var a=e||this.year(),i=t||this.month();return"persian"===this.calendarType?i<1||i>12?0:i<7?31:i<12?30:this.isLeapYear(a)?30:29:"gregorian"===this.calendarType?new Date(a,i,0).getDate():void 0}},{key:"toDate",value:function(){return this.ON.gDate}},{key:"toArray",value:function(){return[this.year(),this.month(),this.date(),this.hour(),this.minute(),this.second(),this.millisecond()]}},{key:"formatNumber",value:function(){var t=void 0,a=this;return"_default"===this.formatPersian?t=void 0!==e&&void 0!==e.exports?!1!==a.formatPersian:!1!==window.formatPersian:!0===this.formatPersian?t=!0:!1===this.formatPersian?t=!1:Error('Invalid Config "formatPersian" !!'),t}},{key:"format",value:function(e){function t(e){switch(e){case"a":return n?r.hour>=12?"ب ظ":"ق ظ":r.hour>=12?"PM":"AM";case"H":return s(r.hour);case"HH":return s(d(r.hour,2));case"h":return s(r.hour%12);case"hh":return s(d(r.hour%12,2));case"m":case"mm":return s(d(r.minute,2));case"s":return s(r.second);case"ss":return s(d(r.second,2));case"D":return s(d(r.date));case"DD":return s(d(r.date,2));case"DDD":var t=a.startOf("year");return s(d(a.diff(t,"days"),3));case"DDDD":var i=a.startOf("year");return s(d(a.diff(i,"days"),3));case"d":return s(a.calendar().weekday);case"ddd":return a._weekNameShort(a.calendar().weekday);case"dddd":return a._weekName(a.calendar().weekday);case"ddddd":return a._dayName(a.calendar().day);case"dddddd":return a._weekNameMin(a.calendar().weekday);case"w":var o=a.startOf("year"),h=parseInt(a.diff(o,"days")/7)+1;return s(h);case"ww":var u=a.startOf("year"),l=d(parseInt(a.diff(u,"days")/7)+1,2);return s(l);case"M":return s(r.month);case"MM":return s(d(r.month,2));case"MMM":return a._monthNameShort(r.month);case"MMMM":return a._monthName(r.month);case"YY":var c=r.year.toString().split("");return s(c[2]+c[3]);case"YYYY":return s(r.year);case"Z":var y="+",f=Math.round(r.timezone/60),v=r.timezone%60;v<0&&(v*=-1),f<0&&(y="-",f*=-1);var m=y+d(f,2)+":"+d(v,2);return s(m);case"ZZ":var p="+",g=Math.round(r.timezone/60),_=r.timezone%60;_<0&&(_*=-1),g<0&&(p="-",g*=-1);var M=p+d(g,2)+""+d(_,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,i=/([[^[]*])|(\\)?(Mo|MM?M?M?|Do|DD?D?D?|dddddd?|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,r={year:a.year(),month:a.month(),hour:a.hours(),minute:a.minutes(),second:a.seconds(),date:a.date(),timezone:a.zone(),unix:a.unix()},n=a.formatNumber(),s=function(e){return n?u(e):e};return e?e.replace(i,t):"YYYY-MM-DD HH:mm:ss a".replace(i,t)}},{key:"add",value:function(e,t){var a=new h(e,t)._data,i=l(e,t).unit;if(t=l(e,t).value,"year"===i||"month"===i){if(a.years>0){var r=this.year()+a.years;this.year(r)}if(a.months>0){var n=this.date(),s=this.month()+a.months,o=this.daysInMonth(this.year(),s);n>=o&&(n=o),this.date(n),this.month(s)}}if("day"===i){var u=this.hour(),d=this.valueOf()+24*t*60*60*1e3;return this.unix(d/1e3).hour(u)}if("hour"===i){var c=this.valueOf()+60*t*60*1e3;return this.unix(c/1e3)}if("minute"===i){var y=this.valueOf()+60*t*1e3;return this.unix(y/1e3)}if("second"===i){var f=this.valueOf()+1e3*t;return this.unix(f/1e3)}if("millisecond"===i){var v=this.valueOf()+t;return this.unix(v/1e3)}return this._getSyncedClass(this.valueOf())}},{key:"subtract",value:function(e,t){var a=new h(e,t)._data,i=l(e,t).unit;if(t=l(e,t).value,"year"===i||"month"===i){if(a.years>0){var r=this.year()-a.years;this.year(r)}if(a.months>0){var n=this.date(),s=this.month()-a.months;this.month(s);var o=this.daysInMonth(this.year(),this.month());n>o&&(n=o),this.date(n)}}if("day"===i){var u=this.hour(),d=this.valueOf()-24*t*60*60*1e3;return this.unix(d/1e3).hour(u)}if("hour"===i){var c=this.valueOf()-60*t*60*1e3;return this.unix(c/1e3)}if("minute"===i){var y=this.valueOf()-60*t*1e3;return this.unix(y/1e3)}if("second"===i){var f=this.valueOf()-1e3*t;return this.unix(f/1e3)}if("millisecond"===i){var v=this.valueOf()-t;return this.unix(v/1e3)}return this._getSyncedClass(this.valueOf())}},{key:"isSameDay",value:function(e){return this&&e&&this.date()==e.date()&&this.year()==e.year()&&this.month()==e.month()}},{key:"isSameMonth",value:function(e){return this&&e&&this.year()==this.year()&&this.month()==e.month()}}],[{key:"rangeName",value:function(){var e=t,a=e.calendarType;return"fa"===e.localType?"persian"===a?c.persian:c.gregorian:"persian"===a?y.persian:y.gregorian}},{key:"toLeapYearMode",value:function(e){var a=t;return a.leapYearMode=e,a}},{key:"toCalendar",value:function(e){var a=t;return a.calendarType=e,a}},{key:"toLocale",value:function(e){var a=t;return a.localType=e,"fa"!==a.localType?a.formatPersian=!1:a.formatPersian="_default",a}},{key:"isPersianDate",value:function(e){return e instanceof t}},{key:"duration",value:function(e,t){return new h(e,t)}},{key:"isDuration",value:function(e){return e instanceof h}},{key:"unix",value:function(e){return e?new t(1e3*e):(new t).unix()}},{key:"getFirstWeekDayOfMonth",value:function(e,a){return new t([e,a,1]).day()}},{key:"utc",value:function(e){return e?new t(e).utc():(new t).utc()}},{key:"isSameDay",value:function(e,t){return e&&t&&e.date()==t.date()&&e.year()==t.year()&&e.month()==t.month()}},{key:"isSameMonth",value:function(e,t){return e&&t&&e.year()==t.year()&&e.month()==t.month()}}]),t}();e.exports=f},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;ae;)t--,a=this.tehran_equinox_jd(t);for(i=a-1;!(a<=e&&e365}},{key:"leap_persian",value:function(e){return 682*((e-(e>0?474:473))%2820+474+38)%2816<682}},{key:"persian_to_jd",value:function(e,t,a){var i=void 0,r=void 0;return i=e-(e>=0?474:473),r=474+this.ASTRO.mod(i,2820),a+(t<=7?31*(t-1):30*(t-1)+6)+Math.floor((682*r-110)/2816)+365*(r-1)+1029983*Math.floor(i/2820)+(this.PERSIAN_EPOCH-1)}},{key:"jd_to_persian",value:function(e){var t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0,d=void 0;return e=Math.floor(e)+.5,r=e-this.persian_to_jd(475,1,1),n=Math.floor(r/1029983),s=this.ASTRO.mod(r,1029983),1029982===s?o=2820:(h=Math.floor(s/366),u=this.ASTRO.mod(s,366),o=Math.floor((2134*h+2816*u+2815)/1028522)+h+1),t=o+2820*n+474,t<=0&&t--,d=e-this.persian_to_jd(t,1,1)+1,a=d<=186?Math.ceil(d/31):Math.ceil((d-6)/30),i=e-this.persian_to_jd(t,a,1)+1,[t,a,i]}},{key:"gWeekDayToPersian",value:function(e){return e+2===8?1:e+2===7?7:e+2}},{key:"updateFromGregorian",value:function(){var e=void 0,t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0;t=this.ON.gregorian.year,a=this.ON.gregorian.month,i=this.ON.gregorian.day,r=0,n=0,s=0,this.ON.gDate=new Date(t,a,i,this.ON.gregorian.hour,this.ON.gregorian.minute,this.ON.gregorian.second,this.ON.gregorian.millisecond),!1===this.parent._utcMode&&(this.ON.zone=this.ON.gDate.getTimezoneOffset()),this.ON.gregorian.year=this.ON.gDate.getFullYear(),this.ON.gregorian.month=this.ON.gDate.getMonth(),this.ON.gregorian.day=this.ON.gDate.getDate(),e=this.gregorian_to_jd(t,a+1,i)+Math.floor(s+60*(n+60*r)+.5)/86400,this.ON.julianday=e,this.ON.modifiedjulianday=e-this.JMJD,o=this.ASTRO.jwday(e),this.ON.gregorian.weekday=o+1,this.ON.gregorian.leap=this.NormLeap[this.leap_gregorian(t)?1:0],o=this.ASTRO.jwday(e),"persian"==this.parent.calendarType&&"algorithmic"==this.parent.leapYearMode&&(u=this.jd_to_persian(e),this.ON.persian.year=u[0],this.ON.persian.month=u[1]-1,this.ON.persian.day=u[2],this.ON.persian.weekday=this.gWeekDayToPersian(o),this.ON.persian.leap=this.NormLeap[this.leap_persian(u[0])?1:0]),"persian"==this.parent.calendarType&&"astronomical"==this.parent.leapYearMode&&(u=this.jd_to_persiana(e),this.ON.persianAstro.year=u[0],this.ON.persianAstro.month=u[1]-1,this.ON.persianAstro.day=u[2],this.ON.persianAstro.weekday=this.gWeekDayToPersian(o),this.ON.persianAstro.leap=this.NormLeap[this.leap_persiana(u[0])?1:0]),null!==this.ON.gregserial.day&&(this.ON.gregserial.day=e-this.J0000),h=864e5*(e-this.J1970),this.ON.unixtime=Math.round(h/1e3)}},{key:"calcGregorian",value:function(e){(e[0]||0===e[0])&&(this.ON.gregorian.year=e[0]),(e[1]||0===e[1])&&(this.ON.gregorian.month=e[1]),(e[2]||0===e[2])&&(this.ON.gregorian.day=e[2]),(e[3]||0===e[3])&&(this.ON.gregorian.hour=e[3]),(e[4]||0===e[4])&&(this.ON.gregorian.minute=e[4]),(e[5]||0===e[5])&&(this.ON.gregorian.second=e[5]),(e[6]||0===e[6])&&(this.ON.gregorian.millisecond=e[6]),this.updateFromGregorian()}},{key:"calcJulian",value:function(){var e=void 0,t=void 0;e=this.ON.julianday,t=this.jd_to_gregorian(e),this.ON.gregorian.year=t[0],this.ON.gregorian.month=t[1]-1,this.ON.gregorian.day=t[2],this.updateFromGregorian()}},{key:"setJulian",value:function(e){this.ON.julianday=e,this.calcJulian()}},{key:"calcPersian",value:function(e){e[0]&&(this.ON.persian.year=e[0]),e[1]&&(this.ON.persian.month=e[1]),e[2]&&(this.ON.persian.day=e[2]),e[3]&&(this.ON.gregorian.hour=e[3]),e[4]&&(this.ON.gregorian.minute=e[4]),e[5]&&(this.ON.gregorian.second=e[5]),e[6]&&(this.ON.gregorian.millisecond=e[6]),this.setJulian(this.persian_to_jd(this.ON.persian.year,this.ON.persian.month,this.ON.persian.day))}},{key:"calcPersiana",value:function(e){e[0]&&(this.ON.persianAstro.year=e[0]),e[1]&&(this.ON.persianAstro.month=e[1]),e[2]&&(this.ON.persianAstro.day=e[2]),e[3]&&(this.ON.gregorian.hour=e[3]),e[4]&&(this.ON.gregorian.minute=e[4]),e[5]&&(this.ON.gregorian.second=e[5]),e[6]&&(this.ON.gregorian.millisecond=e[6]),this.setJulian(this.persiana_to_jd(this.ON.persianAstro.year,this.ON.persianAstro.month,this.ON.persianAstro.day+.5))}}]),e}();e.exports=o},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a=1620&&e<=2e3?(i=Math.floor((e-1620)/2),a=(e-1620)/2-i,t=this.deltaTtab[i]+(this.deltaTtab[i+1]-this.deltaTtab[i])*a):(r=(e-2e3)/100,e<948?t=2177+497*r+44.1*r*r:(t=102+102*r+25.3*r*r,e>2e3&&e<2100&&(t+=.37*(e-2100)))),t}},{key:"equinox",value:function(e,t){var a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0,d=void 0;for(e<1e3?(s=this.JDE0tab1000,d=e/1e3):(s=this.JDE0tab2000,d=(e-2e3)/1e3),n=s[t][0]+s[t][1]*d+s[t][2]*d*d+s[t][3]*d*d*d+s[t][4]*d*d*d*d,h=(n-2451545)/36525,u=35999.373*h-2.47,a=1+.0334*this.dcos(u)+7e-4*this.dcos(2*u),o=0,i=r=0;i<24;i++)o+=this.EquinoxpTerms[r]*this.dcos(this.EquinoxpTerms[r+1]+this.EquinoxpTerms[r+2]*h),r+=3;return n+1e-5*o/a}},{key:"sunpos",value:function(e){var t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0,o=void 0,h=void 0,u=void 0,d=void 0,l=void 0,c=void 0,y=void 0,f=void 0,v=void 0,m=void 0,p=void 0;return t=(e-this.J2000)/this.JulianCentury,a=t*t,i=280.46646+36000.76983*t+3032e-7*a,i=this.fixangle(i),r=357.52911+35999.05029*t+-1537e-7*a,r=this.fixangle(r),n=.016708634+-42037e-9*t+-1.267e-7*a,s=(1.914602+-.004817*t+-14e-6*a)*this.dsin(r)+(.019993-101e-6*t)*this.dsin(2*r)+289e-6*this.dsin(3*r),o=i+s,h=r+s,u=1.000001018*(1-n*n)/(1+n*this.dcos(h)),d=125.04-1934.136*t,l=o+-.00569+-.00478*this.dsin(d),y=this.obliqeq(e),c=y+.00256*this.dcos(d),f=this.rtd(Math.atan2(this.dcos(y)*this.dsin(o),this.dcos(o))),f=this.fixangle(f),v=this.rtd(Math.asin(this.dsin(y)*this.dsin(o))),m=this.rtd(Math.atan2(this.dcos(c)*this.dsin(l),this.dcos(l))),m=this.fixangle(m),p=this.rtd(Math.asin(this.dsin(c)*this.dsin(l))),[i,r,n,s,o,h,u,l,f,v,m,p]}},{key:"equationOfTime",value:function(e){var t=void 0,a=void 0,i=void 0,r=void 0,n=void 0,s=void 0;return s=(e-this.J2000)/this.JulianMillennium,n=280.4664567+360007.6982779*s+.03032028*s*s+s*s*s/49931+-s*s*s*s/15300+-s*s*s*s*s/2e6,n=this.fixangle(n),t=this.sunpos(e)[10],a=this.nutation(e)[0],r=this.obliqeq(e)+this.nutation(e)[1],i=n+-.0057183+-t+a*this.dcos(r),i-=20*Math.floor(i/20),i/=1440}}]),e}();e.exports=n},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"]}}},function(e,t,a){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var a=0;a b', function () { let a = new pDate([1392, 1, 1]), b = new pDate([1391, 1, 1]); assert.deepEqual(a.diff(b, 'year'), 1); @@ -754,6 +754,28 @@ describe('Diff', function () { assert.deepEqual(a.diff(b, 'second'), 31622400); assert.deepEqual(a.diff(b), 31622400000); }); + it('a.diff(b) a < b', function () { + let a = new pDate([1391, 1, 1]), + b = new pDate([1392, 1, 1]); + assert.deepEqual(a.diff(b, 'year'), -1); + assert.deepEqual(a.diff(b, 'month'), -12); + assert.deepEqual(a.diff(b, 'day'), -366); + assert.deepEqual(a.diff(b, 'hour'), -8784); + assert.deepEqual(a.diff(b, 'minute'), -527040); + assert.deepEqual(a.diff(b, 'second'), -31622400); + assert.deepEqual(a.diff(b), -31622400000); + }); + it('a.diff(b) a === b', function () { + let a = new pDate([1391, 1, 1]), + b = new pDate([1391, 1, 1]); + assert.deepEqual(a.diff(b, 'year'), 0); + assert.deepEqual(a.diff(b, 'month'), 0); + assert.deepEqual(a.diff(b, 'day'), 0); + assert.deepEqual(a.diff(b, 'hour'), 0); + assert.deepEqual(a.diff(b, 'minute'), 0); + assert.deepEqual(a.diff(b, 'second'), 0); + assert.deepEqual(a.diff(b), 0); + }); }); From d0874b47877f1c7f26315b1be25c7e435abc593d Mon Sep 17 00:00:00 2001 From: Amin Mousavi Date: Sat, 8 Sep 2018 01:43:32 +0430 Subject: [PATCH 2/2] - Removed coverage folder from .gitignore. --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e6286e1..9d3f1ea 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ .settings/org.eclipse.core.resources.prefs node_modules .idea -.nyc_output -coverage \ No newline at end of file +.nyc_output \ No newline at end of file