idate
Version:
Iranian Date constractor for Javascript
1 lines • 6.67 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.IDate=e():t.IDate=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";function r(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var u=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(1),c=["getHours","getMilliseconds","getMinutes","getSeconds","getTime","getTimezoneOffset","getUTCDate","getUTCDay","getUTCFullYear","getUTCHours","getUTCMilliseconds","getUTCMinutes","getUTCMonth","getUTCSeconds","now","parse","setHours","setMilliseconds","setMinutes","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","toDateString","toISOString","toJSON","toLocaleDateString","toLocaleTimeString","toLocaleString","toTimeString","toUTCString","UTC","valueOf"],f=["Shanbe","Yekshanbe","Doshanbe","Seshanbe","Chaharshanbe","Panjshanbe","Jom'e"],l=["شنبه","یکشنبه","دوشنبه","سهشنبه","چهارشنبه","پنجشنبه","جمعه"],g=["Farvardin","Ordibehesht","Khordad","Tir","Mordad","Shahrivar","Mehr","Aban","Azar","Dey","Bahman","Esfand"],h=["فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"],d=["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"],y=function(t){function e(){o(this,e);var t=a(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),n=void 0,i=Array.from(arguments);if(0===i.length)n=Date.now();else if(1===i.length)n=i[0]instanceof Date?i[0].getTime():i[0];else{var u=(0,s.fixDate)(i[0],i[1]||0,void 0===i[2]?1:i[2]),f=(0,s.toGregorian)(u[0],u[1]+1,u[2]);n=[f.gy,f.gm-1,f.gd].concat([i[3]||0,i[4]||0,i[5]||0,i[6]||0])}Array.isArray(n)?t.gdate=new(Function.prototype.bind.apply(Date,[null].concat(r(n)))):t.gdate=new Date(n);var l=(0,s.toJalaali)(t.gdate.getFullYear(),t.gdate.getMonth()+1,t.gdate.getDate());return t.jdate=[l.jy,l.jm-1,l.jd],c.forEach(function(t){e.prototype[t]=function(){var e;return(e=this.gdate)[t].apply(e,arguments)}}),t}return i(e,t),u(e,[{key:"getFullYear",value:function(){return this.jdate[0]}},{key:"setFullYear",value:function(t){return this.jdate=(0,s.fixDate)(t,this.jdate[1],this.jdate[2]),this.syncDate(),this.gdate.getTime()}},{key:"getMonth",value:function(){return this.jdate[1]}},{key:"setMonth",value:function(t){return this.jdate=(0,s.fixDate)(this.jdate[0],t,this.jdate[2]),this.syncDate(),this.gdate.getTime()}},{key:"getDate",value:function(){return this.jdate[2]}},{key:"setDate",value:function(t){return this.jdate=(0,s.fixDate)(this.jdate[0],this.jdate[1],t),this.syncDate(),this.gdate.getTime()}},{key:"getDay",value:function(){return(this.gdate.getDay()+1)%7}},{key:"syncDate",value:function(){var t=(0,s.toGregorian)(this.jdate[0],this.jdate[1]+1,this.jdate[2]);this.gdate.setFullYear(t.gy),this.gdate.setMonth(t.gm-1),this.gdate.setDate(t.gd)}},{key:"toString",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],e=function(t){return 1===t.toString().length?"0"+t:t.toString()},n=e(this.getHours())+":"+e(this.getMinutes())+":"+e(this.getSeconds());return t?function(t){return t.replace(/./g,function(t){return d[t]||t})}(l[this.getDay()]+" "+this.getDate()+" "+h[this.getMonth()]+" "+this.getFullYear()+" ساعت "+n):f[this.getDay()]+" "+this.getDate()+" "+g[this.getMonth()]+" "+this.getFullYear()+" "+n}}]),e}(Date);e.default=y,t.exports=e.default},function(t,e,n){"use strict";function r(t,e,n){return"[object Date]"===Object.prototype.toString.call(t)&&(n=t.getDate(),e=t.getMonth()+1,t=t.getFullYear()),c(f(t,e,n))}function o(t,e,n){return l(s(t,e,n))}function a(t){return 0===u(t).leap}function i(t,e){return e<=6?31:e<=11?30:a(t)?30:29}function u(t){var e,n,r,o,a,i,u,s=[-61,9,38,199,426,686,756,818,1111,1181,1210,1635,2060,2097,2192,2262,2324,2394,2456,3178],c=s.length,f=t+621,l=-14,d=s[0];if(t<d||t>=s[c-1])throw new Error("Invalid Jalaali year "+t);for(u=1;u<c&&(e=s[u],n=e-d,!(t<e));u+=1)l=l+8*g(n,33)+g(h(n,33),4),d=e;return i=t-d,l=l+8*g(i,33)+g(h(i,33)+3,4),4===h(n,33)&&n-i==4&&(l+=1),o=g(f,4)-g(3*(g(f,100)+1),4)-150,a=20+l-o,n-i<6&&(i=i-n+33*g(n+4,33)),r=h(h(i+1,33)-1,4),-1===r&&(r=4),{leap:r,gy:f,march:a}}function s(t,e,n){var r=u(t);return f(r.gy,3,r.march)+31*(e-1)-g(e,7)*(e-7)+n-1}function c(t){var e,n,r,o=l(t).gy,a=o-621,i=u(a),s=f(o,3,i.march);if((r=t-s)>=0){if(r<=185)return n=1+g(r,31),e=h(r,31)+1,{jy:a,jm:n,jd:e};r-=186}else a-=1,r+=179,1===i.leap&&(r+=1);return n=7+g(r,30),e=h(r,30)+1,{jy:a,jm:n,jd:e}}function f(t,e,n){var r=g(1461*(t+g(e-8,6)+100100),4)+g(153*h(e+9,12)+2,5)+n-34840408;return r=r-g(3*g(t+100100+g(e-8,6),100),4)+752}function l(t){var e,n,r,o,a;return e=4*t+139361631,e=e+4*g(3*g(4*t+183187720,146097),4)-3908,n=5*g(h(e,1461),4)+308,r=g(h(n,153),5)+1,o=h(g(n,153),12)+1,a=g(e,1461)-100100+g(8-o,6),{gy:a,gm:o,gd:r}}function g(t,e){return~~(t/e)}function h(t,e){return t-~~(t/e)*e}function d(t,e,n){for(;e>11;)t+=1,e-=12;for(;e<0;)t-=1,e+=12;for(;n>i(t,e+1);)n-=i(t,e+1),e=e<11?e+1:0,t=0===e?t+1:t;for(;n<=0;)e=e>0?e-1:11,t=11===e?t-1:t,n+=i(t,e+1);return[t,e,n]}Object.defineProperty(e,"__esModule",{value:!0}),e.toJalaali=r,e.toGregorian=o,e.monthLength=i,e.fixDate=d}])});