react-date-object
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["react-date-object"]=t():e["react-date-object"]=t()}(window,(function(){return function(e){var t={};function n(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(a,r,function(t){return e[t]}.bind(null,r));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],a=!0,r=!1,s=void 0;try{for(var o,i=e[Symbol.iterator]();!(a=(o=i.next()).done)&&(n.push(o.value),!t||n.length!==t);a=!0);}catch(e){r=!0,s=e}finally{try{a||null==i.return||i.return()}finally{if(r)throw s}}return n}(e,t)||o(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){var n=t.get(e);if(!n)throw new TypeError("attempted to get private field on non-instance");return n.get?n.get.call(e):n.value}function m(e,t,n){var a=t.get(e);if(!a)throw new TypeError("attempted to set private field on non-instance");if(a.set)a.set.call(e,n);else{if(!a.writable)throw new TypeError("attempted to set read only private field");a.value=n}return n}n.r(t);var f=new WeakMap,d=new WeakMap,N=new WeakMap,y=new WeakMap,b=new WeakMap,v=new WeakMap,p=new WeakMap,g=new WeakMap,w=new WeakMap,A=new WeakMap,k=new WeakMap,E=new WeakMap,M=new WeakMap,O=new WeakMap,S=new WeakMap,F=new WeakMap,D=new WeakMap,x=new WeakMap,Y=new WeakMap,W=new WeakMap,I=function(){function e(){var t,n,a,r,s,o,i,h,I,j,P,G,R,L,C,T,H,z,J,_,U,B,K,$,q,Q,V,X,Z,ee,te,ne,ae,re,se,oe,ie,le,he,ue,ce,me,fe,de=this,Ne=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{date:new Date};l(this,e),f.set(this,{writable:!0,value:void 0}),d.set(this,{writable:!0,value:void 0}),N.set(this,{writable:!0,value:void 0}),y.set(this,{writable:!0,value:void 0}),b.set(this,{writable:!0,value:void 0}),v.set(this,{writable:!0,value:void 0}),p.set(this,{writable:!0,value:void 0}),g.set(this,{writable:!0,value:void 0}),w.set(this,{writable:!0,value:e.locals.EN}),A.set(this,{writable:!0,value:e.calendars.GEORGIAN}),k.set(this,{writable:!0,value:[]}),E.set(this,{writable:!0,value:{YYYY:/\d{4}/,YY:/\d\d/,MMMM:/[A-z]+/,MMM:/[A-z]+/,MM:/\d\d/,M:/\d/,DDDD:/\d{1,3}/,DDD:/\d{1,3}/,DD:/\d\d/,D:/\d/,dddd:/[A-z]+/,ddd:/[A-z]+/,HH:/\d\d/,H:/\d/,hh:/\d\d/,h:/\d/,mm:/\d\d/,m:/\d/,ss:/\d\d/,s:/\d/,SSS:/\d{3}/,SS:/\d\d/,S:/\d/,a:/[a-z]{2,9}/,A:/[a-z]{2,9}/}}),M.set(this,{writable:!0,value:{YYYY:function(e){return m(de,f,Number(e))},YY:function(e){return m(de,f,Number(e))},MMMM:function(e){return m(de,d,de.months.findIndex((function(t){return e.toLowerCase()===t.name.toLowerCase()})))},MMM:function(e){return m(de,d,de.months.findIndex((function(t){return e.toLowerCase()===t.shortName.toLowerCase()})))},MM:function(e){return m(de,d,Number(e)-1)},M:function(e){return m(de,d,Number(e)-1)},DD:function(e){return m(de,N,Number(e))},D:function(e){return m(de,N,Number(e))},HH:function(e){return m(de,y,Number(e))},H:function(e){return m(de,y,Number(e))},hh:function(e){var t=Number(e);m(de,y,t>12?t-12:t)},h:function(e){var t=Number(e);m(de,y,t>12?t-12:t)},mm:function(e){return m(de,b,Number(e))},m:function(e){return m(de,b,Number(e))},ss:function(e){return m(de,v,Number(e))},s:function(e){return m(de,v,Number(e))},SSS:function(e){return de.millisecond=Number(e)},SS:function(e){return de.millisecond=Number(e)},S:function(e){return de.millisecond=Number(e)}}}),O.set(this,{writable:!0,value:(q={},u(q,e.calendars.GEORGIAN,[{length:31,locals:(t={},u(t,e.locals.EN,{name:"January",shortName:"Jan"}),u(t,e.locals.FA,{name:"ژانویه",shortName:"ژان"}),t)},{length:void 0,locals:(n={},u(n,e.locals.EN,{name:"February",shortName:"Feb"}),u(n,e.locals.FA,{name:"فوریه",shortName:"فور"}),n)},{length:31,locals:(a={},u(a,e.locals.EN,{name:"March",shortName:"Mar"}),u(a,e.locals.FA,{name:"مارس",shortName:"ما"}),a)},{length:30,locals:(r={},u(r,e.locals.EN,{name:"April",shortName:"Apr"}),u(r,e.locals.FA,{name:"آوریل",shortName:"آور"}),r)},{length:31,locals:(s={},u(s,e.locals.EN,{name:"May",shortName:"May"}),u(s,e.locals.FA,{name:"مه",shortName:"مه"}),s)},{length:30,locals:(o={},u(o,e.locals.EN,{name:"June",shortName:"June"}),u(o,e.locals.FA,{name:"ژوئن",shortName:"ژوئن"}),o)},{length:31,locals:(i={},u(i,e.locals.EN,{name:"July",shortName:"July"}),u(i,e.locals.FA,{name:"ژوئیه",shortName:"ژوئیه"}),i)},{length:31,locals:(h={},u(h,e.locals.EN,{name:"August",shortName:"Aug"}),u(h,e.locals.FA,{name:"اوت",shortName:"اوت"}),h)},{length:30,locals:(I={},u(I,e.locals.EN,{name:"September",shortName:"Sept"}),u(I,e.locals.FA,{name:"سپتامبر",shortName:"سپ"}),I)},{length:31,locals:(j={},u(j,e.locals.EN,{name:"October",shortName:"Oct"}),u(j,e.locals.FA,{name:"اکتبر",shortName:"اک"}),j)},{length:30,locals:(P={},u(P,e.locals.EN,{name:"November",shortName:"Nov"}),u(P,e.locals.FA,{name:"نوامبر",shortName:"نو"}),P)},{length:31,locals:(G={},u(G,e.locals.EN,{name:"December",shortName:"Dec"}),u(G,e.locals.FA,{name:"دسامبر",shortName:"دس"}),G)}]),u(q,e.calendars.PERSIAN,[{length:31,locals:(R={},u(R,e.locals.EN,{name:"Farvardin",shortName:"Far"}),u(R,e.locals.FA,{name:"فروردین",shortName:"فر"}),R)},{length:31,locals:(L={},u(L,e.locals.EN,{name:"Ordibehesht",shortName:"Ord"}),u(L,e.locals.FA,{name:"اردیبهشت",shortName:"ار"}),L)},{length:31,locals:(C={},u(C,e.locals.EN,{name:"Khordad",shortName:"Khor"}),u(C,e.locals.FA,{name:"خرداد",shortName:"خرد"}),C)},{length:31,locals:(T={},u(T,e.locals.EN,{name:"Tir",shortName:"Tir"}),u(T,e.locals.FA,{name:"تیر",shortName:"تیر"}),T)},{length:31,locals:(H={},u(H,e.locals.EN,{name:"Mordad",shortName:"Mor"}),u(H,e.locals.FA,{name:"مرداد",shortName:"مر"}),H)},{length:31,locals:(z={},u(z,e.locals.EN,{name:"Shahrivar",shortName:"Sha"}),u(z,e.locals.FA,{name:"شهریور",shortName:"شه"}),z)},{length:30,locals:(J={},u(J,e.locals.EN,{name:"Mehr",shortName:"Mehr"}),u(J,e.locals.FA,{name:"مهر",shortName:"مه"}),J)},{length:30,locals:(_={},u(_,e.locals.EN,{name:"Aban",shortName:"Aban"}),u(_,e.locals.FA,{name:"آبان",shortName:"آبا"}),_)},{length:30,locals:(U={},u(U,e.locals.EN,{name:"Azar",shortName:"Azar"}),u(U,e.locals.FA,{name:"آذر",shortName:"آذ"}),U)},{length:30,locals:(B={},u(B,e.locals.EN,{name:"Dey",shortName:"Dey"}),u(B,e.locals.FA,{name:"دی",shortName:"دی"}),B)},{length:30,locals:(K={},u(K,e.locals.EN,{name:"Bahman",shortName:"Bah"}),u(K,e.locals.FA,{name:"بهمن",shortName:"بهم"}),K)},{length:void 0,locals:($={},u($,e.locals.EN,{name:"Esfand",shortName:"Esf"}),u($,e.locals.FA,{name:"اسفند",shortName:"اسف"}),$)}]),q)}),S.set(this,{writable:!0,value:(ue={},u(ue,e.calendars.GEORGIAN,[{index:0,locals:(Q={},u(Q,e.locals.EN,{name:"Sunday",shortName:"Sun"}),u(Q,e.locals.FA,{name:"یکشنبه",shortName:"یک"}),Q)},{index:1,locals:(V={},u(V,e.locals.EN,{name:"Monday",shortName:"Mon"}),u(V,e.locals.FA,{name:"دوشنبه",shortName:"دو"}),V)},{index:2,locals:(X={},u(X,e.locals.EN,{name:"Tuesday",shortName:"Tue"}),u(X,e.locals.FA,{name:"سه شنبه",shortName:"سه"}),X)},{index:3,locals:(Z={},u(Z,e.locals.EN,{name:"Wednesday",shortName:"Wed"}),u(Z,e.locals.FA,{name:"چهارشنبه",shortName:"چهار"}),Z)},{index:4,locals:(ee={},u(ee,e.locals.EN,{name:"Thursday",shortName:"Thu"}),u(ee,e.locals.FA,{name:"پنجشنبه",shortName:"پنج"}),ee)},{index:5,locals:(te={},u(te,e.locals.EN,{name:"Friday",shortName:"Fri"}),u(te,e.locals.FA,{name:"جمعه",shortName:"جم"}),te)},{index:6,locals:(ne={},u(ne,e.locals.EN,{name:"Saturday",shortName:"Sat"}),u(ne,e.locals.FA,{name:"شنبه",shortName:"شن"}),ne)}]),u(ue,e.calendars.PERSIAN,[{index:5,locals:(ae={},u(ae,e.locals.EN,{name:"Panjshanbeh",shortName:"Pa"}),u(ae,e.locals.FA,{name:"پنجشنبه",shortName:"پنج"}),ae)},{index:6,locals:(re={},u(re,e.locals.EN,{name:"Jomeh",shortName:"Jo"}),u(re,e.locals.FA,{name:"جمعه",shortName:"جم"}),re)},{index:0,locals:(se={},u(se,e.locals.EN,{name:"Shanbeh",shortName:"Sh"}),u(se,e.locals.FA,{name:"شنبه",shortName:"شن"}),se)},{index:1,locals:(oe={},u(oe,e.locals.EN,{name:"YekShanbeh",shortName:"Ye"}),u(oe,e.locals.FA,{name:"یکشنبه",shortName:"یک"}),oe)},{index:2,locals:(ie={},u(ie,e.locals.EN,{name:"Doshanbeh",shortName:"Do"}),u(ie,e.locals.FA,{name:"دوشنبه",shortName:"دو"}),ie)},{index:3,locals:(le={},u(le,e.locals.EN,{name:"Seshanbeh",shortName:"Se"}),u(le,e.locals.FA,{name:"سه شنبه",shortName:"سه"}),le)},{index:4,locals:(he={},u(he,e.locals.EN,{name:"Chaharshanbeh",shortName:"Ch"}),u(he,e.locals.FA,{name:"چهارشنبه",shortName:"چهار"}),he)}]),ue)}),F.set(this,{writable:!0,value:(ce={},u(ce,e.locals.EN,["0","1","2","3","4","5","6","7","8","9"]),u(ce,e.locals.FA,["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"]),ce)}),D.set(this,{writable:!0,value:(me={},u(me,e.locals.EN,[{name:"AM",shortName:"am"},{name:"PM",shortName:"pm"}]),u(me,e.locals.FA,[{name:"قبل از ظهر",shortName:"ق.ظ"},{name:"بعد از ظهر",shortName:"ب.ظ"}]),me)}),x.set(this,{writable:!0,value:(fe={},u(fe,e.calendars.PERSIAN,u({},e.calendars.GEORGIAN,226895)),u(fe,e.calendars.GEORGIAN,u({},e.calendars.PERSIAN,-226895)),fe)}),Y.set(this,{writable:!0,value:function(){var e=function(){for(var e=!1;c(de,d)<1;)m(de,d,c(de,d)+12),m(de,f,c(de,f)-1),0===c(de,f)&&m(de,f,-1),e=!0;for(;c(de,d)>11;)m(de,d,c(de,d)-12),m(de,f,c(de,f)+1),0===c(de,f)&&m(de,f,1),e=!0;e&&c(de,W).call(de)};if(!(Number.isNaN(Number(c(de,f)))||Number.isNaN(Number(c(de,d)))||Number.isNaN(Number(c(de,N))))){for(;c(de,p)>=1e3;)m(de,p,c(de,p)-1e3),m(de,v,c(de,v)+1);for(;c(de,p)<0;)m(de,p,c(de,p)+1e3),m(de,v,c(de,v)-1);for(;c(de,v)>=60;)m(de,v,c(de,v)-60),m(de,b,c(de,b)+1);for(;c(de,v)<0;)m(de,v,c(de,v)+60),m(de,b,c(de,b)-1);for(;c(de,b)>=60;)m(de,b,c(de,b)-60),m(de,y,c(de,y)+1);for(;c(de,b)<0;)m(de,b,c(de,b)+60),m(de,y,c(de,y)-1);for(;c(de,y)>=24;)m(de,y,c(de,y)-24),m(de,N,c(de,N)+1);for(;c(de,y)<0;)m(de,y,c(de,y)+24),m(de,N,c(de,N)-1);for(;;){for((c(de,d)<1||c(de,d)>11)&&e();c(de,N)<1;)m(de,d,c(de,d)-1),e(),m(de,N,de.month.length+c(de,N));if(c(de,N)<=de.month.length)break;m(de,N,c(de,N)-de.month.length),m(de,d,1+ +c(de,d))}}}}),W.set(this,{writable:!0,value:function(){if(0!==c(de,f)){var t=c(de,f)>0?1:-1,n=function(){return c(de,f)>0?t<=c(de,f):c(de,f)<=t},a=function(){return c(de,f)>0?t++:t--};switch(m(de,k,[]),c(de,A)){case e.calendars.PERSIAN:for(var r=.2684,s={5:4,38:37,199:198,232:231,265:264,298:297,557:558,590:591,623:624,982:983,1015:1016,1048:1049,1081:1082,1114:1115,1242:1243,1374:1375,1407:1408,1440:1441,1506:1507,1539:1540,1572:1573,1605:1606,1931:1932,1964:1965,2063:2064,2096:2097,2687:2686,2720:2719,2753:2752,2819:2818,2852:2851,2885:2884,3017:3016,3112:3111,3145:3144,3178:3177,3211:3210,3244:3243,3277:3276,3310:3309,3343:3342,3376:3375,3409:3408,3442:3441,3508:3507,3541:3540,3574:3573,3603:3602,3607:3606,3636:3635,3669:3668,3702:3701,3706:3705,3735:3734,3768:3767,3801:3800,3834:3833,3867:3866,3900:3899,3933:3932,3966:3965,3999:3998,4065:4064,4094:4093,4098:4097,4127:4126,4131:4130,4160:4159,4193:4192,4226:4225,4259:4258,4292:4291,4325:4324,4358:4357,4391:4390,4585:4584,4618:4617,4651:4650,4750:4749,4943:4944,4976:4977,5009:5010,5170:5171,5203:5204,5236:5237,5265:5266,5269:5270,5298:5299,5302:5303,5331:5332,5335:5336,5364:5365,5368:5369,5393:5394,5397:5398,5401:5402,5426:5427,5430:5431,5434:5435,5459:5460,5463:5464,5467:5468,5492:5493,5496:5497,5500:5501,5521:5522,5525:5526,5529:5530,5554:5555,5558:5559,5562:5563,5587:5588,5591:5592,5595:5596,5616:5617,5620:5621,5624:5625,5628:5629,5649:5650,5653:5654,5657:5658,5661:5662,5682:5683,5686:5687,5690:5691,5694:5695,5715:5716,5719:5720,5723:5724,5727:5728,5744:5745,5748:5749,5752:5753,5756:5757,5760:5761,5777:5778,5781:5782,5785:5786,5789:5790,5793:5794,5810:5811,5814:5815,5818:5819,5822:5823,5826:5827,5839:5840,5843:5844,5847:5848,5851:5852,5855:5856,5859:5860,5872:5873,5876:5877,5880:5881,5884:5885,5888:5889,5892:5893,5901:5902,5905:5906,5909:5910,5913:5914,5917:5918,5921:5922,5925:5926,5934:5935,5938:5939,5942:5943,5946:5947,5950:5951,5954:5955,5958:5959,5967:5968,5971:5972,5975:5976,5979:5980,5983:5984,5987:5988,5991:5992,5996:5997,6e3:6001,6004:6005,6008:6009,6012:6013,6016:6017,6020:6021,6029:6030,6033:6034,6037:6038,6041:6042,6045:6046,6049:6050,6053:6054,6058:6059,6062:6063,6066:6067,6070:6071,6074:6075,6078:6079,6082:6083,6086:6087,6091:6092,6095:6096,6099:6100,6103:6104,6107:6108,6111:6112,6115:6116,6119:6120,6124:6125,6128:6129,6132:6133,6136:6137,6140:6141,6144:6145,6148:6149,6152:6154,6157:6158,6161:6162,6165:6166,6169:6170,6173:6174,6177:6178,6181:6182,6185:6187,6190:6191,6194:6195,6198:6199,6202:6203,6206:6207,6210:6211,6214:6215,6218:6220,6223:6224,6227:6228,6231:6232,6235:6236,6239:6240,6243:6244,6247:6249,6251:6253,6256:6257,6260:6261,6264:6265,6268:6269,6272:6273,6276:6277,6280:6282,6284:6286,6289:6290,6293:6294,6297:6298,6301:6302,6305:6306,6309:6310,6313:6315,6317:6319,6322:6323,6326:6327,6330:6331,6334:6335,6338:6339,6342:6344,6346:6348,6350:6352,6355:6356,6359:6360,6363:6364,6367:6368,6371:6372,6375:6377,6379:6381,6383:6385,6388:6389,6392:6393,6396:6397,6400:6401,6404:6406,6408:6410,6412:6414,6416:6418,6421:6422,6425:6426,6429:6430,6433:6434,6437:6439,6441:6443,6445:6447,6449:6451,6454:6455,6458:6459,6462:6463,6466:6468,6470:6472,6474:6476,6478:6480,6482:6484,6487:6488,6491:6492,6495:6496};n();){if((r+=c(de,f)>0?.242362:-.242362)>1&&(r-=1),r<0&&(r+=1),r>=.257800926&&r<=.5){var o=s[t]||t;c(de,f)>0&&o<=c(de,f)&&c(de,k).push(o),c(de,f)<0&&c(de,k).push(o)}a()}break;default:for(;n();)(t%4==0&&t%100!=0||t%400==0)&&c(de,k).push(t),a()}}}}),(Ne instanceof Date||Ne instanceof e||"string"==typeof Ne)&&(Ne={date:Ne});var ye=Ne,be=ye.calendar,ve=ye.local,pe=ye.format,ge=ye.date,we=ye.year,Ae=ye.month,ke=ye.day,Ee=ye.hour,Me=ye.minute,Oe=ye.second,Se=ye.millisecond,Fe=!0;if(be&&m(this,A,e.calendars[be.toUpperCase()]),!c(this,A))throw new Error("calendar not found");ve&&m(this,w,e.locals[ve.toUpperCase()]||e.locals.EN),!be||ge||we||Ae||ke||Ee||Me||Oe||Se||(ge=new Date),m(this,g,pe),"string"==typeof ge&&this.parse(ge);var De=function(){0===Ae&&(Ae=1),m(de,f,we),m(de,d,Ae-1),m(de,N,ke),m(de,y,Ee),m(de,b,Me),m(de,v,Oe),m(de,p,Se)};if(ge instanceof e&&(m(this,f,ge.year),m(this,d,ge.month.index),m(this,N,ge.day),m(this,y,ge.hour),m(this,b,ge.minute),m(this,v,ge.second),m(this,p,ge.millisecond),m(this,A,ge.calendar.toUpperCase()),m(this,w,ge.local.toUpperCase()),m(this,g,ge._format),m(this,k,ge.leaps),Fe=!1),ge instanceof Date){if(we=ge.getFullYear(),Ae=ge.getMonth()+1,ke=ge.getDate(),Ee=ge.getHours(),Me=ge.getMinutes(),Oe=ge.getSeconds(),Se=ge.getMilliseconds(),c(this,A)!==e.calendars.GEORGIAN){var xe=new e({year:we,month:Ae,day:ke,hour:Ee,minute:Me,second:Oe}).convert(c(this,A));we=xe.year,Ae=xe.month.number,ke=xe.day,Ee=xe.hour,Me=xe.minute,Oe=xe.second,Se=xe.millisecond}De()}ge||De(),0===c(this,f)&&m(this,f,-1),Fe&&(c(this,W).call(this),c(this,Y).call(this))}var t,n,a;return t=e,(n=[{key:"parse",value:function(t){if(t){var n=c(this,g);if(c(this,w)!==e.locals.en){var a,r=c(this,F)[c(this,w)],i=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=o(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){l=!0,s=e},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw s}}}}(r);try{for(i.s();!(a=i.n()).done;){var l=a.value;t=t.replace(new RegExp(l,"g"),r.indexOf(l))}}catch(e){i.e(e)}finally{i.f()}}if(n){for(var h=n.split(/[^\w\u0600-\u06FF]/),u=t.split(/[^\w\u0600-\u06FF]/),A=0;A<h.length;A++){var k=c(this,M)[h[A]];k&&u[A]&&k(u[A])}c(this,y)||m(this,y,0),c(this,b)||m(this,b,0),c(this,v)||m(this,v,0),c(this,p)||m(this,p,0)}else{var E=s(t.match(/(-?\d{2,4})?\W?([A-z]{3,9}|\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,3})?\W?(am|pm)?/),9),O=E[1],S=E[2],x=E[3],Y=E[4],W=E[5],I=E[6],j=E[7],P=E[8];S&&(S=/\d+/.test(S)?Number(S)-1:this.months.findIndex((function(e){return new RegExp(S,"i").test(e.name)}))),m(this,f,O?Number(O):0),m(this,d,S||0),m(this,N,Number(x||1)),m(this,y,Number(Y||0)),m(this,b,Number(W||0)),m(this,v,Number(I||0)),m(this,p,Number(j||0)),P&&"pm"===P&&c(this,y)<12&&m(this,y,c(this,y)+12)}t.includes(c(this,D)[c(this,w)][1].shortName)&&c(this,y)<12&&m(this,y,c(this,y)+12),t.includes(c(this,D)[c(this,w)][1].name)&&c(this,y)<12&&m(this,y,c(this,y)+12)}}},{key:"convert",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.calendars.GEORGIAN;if(!(n=e.calendars[n.toUpperCase()]))throw new Error("calendar not found");if(n===c(this,A))return this;var a=function(){var a=0;switch(c(t,A)+"->"+n){case"PERSIAN->GEORGIAN":case"GEORGIAN->PERSIAN":a=c(t,d)<10||10===c(t,d)&&c(t,N)<=(t.isLeap?11:10)?n===e.calendars.GEORGIAN?621:-621:n===e.calendars.GEORGIAN?622:-622;break;default:a=0}return a},r=c(this,f),s=this.dayOfBeginning,o=void 0,i=void 0;return s+=c(this,x)[c(this,A)][n],r=1+~~((s-=(i=new e({calendar:n,year:r+a(),month:1,day:1})).isLeap?i.leaps.length-1:i.leaps.length)/365),s%=365,o=0,m(this,f,r),m(this,d,o),m(this,N,~~s),m(this,A,n),c(this,W).call(this),c(this,Y).call(this),this}},{key:"format",value:function(t){t||(t=c(this,g)||"YYYY/MM/DD");var n=100,a={};for(var r in c(this,E))for(;t.includes(r);)t=t.replace(r,n),a[n]=this.getProperty(r),console.log(a[n],r,this.getProperty(r)),n++;for(var s in a)t=t.replace(s,a[s]);if(c(this,w)!==e.locals.en){var o=c(this,F)[c(this,w)];t=t.replace(/[0-9]/g,(function(e){return o[e]}))}return t}},{key:"getProperty",value:function(e){var t=function(e){return e<10?"0"+e:e};switch(e){case"YYYY":return this.year;case"YY":return this.year.toString().substring(2,4);case"MMMM":return this.month.name;case"MMM":return this.month.shortName;case"MM":return t(this.month.number);case"M":return this.month.number;case"DDDD":case"DDD":return this.dayOfYear;case"DD":return t(this.day);case"D":return this.day;case"HH":return t(this.hour);case"H":return this.hour;case"dddd":return this.weekDay.name;case"ddd":return this.weekDay.shortName;case"hh":return t(this.hour>12?this.hour-12:this.hour);case"h":return this.hour>12?this.hour-12:this.hour;case"mm":return t(this.minute);case"m":return this.minute;case"ss":return t(this.second);case"s":return this.second;case"SSS":return c(this,p);case"SS":return c(this,p).toString().substring(0,2);case"S":return c(this,p).toString().substring(0,1);case"a":return this.hour>=12?c(this,D)[c(this,w)][1].shortName:c(this,D)[c(this,w)][0].shortName;case"A":return this.hour>=12?c(this,D)[c(this,w)][1].name:c(this,D)[c(this,w)][0].name;default:return""}}},{key:"setYear",value:function(e){return this.year=e,this}},{key:"setMonth",value:function(e){return this.month=e,this}},{key:"setDay",value:function(e){return this.day=e,this}},{key:"setHour",value:function(e){return this.hour=e,this}},{key:"setMinute",value:function(e){return this.minute=e,this}},{key:"setSecond",value:function(e){return this.second=e,this}},{key:"setMillisecond",value:function(e){return this.millisecond=e,this}},{key:"setFormat",value:function(e){return m(this,g,e),this}},{key:"setLocal",value:function(e){return this.local=e,this}},{key:"setCalendar",value:function(e){return this.calendar=e,this}},{key:"toFirstOfYear",value:function(){return this.month=1,this.day=1,this}},{key:"toLastOfYear",value:function(){return this.day>=29&&(this.day=29),this.month=12,this.toLastOfMonth(),this}},{key:"toFirstOfMonth",value:function(){return m(this,N,1),this}},{key:"toLastOfMonth",value:function(){return m(this,N,0),m(this,d,c(this,d)+1),c(this,Y).call(this),this}},{key:"toFirstOfWeek",value:function(){return this.day-=this.weekDay.index,this}},{key:"toLastOfWeek",value:function(){return this.day+=6-this.weekDay.index,this}},{key:"toFirstWeekOfYear",value:function(){return this.toFirstOfYear(),0===this.weekDay.index?this:this.toLastOfWeek().setDay(this.day+1)}},{key:"toLastWeekOfYear",value:function(){return this.toLastOfYear().toFirstOfWeek()}},{key:"toString",value:function(){return this.format()}},{key:"toDate",value:function(){return c(this,A)!==e.calendars.GEORGIAN&&this.convert(e.calendars.GEORGIAN),new Date(c(this,f),c(this,d),c(this,N),c(this,y),c(this,v))}},{key:"dayOfBeginning",get:function(){var e=365*(c(this,f)>0?c(this,f)-1:c(this,f)),t=this.isLeap?this.leaps.length-1:this.leaps.length;return c(this,f)>0&&(e+=t),c(this,f)<0&&(e-=t),e+=this.dayOfYear}},{key:"dayOfYear",get:function(){for(var e=c(this,N),t=this.months,n=0;n<t.length&&!(n>=c(this,d));n++)e+=t[n].length;return e}},{key:"weekOfYear",get:function(){return 1+~~(this.dayOfYear/7)}},{key:"daysLeft",get:function(){return(this.isLeap?366:365)-this.dayOfYear}},{key:"year",get:function(){return c(this,f)},set:function(e){m(this,f,e),c(this,W).call(this),c(this,Y).call(this)}},{key:"month",get:function(){var e=this.months[c(this,d)];return e?(e.index=c(this,d),e.number=e.index+1,e.toString=function(){return this.number},e):[]},set:function(e){m(this,d,e-1),c(this,Y).call(this)}},{key:"day",get:function(){return c(this,N)},set:function(e){m(this,N,e),c(this,Y).call(this)}},{key:"weekDay",get:function(){var e=this.dayOfBeginning%7;e<0&&(e+=7);var t=c(this,S)[c(this,A)][e];return t?t=r({index:t.index,number:t.index+1,toString:function(){return this.number}},t.locals[c(this,w)]):{}}},{key:"hour",get:function(){return c(this,y)},set:function(e){m(this,y,e),c(this,Y).call(this)}},{key:"minute",get:function(){return c(this,b)},set:function(e){m(this,b,e),c(this,Y).call(this)}},{key:"second",get:function(){return c(this,v)},set:function(e){m(this,v,e),c(this,Y).call(this)}},{key:"millisecond",get:function(){return c(this,p)},set:function(e){m(this,p,e),c(this,Y).call(this)}},{key:"months",get:function(){var t=this,n=c(this,O)[c(this,A)];switch(c(this,A)){case e.calendars.PERSIAN:n[11].length=this.isLeap?30:29;break;default:n[1].length=this.isLeap?29:28}return n=n.map((function(e){return r({length:e.length},e.locals[c(t,w)])}))}},{key:"weeks",get:function(){var e=this,t=c(this,S)[c(this,A)];return t.sort((function(e,t){return e.index-t.index})),t=t.map((function(t){return r({index:t.index,number:t.index+1},t.locals[c(e,w)])}))}},{key:"leaps",get:function(){return c(this,k)}},{key:"calendar",get:function(){return c(this,A).toLowerCase()},set:function(e){this.convert(e)}},{key:"local",get:function(){return c(this,w).toLowerCase()},set:function(t){t=t.toUpperCase(),e.locals[t]||(t=e.locals.en),m(this,w,t)}},{key:"meridiems",get:function(){return c(this,D)[c(this,w)]}},{key:"digits",get:function(){return c(this,F)[c(this,w)]}},{key:"_format",get:function(){return c(this,g)},set:function(e){m(this,g,e)}},{key:"isLeap",get:function(){return c(this,k).includes(c(this,f))}}])&&h(t.prototype,n),a&&h(t,a),e}();u(I,"calendars",{GEORGIAN:"GEORGIAN",PERSIAN:"PERSIAN"}),u(I,"locals",{EN:"EN",FA:"FA"}),t.default=I}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["react-date-object"]=t():e["react-date-object"]=t()}(window,(function(){return function(e){var t={};function n(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(a,r,function(t){return e[t]}.bind(null,r));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function a(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){h(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],a=!0,r=!1,s=void 0;try{for(var i,o=e[Symbol.iterator]();!(a=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);a=!0);}catch(e){r=!0,s=e}finally{try{a||null==o.return||o.return()}finally{if(r)throw s}}return n}(e,t)||s(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function h(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){var n=t.get(e);if(!n)throw new TypeError("attempted to get private field on non-instance");return n.get?n.get.call(e):n.value}function c(e,t,n){var a=t.get(e);if(!a)throw new TypeError("attempted to set private field on non-instance");if(a.set)a.set.call(e,n);else{if(!a.writable)throw new TypeError("attempted to set read only private field");a.value=n}return n}var m=new WeakMap,f=new WeakMap,d=new WeakMap,N=new WeakMap,y=new WeakMap,b=new WeakMap,p=new WeakMap,v=new WeakMap,g=new WeakMap,w=new WeakMap,A=new WeakMap,k=new WeakMap,E=new WeakMap,M=new WeakMap,O=new WeakMap,S=new WeakMap,F=new WeakMap,D=new WeakMap,x=new WeakMap,Y=new WeakMap,W=new WeakMap,I=function(){function e(){var t,n,a,r,s,i,l,I,j,G,P,R,L,C,T,H,z,J,U,_,B,K,$,q,Q,V,X,Z,ee,te,ne,ae,re,se,ie,oe,le,he,ue,ce,me,fe,de,Ne=this,ye=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{date:new Date};o(this,e),m.set(this,{writable:!0,value:void 0}),f.set(this,{writable:!0,value:void 0}),d.set(this,{writable:!0,value:void 0}),N.set(this,{writable:!0,value:void 0}),y.set(this,{writable:!0,value:void 0}),b.set(this,{writable:!0,value:void 0}),p.set(this,{writable:!0,value:void 0}),v.set(this,{writable:!0,value:void 0}),g.set(this,{writable:!0,value:e.locals.EN}),w.set(this,{writable:!0,value:e.calendars.GEORGIAN}),A.set(this,{writable:!0,value:[]}),k.set(this,{writable:!0,value:{YYYY:/\d{4}/,YY:/\d\d/,MMMM:/[A-z]+/,MMM:/[A-z]+/,MM:/\d\d/,M:/\d/,DDDD:/\d{1,3}/,DDD:/\d{1,3}/,DD:/\d\d/,D:/\d/,dddd:/[A-z]+/,ddd:/[A-z]+/,HH:/\d\d/,H:/\d/,hh:/\d\d/,h:/\d/,mm:/\d\d/,m:/\d/,ss:/\d\d/,s:/\d/,SSS:/\d{3}/,SS:/\d\d/,S:/\d/,a:/[a-z]{2,9}/,A:/[a-z]{2,9}/}}),E.set(this,{writable:!0,value:{YYYY:function(e){return c(Ne,m,Number(e))},YY:function(e){return c(Ne,m,Number(e))},MMMM:function(e){return c(Ne,f,Ne.months.findIndex((function(t){return e.toLowerCase()===t.name.toLowerCase()})))},MMM:function(e){return c(Ne,f,Ne.months.findIndex((function(t){return e.toLowerCase()===t.shortName.toLowerCase()})))},MM:function(e){return c(Ne,f,Number(e)-1)},M:function(e){return c(Ne,f,Number(e)-1)},DD:function(e){return c(Ne,d,Number(e))},D:function(e){return c(Ne,d,Number(e))},HH:function(e){return c(Ne,N,Number(e))},H:function(e){return c(Ne,N,Number(e))},hh:function(e){var t=Number(e);c(Ne,N,t>12?t-12:t)},h:function(e){var t=Number(e);c(Ne,N,t>12?t-12:t)},mm:function(e){return c(Ne,y,Number(e))},m:function(e){return c(Ne,y,Number(e))},ss:function(e){return c(Ne,b,Number(e))},s:function(e){return c(Ne,b,Number(e))},SSS:function(e){return Ne.millisecond=Number(e)},SS:function(e){return Ne.millisecond=Number(e)},S:function(e){return Ne.millisecond=Number(e)}}}),M.set(this,{writable:!0,value:(Q={},h(Q,e.calendars.GEORGIAN,[{length:31,locals:(t={},h(t,e.locals.EN,{name:"January",shortName:"Jan"}),h(t,e.locals.FA,{name:"ژانویه",shortName:"ژان"}),t)},{length:void 0,locals:(n={},h(n,e.locals.EN,{name:"February",shortName:"Feb"}),h(n,e.locals.FA,{name:"فوریه",shortName:"فور"}),n)},{length:31,locals:(a={},h(a,e.locals.EN,{name:"March",shortName:"Mar"}),h(a,e.locals.FA,{name:"مارس",shortName:"ما"}),a)},{length:30,locals:(r={},h(r,e.locals.EN,{name:"April",shortName:"Apr"}),h(r,e.locals.FA,{name:"آوریل",shortName:"آور"}),r)},{length:31,locals:(s={},h(s,e.locals.EN,{name:"May",shortName:"May"}),h(s,e.locals.FA,{name:"مه",shortName:"مه"}),s)},{length:30,locals:(i={},h(i,e.locals.EN,{name:"June",shortName:"June"}),h(i,e.locals.FA,{name:"ژوئن",shortName:"ژوئن"}),i)},{length:31,locals:(l={},h(l,e.locals.EN,{name:"July",shortName:"July"}),h(l,e.locals.FA,{name:"ژوئیه",shortName:"ژوئیه"}),l)},{length:31,locals:(I={},h(I,e.locals.EN,{name:"August",shortName:"Aug"}),h(I,e.locals.FA,{name:"اوت",shortName:"اوت"}),I)},{length:30,locals:(j={},h(j,e.locals.EN,{name:"September",shortName:"Sept"}),h(j,e.locals.FA,{name:"سپتامبر",shortName:"سپ"}),j)},{length:31,locals:(G={},h(G,e.locals.EN,{name:"October",shortName:"Oct"}),h(G,e.locals.FA,{name:"اکتبر",shortName:"اک"}),G)},{length:30,locals:(P={},h(P,e.locals.EN,{name:"November",shortName:"Nov"}),h(P,e.locals.FA,{name:"نوامبر",shortName:"نو"}),P)},{length:31,locals:(R={},h(R,e.locals.EN,{name:"December",shortName:"Dec"}),h(R,e.locals.FA,{name:"دسامبر",shortName:"دس"}),R)}]),h(Q,e.calendars.PERSIAN,[{length:31,locals:(L={},h(L,e.locals.EN,{name:"Farvardin",shortName:"Far"}),h(L,e.locals.FA,{name:"فروردین",shortName:"فر"}),L)},{length:31,locals:(C={},h(C,e.locals.EN,{name:"Ordibehesht",shortName:"Ord"}),h(C,e.locals.FA,{name:"اردیبهشت",shortName:"ار"}),C)},{length:31,locals:(T={},h(T,e.locals.EN,{name:"Khordad",shortName:"Khor"}),h(T,e.locals.FA,{name:"خرداد",shortName:"خرد"}),T)},{length:31,locals:(H={},h(H,e.locals.EN,{name:"Tir",shortName:"Tir"}),h(H,e.locals.FA,{name:"تیر",shortName:"تیر"}),H)},{length:31,locals:(z={},h(z,e.locals.EN,{name:"Mordad",shortName:"Mor"}),h(z,e.locals.FA,{name:"مرداد",shortName:"مر"}),z)},{length:31,locals:(J={},h(J,e.locals.EN,{name:"Shahrivar",shortName:"Sha"}),h(J,e.locals.FA,{name:"شهریور",shortName:"شه"}),J)},{length:30,locals:(U={},h(U,e.locals.EN,{name:"Mehr",shortName:"Mehr"}),h(U,e.locals.FA,{name:"مهر",shortName:"مه"}),U)},{length:30,locals:(_={},h(_,e.locals.EN,{name:"Aban",shortName:"Aban"}),h(_,e.locals.FA,{name:"آبان",shortName:"آبا"}),_)},{length:30,locals:(B={},h(B,e.locals.EN,{name:"Azar",shortName:"Azar"}),h(B,e.locals.FA,{name:"آذر",shortName:"آذ"}),B)},{length:30,locals:(K={},h(K,e.locals.EN,{name:"Dey",shortName:"Dey"}),h(K,e.locals.FA,{name:"دی",shortName:"دی"}),K)},{length:30,locals:($={},h($,e.locals.EN,{name:"Bahman",shortName:"Bah"}),h($,e.locals.FA,{name:"بهمن",shortName:"بهم"}),$)},{length:void 0,locals:(q={},h(q,e.locals.EN,{name:"Esfand",shortName:"Esf"}),h(q,e.locals.FA,{name:"اسفند",shortName:"اسف"}),q)}]),Q)}),O.set(this,{writable:!0,value:(ce={},h(ce,e.calendars.GEORGIAN,[{index:0,locals:(V={},h(V,e.locals.EN,{name:"Sunday",shortName:"Sun"}),h(V,e.locals.FA,{name:"یکشنبه",shortName:"یک"}),V)},{index:1,locals:(X={},h(X,e.locals.EN,{name:"Monday",shortName:"Mon"}),h(X,e.locals.FA,{name:"دوشنبه",shortName:"دو"}),X)},{index:2,locals:(Z={},h(Z,e.locals.EN,{name:"Tuesday",shortName:"Tue"}),h(Z,e.locals.FA,{name:"سه شنبه",shortName:"سه"}),Z)},{index:3,locals:(ee={},h(ee,e.locals.EN,{name:"Wednesday",shortName:"Wed"}),h(ee,e.locals.FA,{name:"چهارشنبه",shortName:"چهار"}),ee)},{index:4,locals:(te={},h(te,e.locals.EN,{name:"Thursday",shortName:"Thu"}),h(te,e.locals.FA,{name:"پنجشنبه",shortName:"پنج"}),te)},{index:5,locals:(ne={},h(ne,e.locals.EN,{name:"Friday",shortName:"Fri"}),h(ne,e.locals.FA,{name:"جمعه",shortName:"جم"}),ne)},{index:6,locals:(ae={},h(ae,e.locals.EN,{name:"Saturday",shortName:"Sat"}),h(ae,e.locals.FA,{name:"شنبه",shortName:"شن"}),ae)}]),h(ce,e.calendars.PERSIAN,[{index:5,locals:(re={},h(re,e.locals.EN,{name:"Panjshanbeh",shortName:"Pa"}),h(re,e.locals.FA,{name:"پنجشنبه",shortName:"پنج"}),re)},{index:6,locals:(se={},h(se,e.locals.EN,{name:"Jomeh",shortName:"Jo"}),h(se,e.locals.FA,{name:"جمعه",shortName:"جم"}),se)},{index:0,locals:(ie={},h(ie,e.locals.EN,{name:"Shanbeh",shortName:"Sh"}),h(ie,e.locals.FA,{name:"شنبه",shortName:"شن"}),ie)},{index:1,locals:(oe={},h(oe,e.locals.EN,{name:"YekShanbeh",shortName:"Ye"}),h(oe,e.locals.FA,{name:"یکشنبه",shortName:"یک"}),oe)},{index:2,locals:(le={},h(le,e.locals.EN,{name:"Doshanbeh",shortName:"Do"}),h(le,e.locals.FA,{name:"دوشنبه",shortName:"دو"}),le)},{index:3,locals:(he={},h(he,e.locals.EN,{name:"Seshanbeh",shortName:"Se"}),h(he,e.locals.FA,{name:"سه شنبه",shortName:"سه"}),he)},{index:4,locals:(ue={},h(ue,e.locals.EN,{name:"Chaharshanbeh",shortName:"Ch"}),h(ue,e.locals.FA,{name:"چهارشنبه",shortName:"چهار"}),ue)}]),ce)}),S.set(this,{writable:!0,value:(me={},h(me,e.locals.EN,["0","1","2","3","4","5","6","7","8","9"]),h(me,e.locals.FA,["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"]),me)}),F.set(this,{writable:!0,value:(fe={},h(fe,e.locals.EN,[{name:"AM",shortName:"am"},{name:"PM",shortName:"pm"}]),h(fe,e.locals.FA,[{name:"قبل از ظهر",shortName:"ق.ظ"},{name:"بعد از ظهر",shortName:"ب.ظ"}]),fe)}),D.set(this,{writable:!0,value:(de={},h(de,e.calendars.PERSIAN,h({},e.calendars.GEORGIAN,226895)),h(de,e.calendars.GEORGIAN,h({},e.calendars.PERSIAN,-226895)),de)}),x.set(this,{writable:!0,value:function(){var e=function(){for(var e=!1;u(Ne,f)<1;)c(Ne,f,u(Ne,f)+12),c(Ne,m,u(Ne,m)-1),0===u(Ne,m)&&c(Ne,m,-1),e=!0;for(;u(Ne,f)>11;)c(Ne,f,u(Ne,f)-12),c(Ne,m,u(Ne,m)+1),0===u(Ne,m)&&c(Ne,m,1),e=!0;e&&u(Ne,Y).call(Ne)};if(!(Number.isNaN(Number(u(Ne,m)))||Number.isNaN(Number(u(Ne,f)))||Number.isNaN(Number(u(Ne,d))))){for(;u(Ne,p)>=1e3;)c(Ne,p,u(Ne,p)-1e3),c(Ne,b,u(Ne,b)+1);for(;u(Ne,p)<0;)c(Ne,p,u(Ne,p)+1e3),c(Ne,b,u(Ne,b)-1);for(;u(Ne,b)>=60;)c(Ne,b,u(Ne,b)-60),c(Ne,y,u(Ne,y)+1);for(;u(Ne,b)<0;)c(Ne,b,u(Ne,b)+60),c(Ne,y,u(Ne,y)-1);for(;u(Ne,y)>=60;)c(Ne,y,u(Ne,y)-60),c(Ne,N,u(Ne,N)+1);for(;u(Ne,y)<0;)c(Ne,y,u(Ne,y)+60),c(Ne,N,u(Ne,N)-1);for(;u(Ne,N)>=24;)c(Ne,N,u(Ne,N)-24),c(Ne,d,u(Ne,d)+1);for(;u(Ne,N)<0;)c(Ne,N,u(Ne,N)+24),c(Ne,d,u(Ne,d)-1);for(;;){for((u(Ne,f)<1||u(Ne,f)>11)&&e();u(Ne,d)<1;)c(Ne,f,u(Ne,f)-1),e(),c(Ne,d,Ne.month.length+u(Ne,d));if(u(Ne,d)<=Ne.month.length)break;c(Ne,d,u(Ne,d)-Ne.month.length),c(Ne,f,1+ +u(Ne,f))}u(Ne,N)||c(Ne,N,0),u(Ne,y)||c(Ne,y,0),u(Ne,b)||c(Ne,b,0),u(Ne,p)||c(Ne,p,0)}}}),Y.set(this,{writable:!0,value:function(){if(0!==u(Ne,m)){var t=u(Ne,m)>0?1:-1,n=function(){return u(Ne,m)>0?t<=u(Ne,m):u(Ne,m)<=t},a=function(){return u(Ne,m)>0?t++:t--};switch(c(Ne,A,[]),u(Ne,w)){case e.calendars.PERSIAN:for(var r=.2684,s={5:4,38:37,199:198,232:231,265:264,298:297,557:558,590:591,623:624,982:983,1015:1016,1048:1049,1081:1082,1114:1115,1242:1243,1374:1375,1407:1408,1440:1441,1506:1507,1539:1540,1572:1573,1605:1606,1931:1932,1964:1965,2063:2064,2096:2097,2687:2686,2720:2719,2753:2752,2819:2818,2852:2851,2885:2884,3017:3016,3112:3111,3145:3144,3178:3177,3211:3210,3244:3243,3277:3276,3310:3309,3343:3342,3376:3375,3409:3408,3442:3441,3508:3507,3541:3540,3574:3573,3603:3602,3607:3606,3636:3635,3669:3668,3702:3701,3706:3705,3735:3734,3768:3767,3801:3800,3834:3833,3867:3866,3900:3899,3933:3932,3966:3965,3999:3998,4065:4064,4094:4093,4098:4097,4127:4126,4131:4130,4160:4159,4193:4192,4226:4225,4259:4258,4292:4291,4325:4324,4358:4357,4391:4390,4585:4584,4618:4617,4651:4650,4750:4749,4943:4944,4976:4977,5009:5010,5170:5171,5203:5204,5236:5237,5265:5266,5269:5270,5298:5299,5302:5303,5331:5332,5335:5336,5364:5365,5368:5369,5393:5394,5397:5398,5401:5402,5426:5427,5430:5431,5434:5435,5459:5460,5463:5464,5467:5468,5492:5493,5496:5497,5500:5501,5521:5522,5525:5526,5529:5530,5554:5555,5558:5559,5562:5563,5587:5588,5591:5592,5595:5596,5616:5617,5620:5621,5624:5625,5628:5629,5649:5650,5653:5654,5657:5658,5661:5662,5682:5683,5686:5687,5690:5691,5694:5695,5715:5716,5719:5720,5723:5724,5727:5728,5744:5745,5748:5749,5752:5753,5756:5757,5760:5761,5777:5778,5781:5782,5785:5786,5789:5790,5793:5794,5810:5811,5814:5815,5818:5819,5822:5823,5826:5827,5839:5840,5843:5844,5847:5848,5851:5852,5855:5856,5859:5860,5872:5873,5876:5877,5880:5881,5884:5885,5888:5889,5892:5893,5901:5902,5905:5906,5909:5910,5913:5914,5917:5918,5921:5922,5925:5926,5934:5935,5938:5939,5942:5943,5946:5947,5950:5951,5954:5955,5958:5959,5967:5968,5971:5972,5975:5976,5979:5980,5983:5984,5987:5988,5991:5992,5996:5997,6e3:6001,6004:6005,6008:6009,6012:6013,6016:6017,6020:6021,6029:6030,6033:6034,6037:6038,6041:6042,6045:6046,6049:6050,6053:6054,6058:6059,6062:6063,6066:6067,6070:6071,6074:6075,6078:6079,6082:6083,6086:6087,6091:6092,6095:6096,6099:6100,6103:6104,6107:6108,6111:6112,6115:6116,6119:6120,6124:6125,6128:6129,6132:6133,6136:6137,6140:6141,6144:6145,6148:6149,6152:6154,6157:6158,6161:6162,6165:6166,6169:6170,6173:6174,6177:6178,6181:6182,6185:6187,6190:6191,6194:6195,6198:6199,6202:6203,6206:6207,6210:6211,6214:6215,6218:6220,6223:6224,6227:6228,6231:6232,6235:6236,6239:6240,6243:6244,6247:6249,6251:6253,6256:6257,6260:6261,6264:6265,6268:6269,6272:6273,6276:6277,6280:6282,6284:6286,6289:6290,6293:6294,6297:6298,6301:6302,6305:6306,6309:6310,6313:6315,6317:6319,6322:6323,6326:6327,6330:6331,6334:6335,6338:6339,6342:6344,6346:6348,6350:6352,6355:6356,6359:6360,6363:6364,6367:6368,6371:6372,6375:6377,6379:6381,6383:6385,6388:6389,6392:6393,6396:6397,6400:6401,6404:6406,6408:6410,6412:6414,6416:6418,6421:6422,6425:6426,6429:6430,6433:6434,6437:6439,6441:6443,6445:6447,6449:6451,6454:6455,6458:6459,6462:6463,6466:6468,6470:6472,6474:6476,6478:6480,6482:6484,6487:6488,6491:6492,6495:6496};n();){if((r+=u(Ne,m)>0?.242362:-.242362)>1&&(r-=1),r<0&&(r+=1),r>=.257800926&&r<=.5){var i=s[t]||t;u(Ne,m)>0&&i<=u(Ne,m)&&u(Ne,A).push(i),u(Ne,m)<0&&u(Ne,A).push(i)}a()}break;default:for(;n();)(t%4==0&&t%100!=0||t%400==0)&&u(Ne,A).push(t),a()}}}}),W.set(this,{writable:!0,value:function(e){if(!Number.isNaN(Number(e)))return Number(e)}}),(ye instanceof Date||ye instanceof e||"string"==typeof ye)&&(ye={date:ye}),"number"==typeof ye&&(ye={date:new Date(1e3*ye)});var be=ye,pe=be.calendar,ve=be.local,ge=be.format,we=be.date,Ae=be.year,ke=be.month,Ee=be.day,Me=be.hour,Oe=be.minute,Se=be.second,Fe=be.millisecond,De=!0;if(pe&&c(this,w,e.calendars[pe.toUpperCase()]),!u(this,w))throw new Error("calendar not found");ve&&c(this,g,e.locals[ve.toUpperCase()]||e.locals.EN),!pe||we||Ae||ke||Ee||Me||Oe||Se||Fe||(we=new Date),c(this,v,ge),"string"==typeof we&&this.parse(we),"number"==typeof we&&(we=new Date(1e3*we));var xe=function(){0===ke&&(ke=1),c(Ne,m,Ae),c(Ne,f,ke-1),c(Ne,d,Ee),c(Ne,N,Me),c(Ne,y,Oe),c(Ne,b,Se),c(Ne,p,Fe)};if(we instanceof e&&(c(this,m,we.year),c(this,f,we.month.index),c(this,d,we.day),c(this,N,we.hour),c(this,y,we.minute),c(this,b,we.second),c(this,p,we.millisecond),c(this,w,we.calendar.toUpperCase()),c(this,g,we.local.toUpperCase()),c(this,v,we._format),c(this,A,we.leaps),De=!1),we instanceof Date){if(Ae=we.getFullYear(),ke=we.getMonth()+1,Ee=we.getDate(),Me=we.getHours(),Oe=we.getMinutes(),Se=we.getSeconds(),Fe=we.getMilliseconds(),u(this,w)!==e.calendars.GEORGIAN){var Ye=new e({year:Ae,month:ke,day:Ee,hour:Me,minute:Oe,second:Se}).convert(u(this,w));Ae=Ye.year,ke=Ye.month.number,Ee=Ye.day,Me=Ye.hour,Oe=Ye.minute,Se=Ye.second,Fe=Ye.millisecond}xe()}we||xe(),0===u(this,m)&&c(this,m,-1),De&&(u(this,Y).call(this),u(this,x).call(this))}var t,n,i;return t=e,(n=[{key:"parse",value:function(t){if(t){var n=u(this,v);if(u(this,g)!==e.locals.en){var a,i=u(this,S)[u(this,g)],o=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=s(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){l=!0,i=e},f:function(){try{o||null==n.return||n.return()}finally{if(l)throw i}}}}(i);try{for(o.s();!(a=o.n()).done;){var l=a.value;t=t.replace(new RegExp(l,"g"),i.indexOf(l))}}catch(e){o.e(e)}finally{o.f()}}if(n)for(var h=n.split(/[^\w\u0600-\u06FF]/),w=t.split(/[^\w\u0600-\u06FF]/),A=0;A<h.length;A++){var k=u(this,E)[h[A]];k&&w[A]&&k(w[A])}else{var M=r(t.match(/(-?\d{2,4})?\W?([A-z]{3,9}|\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,3})?\W?(am|pm)?/),9),O=M[1],D=M[2],x=M[3],Y=M[4],W=M[5],I=M[6],j=M[7],G=M[8];D&&(D=/\d+/.test(D)?Number(D)-1:this.months.findIndex((function(e){return new RegExp(D,"i").test(e.name)}))),c(this,m,Number(O)),c(this,f,Number(D)),c(this,d,Number(x)),c(this,N,Number(Y)),c(this,y,Number(W)),c(this,b,Number(I)),c(this,p,Number(j)),G&&"pm"===G&&u(this,N)<12&&c(this,N,u(this,N)+12)}t.includes(u(this,F)[u(this,g)][1].shortName)&&u(this,N)<12&&c(this,N,u(this,N)+12),t.includes(u(this,F)[u(this,g)][1].name)&&u(this,N)<12&&c(this,N,u(this,N)+12)}}},{key:"convert",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.calendars.GEORGIAN;if(!(n=e.calendars[n.toUpperCase()]))throw new Error("calendar not found");if(n===u(this,w))return this;var a=function(){var a=0;switch(u(t,w)+"->"+n){case"PERSIAN->GEORGIAN":case"GEORGIAN->PERSIAN":a=u(t,f)<10||10===u(t,f)&&u(t,d)<=(t.isLeap?11:10)?n===e.calendars.GEORGIAN?621:-621:n===e.calendars.GEORGIAN?622:-622;break;default:a=0}return a},r=u(this,m),s=this.dayOfBeginning,i=void 0,o=void 0;return s+=u(this,D)[u(this,w)][n],r=1+~~((s-=(o=new e({calendar:n,year:r+a(),month:1,day:1})).isLeap?o.leaps.length-1:o.leaps.length)/365),s%=365,i=0,c(this,m,r),c(this,f,i),c(this,d,~~s),c(this,w,n),u(this,Y).call(this),u(this,x).call(this),this}},{key:"format",value:function(t){if(!t||"string"==typeof t){t||(t=u(this,v)||"YYYY/MM/DD");var n=100,a={};for(var r in u(this,k))for(;t.includes(r);)t=t.replace(r,n),a[n]=this.getProperty(r),n++;for(var s in a)t=t.replace(s,a[s]);if(u(this,g)!==e.locals.en){var i=u(this,S)[u(this,g)];t=t.replace(/[0-9]/g,(function(e){return i[e]}))}return t}}},{key:"getProperty",value:function(e){var t=function(e){return e<10?"0"+e:e};switch(e){case"YYYY":return this.year;case"YY":return this.year.toString().substring(2,4);case"MMMM":return this.month.name;case"MMM":return this.month.shortName;case"MM":return t(this.month.number);case"M":return this.month.number;case"DDDD":case"DDD":return this.dayOfYear;case"DD":return t(this.day);case"D":return this.day;case"HH":return t(this.hour);case"H":return this.hour;case"dddd":return this.weekDay.name;case"ddd":return this.weekDay.shortName;case"hh":return t(this.hour>12?this.hour-12:this.hour);case"h":return this.hour>12?this.hour-12:this.hour;case"mm":return t(this.minute);case"m":return this.minute;case"ss":return t(this.second);case"s":return this.second;case"SSS":return u(this,p);case"SS":return u(this,p).toString().substring(0,2);case"S":return u(this,p).toString().substring(0,1);case"a":return this.hour>=12?u(this,F)[u(this,g)][1].shortName:u(this,F)[u(this,g)][0].shortName;case"A":return this.hour>=12?u(this,F)[u(this,g)][1].name:u(this,F)[u(this,g)][0].name;default:return""}}},{key:"setYear",value:function(e){return this.year=e,this}},{key:"setMonth",value:function(e){return this.month=e,this}},{key:"setDay",value:function(e){return this.day=e,this}},{key:"setHour",value:function(e){return this.hour=e,this}},{key:"setMinute",value:function(e){return this.minute=e,this}},{key:"setSecond",value:function(e){return this.second=e,this}},{key:"setMillisecond",value:function(e){return this.millisecond=e,this}},{key:"setFormat",value:function(e){return c(this,v,e),this}},{key:"setLocal",value:function(e){return this.local=e,this}},{key:"setCalendar",value:function(e){return this.calendar=e,this}},{key:"toFirstOfYear",value:function(){return this.month=1,this.day=1,this}},{key:"toLastOfYear",value:function(){return this.day>=29&&(this.day=29),this.month=12,this.toLastOfMonth(),this}},{key:"toFirstOfMonth",value:function(){return c(this,d,1),this}},{key:"toLastOfMonth",value:function(){return c(this,d,0),c(this,f,u(this,f)+1),u(this,x).call(this),this}},{key:"toFirstOfWeek",value:function(){return this.day-=this.weekDay.index,this}},{key:"toLastOfWeek",value:function(){return this.day+=6-this.weekDay.index,this}},{key:"toFirstWeekOfYear",value:function(){return this.toFirstOfYear(),0===this.weekDay.index?this:this.toLastOfWeek().setDay(this.day+1)}},{key:"toLastWeekOfYear",value:function(){return this.toLastOfYear().toFirstOfWeek()}},{key:"toString",value:function(){return this.format()}},{key:"toDate",value:function(){return u(this,w)!==e.calendars.GEORGIAN&&this.convert(e.calendars.GEORGIAN),new Date(u(this,m),u(this,f),u(this,d),u(this,N),u(this,y),u(this,b),u(this,p))}},{key:"toUnix",value:function(){return this.unix}},{key:"dayOfBeginning",get:function(){var e=365*(u(this,m)>0?u(this,m)-1:u(this,m)),t=this.isLeap?this.leaps.length-1:this.leaps.length;return u(this,m)>0&&(e+=t),u(this,m)<0&&(e-=t),e+=this.dayOfYear}},{key:"dayOfYear",get:function(){for(var e=u(this,d),t=this.months,n=0;n<t.length&&!(n>=u(this,f));n++)e+=t[n].length;return e}},{key:"weekOfYear",get:function(){return 1+~~(this.dayOfYear/7)}},{key:"daysLeft",get:function(){return(this.isLeap?366:365)-this.dayOfYear}},{key:"year",get:function(){return u(this,m)},set:function(e){(e=u(this,W).call(this,e))&&(c(this,m,e),u(this,Y).call(this),u(this,x).call(this))}},{key:"month",get:function(){var e=this.months[u(this,f)];return e?(e.index=u(this,f),e.number=e.index+1,e.toString=function(){return this.number},e):[]},set:function(e){(e=u(this,W).call(this,e))&&(c(this,f,e-1),u(this,x).call(this))}},{key:"day",get:function(){return u(this,d)},set:function(e){(e=u(this,W).call(this,e))&&(c(this,d,e),u(this,x).call(this))}},{key:"weekDay",get:function(){var e=this.dayOfBeginning%7;e<0&&(e+=7);var t=u(this,O)[u(this,w)][e];return t?t=a({index:t.index,number:t.index+1,toString:function(){return this.number}},t.locals[u(this,g)]):{}}},{key:"hour",get:function(){return u(this,N)},set:function(e){(e=u(this,W).call(this,e))&&(c(this,N,e),u(this,x).call(this))}},{key:"minute",get:function(){return u(this,y)},set:function(e){(e=u(this,W).call(this,e))&&(c(this,y,e),u(this,x).call(this))}},{key:"second",get:function(){return u(this,b)},set:function(e){(e=u(this,W).call(this,e))&&(c(this,b,e),u(this,x).call(this))}},{key:"millisecond",get:function(){return u(this,p)},set:function(e){(e=u(this,W).call(this,e))&&(c(this,p,e),u(this,x).call(this))}},{key:"months",get:function(){var t=this,n=u(this,M)[u(this,w)];switch(u(this,w)){case e.calendars.PERSIAN:n[11].length=this.isLeap?30:29;break;default:n[1].length=this.isLeap?29:28}return n=n.map((function(e){return a({length:e.length},e.locals[u(t,g)])}))}},{key:"weeks",get:function(){var e=this,t=u(this,O)[u(this,w)];return t.sort((function(e,t){return e.index-t.index})),t=t.map((function(t){return a({index:t.index,number:t.index+1},t.locals[u(e,g)])}))}},{key:"leaps",get:function(){return u(this,A)}},{key:"calendar",get:function(){return u(this,w).toLowerCase()},set:function(e){this.convert(e)}},{key:"local",get:function(){return u(this,g).toLowerCase()},set:function(t){t=t.toUpperCase(),e.locals[t]||(t=e.locals.EN),c(this,g,t)}},{key:"meridiems",get:function(){return u(this,F)[u(this,g)]}},{key:"digits",get:function(){return u(this,S)[u(this,g)]}},{key:"_format",get:function(){return u(this,v)},set:function(e){"string"==typeof e&&c(this,v,e)}},{key:"isLeap",get:function(){return u(this,A).includes(u(this,m))}},{key:"unix",get:function(){return Math.round(this.toDate().getTime()/1e3)}}])&&l(t.prototype,n),i&&l(t,i),e}();h(I,"calendars",{GEORGIAN:"GEORGIAN",PERSIAN:"PERSIAN"}),h(I,"locals",{EN:"EN",FA:"FA"}),e.exports=I},function(e,t,n){e.exports=n(2)},function(e,t,n){"use strict";n.r(t);var a=n(0),r=n.n(a);t.default=r.a}])})); |
1079
index.js
@@ -1,1080 +0,3 @@ | ||
class DateObject { | ||
#year | ||
#month | ||
#day | ||
#hour | ||
#minute | ||
#second | ||
#millisecond | ||
#format | ||
#local = DateObject.locals.EN | ||
#calendar = DateObject.calendars.GEORGIAN | ||
#leaps = [] | ||
#types = { | ||
YYYY: /\d{4}/, | ||
YY: /\d\d/, | ||
MMMM: /[A-z]+/, //month name | ||
MMM: /[A-z]+/, //month shortName | ||
MM: /\d\d/, | ||
M: /\d/, | ||
DDDD: /\d{1,3}/, | ||
DDD: /\d{1,3}/, | ||
DD: /\d\d/, | ||
D: /\d/, | ||
dddd: /[A-z]+/, //weekDay name | ||
ddd: /[A-z]+/, //weekDay shortName | ||
HH: /\d\d/, | ||
H: /\d/, | ||
hh: /\d\d/, | ||
h: /\d/, | ||
mm: /\d\d/, | ||
m: /\d/, | ||
ss: /\d\d/, | ||
s: /\d/, | ||
SSS: /\d{3}/, | ||
SS: /\d\d/, | ||
S: /\d/, | ||
a: /[a-z]{2,9}/, | ||
A: /[a-z]{2,9}/ | ||
} | ||
import DateObject from "date-object" | ||
#reverse = { | ||
"YYYY": string => this.#year = Number(string), | ||
"YY": string => this.#year = Number(string), | ||
"MMMM": string => this.#month = this.months.findIndex(month => string.toLowerCase() === month.name.toLowerCase()), | ||
"MMM": string => this.#month = this.months.findIndex(month => string.toLowerCase() === month.shortName.toLowerCase()), | ||
"MM": string => this.#month = Number(string) - 1, | ||
"M": string => this.#month = Number(string) - 1, | ||
"DD": string => this.#day = Number(string), | ||
"D": string => this.#day = Number(string), | ||
"HH": string => this.#hour = Number(string), | ||
"H": string => this.#hour = Number(string), | ||
"hh": string => { | ||
let hour = Number(string) | ||
this.#hour = hour > 12 ? hour - 12 : hour | ||
}, | ||
"h": string => { | ||
let hour = Number(string) | ||
this.#hour = hour > 12 ? hour - 12 : hour | ||
}, | ||
"mm": string => this.#minute = Number(string), | ||
"m": string => this.#minute = Number(string), | ||
"ss": string => this.#second = Number(string), | ||
"s": string => this.#second = Number(string), | ||
"SSS": string => this.millisecond = Number(string), | ||
"SS": string => this.millisecond = Number(string), | ||
"S": string => this.millisecond = Number(string), | ||
} | ||
static calendars = { | ||
GEORGIAN: "GEORGIAN", | ||
PERSIAN: "PERSIAN" | ||
} | ||
static locals = { | ||
EN: "EN", | ||
FA: "FA" | ||
} | ||
#months = { | ||
[DateObject.calendars.GEORGIAN]: [ | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "January", shortName: "Jan" }, | ||
[DateObject.locals.FA]: { name: "ژانویه", shortName: "ژان" } | ||
} | ||
}, | ||
{ | ||
length: undefined, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "February", shortName: "Feb" }, | ||
[DateObject.locals.FA]: { name: "فوریه", shortName: "فور" } | ||
} | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "March", shortName: "Mar" }, | ||
[DateObject.locals.FA]: { name: "مارس", shortName: "ما" } | ||
} | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "April", shortName: "Apr" }, | ||
[DateObject.locals.FA]: { name: "آوریل", shortName: "آور" } | ||
} | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "May", shortName: "May" }, | ||
[DateObject.locals.FA]: { name: "مه", shortName: "مه" } | ||
} | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "June", shortName: "June" }, | ||
[DateObject.locals.FA]: { name: "ژوئن", shortName: "ژوئن" } | ||
} | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "July", shortName: "July" }, | ||
[DateObject.locals.FA]: { name: "ژوئیه", shortName: "ژوئیه" } | ||
} | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "August", shortName: "Aug" }, | ||
[DateObject.locals.FA]: { name: "اوت", shortName: "اوت" } | ||
} | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "September", shortName: "Sept" }, | ||
[DateObject.locals.FA]: { name: "سپتامبر", shortName: "سپ" } | ||
} | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "October", shortName: "Oct" }, | ||
[DateObject.locals.FA]: { name: "اکتبر", shortName: "اک" } | ||
} | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "November", shortName: "Nov" }, | ||
[DateObject.locals.FA]: { name: "نوامبر", shortName: "نو" } | ||
} | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "December", shortName: "Dec" }, | ||
[DateObject.locals.FA]: { name: "دسامبر", shortName: "دس" } | ||
} | ||
} | ||
], | ||
[DateObject.calendars.PERSIAN]: [ | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Farvardin", shortName: "Far" }, | ||
[DateObject.locals.FA]: { name: "فروردین", shortName: "فر" } | ||
}, | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Ordibehesht", shortName: "Ord" }, | ||
[DateObject.locals.FA]: { name: "اردیبهشت", shortName: "ار" } | ||
}, | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Khordad", shortName: "Khor" }, | ||
[DateObject.locals.FA]: { name: "خرداد", shortName: "خرد" } | ||
}, | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Tir", shortName: "Tir" }, | ||
[DateObject.locals.FA]: { name: "تیر", shortName: "تیر" } | ||
}, | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Mordad", shortName: "Mor" }, | ||
[DateObject.locals.FA]: { name: "مرداد", shortName: "مر" } | ||
}, | ||
}, | ||
{ | ||
length: 31, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Shahrivar", shortName: "Sha" }, | ||
[DateObject.locals.FA]: { name: "شهریور", shortName: "شه" } | ||
}, | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Mehr", shortName: "Mehr" }, | ||
[DateObject.locals.FA]: { name: "مهر", shortName: "مه" } | ||
}, | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Aban", shortName: "Aban" }, | ||
[DateObject.locals.FA]: { name: "آبان", shortName: "آبا" } | ||
}, | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Azar", shortName: "Azar" }, | ||
[DateObject.locals.FA]: { name: "آذر", shortName: "آذ" } | ||
}, | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Dey", shortName: "Dey" }, | ||
[DateObject.locals.FA]: { name: "دی", shortName: "دی" } | ||
}, | ||
}, | ||
{ | ||
length: 30, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Bahman", shortName: "Bah" }, | ||
[DateObject.locals.FA]: { name: "بهمن", shortName: "بهم" } | ||
}, | ||
}, | ||
{ | ||
length: undefined, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Esfand", shortName: "Esf" }, | ||
[DateObject.locals.FA]: { name: "اسفند", shortName: "اسف" } | ||
}, | ||
} | ||
] | ||
} | ||
#weeks = { | ||
[DateObject.calendars.GEORGIAN]: [ | ||
{ | ||
index: 0, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Sunday", shortName: "Sun" }, | ||
[DateObject.locals.FA]: { name: "یکشنبه", shortName: "یک" } | ||
} | ||
}, | ||
{ | ||
index: 1, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Monday", shortName: "Mon" }, | ||
[DateObject.locals.FA]: { name: "دوشنبه", shortName: "دو" } | ||
} | ||
}, | ||
{ | ||
index: 2, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Tuesday", shortName: "Tue" }, | ||
[DateObject.locals.FA]: { name: "سه شنبه", shortName: "سه" } | ||
} | ||
}, | ||
{ | ||
index: 3, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Wednesday", shortName: "Wed" }, | ||
[DateObject.locals.FA]: { name: "چهارشنبه", shortName: "چهار" } | ||
} | ||
}, | ||
{ | ||
index: 4, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Thursday", shortName: "Thu" }, | ||
[DateObject.locals.FA]: { name: "پنجشنبه", shortName: "پنج" } | ||
} | ||
}, | ||
{ | ||
index: 5, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Friday", shortName: "Fri" }, | ||
[DateObject.locals.FA]: { name: "جمعه", shortName: "جم" } | ||
} | ||
}, | ||
{ | ||
index: 6, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Saturday", shortName: "Sat" }, | ||
[DateObject.locals.FA]: { name: "شنبه", shortName: "شن" } | ||
} | ||
} | ||
], | ||
[DateObject.calendars.PERSIAN]: [ | ||
{ | ||
index: 5, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Panjshanbeh", shortName: "Pa" }, | ||
[DateObject.locals.FA]: { name: "پنجشنبه", shortName: "پنج" } | ||
} | ||
}, | ||
{ | ||
index: 6, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Jomeh", shortName: "Jo" }, | ||
[DateObject.locals.FA]: { name: "جمعه", shortName: "جم" } | ||
} | ||
}, | ||
{ | ||
index: 0, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Shanbeh", shortName: "Sh" }, | ||
[DateObject.locals.FA]: { name: "شنبه", shortName: "شن" } | ||
} | ||
}, | ||
{ | ||
index: 1, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "YekShanbeh", shortName: "Ye" }, | ||
[DateObject.locals.FA]: { name: "یکشنبه", shortName: "یک" } | ||
} | ||
}, | ||
{ | ||
index: 2, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Doshanbeh", shortName: "Do" }, | ||
[DateObject.locals.FA]: { name: "دوشنبه", shortName: "دو" } | ||
} | ||
}, | ||
{ | ||
index: 3, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Seshanbeh", shortName: "Se" }, | ||
[DateObject.locals.FA]: { name: "سه شنبه", shortName: "سه" } | ||
} | ||
}, | ||
{ | ||
index: 4, | ||
locals: { | ||
[DateObject.locals.EN]: { name: "Chaharshanbeh", shortName: "Ch" }, | ||
[DateObject.locals.FA]: { name: "چهارشنبه", shortName: "چهار" } | ||
} | ||
}, | ||
], | ||
} | ||
#digits = { | ||
[DateObject.locals.EN]: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], | ||
[DateObject.locals.FA]: ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"] | ||
} | ||
#meridiems = { | ||
[DateObject.locals.EN]: [{ name: "AM", shortName: "am" }, { name: "PM", shortName: "pm" }], | ||
[DateObject.locals.FA]: [{ name: "قبل از ظهر", shortName: "ق.ظ" }, { name: "بعد از ظهر", shortName: "ب.ظ" }] | ||
} | ||
#epoch = { | ||
[DateObject.calendars.PERSIAN]: { | ||
[DateObject.calendars.GEORGIAN]: 226895 | ||
}, | ||
[DateObject.calendars.GEORGIAN]: { | ||
[DateObject.calendars.PERSIAN]: -226895 | ||
} | ||
} | ||
constructor(object = { date: new Date() }) { | ||
if (object instanceof Date || object instanceof DateObject || typeof object === "string") object = { date: object } | ||
let { calendar, local, format, date, year, month, day, hour, minute, second, millisecond } = object | ||
let mustGetLeaps = true | ||
if (calendar) this.#calendar = DateObject.calendars[calendar.toUpperCase()] | ||
if (!this.#calendar) throw new Error("calendar not found") | ||
if (local) this.#local = DateObject.locals[local.toUpperCase()] || DateObject.locals.EN | ||
if (calendar && !date && !year && !month && !day && !hour && !minute && !second && !millisecond) date = new Date() | ||
this.#format = format | ||
if (typeof date === "string") this.parse(date) | ||
const setDate = () => { | ||
if (month === 0) month = 1 | ||
this.#year = year | ||
this.#month = month - 1 | ||
this.#day = day | ||
this.#hour = hour | ||
this.#minute = minute | ||
this.#second = second | ||
this.#millisecond = millisecond | ||
} | ||
if (date instanceof DateObject) { | ||
this.#year = date.year | ||
this.#month = date.month.index | ||
this.#day = date.day | ||
this.#hour = date.hour | ||
this.#minute = date.minute | ||
this.#second = date.second | ||
this.#millisecond = date.millisecond | ||
this.#calendar = date.calendar.toUpperCase() | ||
this.#local = date.local.toUpperCase() | ||
this.#format = date._format | ||
this.#leaps = date.leaps | ||
mustGetLeaps = false | ||
} | ||
if (date instanceof Date) { | ||
year = date.getFullYear() | ||
month = date.getMonth() + 1 | ||
day = date.getDate() | ||
hour = date.getHours() | ||
minute = date.getMinutes() | ||
second = date.getSeconds() | ||
millisecond = date.getMilliseconds() | ||
if (this.#calendar !== DateObject.calendars.GEORGIAN) { | ||
let dateObject = new DateObject({ year, month, day, hour, minute, second }).convert(this.#calendar) | ||
year = dateObject.year | ||
month = dateObject.month.number | ||
day = dateObject.day | ||
hour = dateObject.hour | ||
minute = dateObject.minute | ||
second = dateObject.second | ||
millisecond = dateObject.millisecond | ||
} | ||
setDate() | ||
} | ||
if (!date) setDate() | ||
if (this.#year === 0) this.#year = -1 | ||
if (mustGetLeaps) { | ||
this.#getLeaps() | ||
this.#fix() | ||
} | ||
} | ||
parse(string) { | ||
if (!string) return | ||
let format = this.#format | ||
if (this.#local !== DateObject.locals.en) { | ||
let digits = this.#digits[this.#local] | ||
for (let digit of digits) { | ||
string = string.replace(new RegExp(digit, "g"), digits.indexOf(digit)) | ||
} | ||
} | ||
if (!format) { | ||
const regex = /(-?\d{2,4})?\W?([A-z]{3,9}|\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,2})?\W?(\d{1,3})?\W?(am|pm)?/ | ||
let [, year, month, day, hour, minute, second, millisecond, a] = string.match(regex) | ||
if (month) { | ||
if (/\d+/.test(month)) { | ||
month = Number(month) - 1 | ||
} else { | ||
month = this.months.findIndex($month => new RegExp(month, "i").test($month.name)) | ||
} | ||
} | ||
this.#year = year ? Number(year) : 0 | ||
this.#month = month || 0 | ||
this.#day = Number(day || 1) | ||
this.#hour = Number(hour || 0) | ||
this.#minute = Number(minute || 0) | ||
this.#second = Number(second || 0) | ||
this.#millisecond = Number(millisecond || 0) | ||
if (a && a === "pm" && this.#hour < 12) { | ||
this.#hour = this.#hour + 12 | ||
} | ||
} else { | ||
const formatArray = format.split(/[^\w\u0600-\u06FF]/) | ||
const stringArray = string.split(/[^\w\u0600-\u06FF]/) | ||
for (let i = 0; i < formatArray.length; i++) { | ||
let reverse = this.#reverse[formatArray[i]] | ||
if (reverse && stringArray[i]) reverse(stringArray[i]) | ||
} | ||
if (!this.#hour) this.#hour = 0 | ||
if (!this.#minute) this.#minute = 0 | ||
if (!this.#second) this.#second = 0 | ||
if (!this.#millisecond) this.#millisecond = 0 | ||
} | ||
if (string.includes(this.#meridiems[this.#local][1].shortName) && this.#hour < 12) { | ||
this.#hour = this.#hour + 12 | ||
} | ||
if (string.includes(this.#meridiems[this.#local][1].name) && this.#hour < 12) { | ||
this.#hour = this.#hour + 12 | ||
} | ||
} | ||
#fix = () => { | ||
const setMonth = () => { | ||
let mustGetLeaps = false | ||
while (this.#month < 1) { | ||
this.#month += 12 | ||
this.#year -= 1 | ||
if (this.#year === 0) this.#year = -1 | ||
mustGetLeaps = true | ||
} | ||
while (this.#month > 11) { | ||
this.#month -= 12 | ||
this.#year += 1 | ||
if (this.#year === 0) this.#year = 1 | ||
mustGetLeaps = true | ||
} | ||
if (mustGetLeaps) this.#getLeaps() | ||
} | ||
if (Number.isNaN(Number(this.#year)) || Number.isNaN(Number(this.#month)) || Number.isNaN(Number(this.#day))) return | ||
while (this.#millisecond >= 1000) { | ||
this.#millisecond -= 1000 | ||
this.#second += 1 | ||
} | ||
while (this.#millisecond < 0) { | ||
this.#millisecond += 1000 | ||
this.#second -= 1 | ||
} | ||
while (this.#second >= 60) { | ||
this.#second -= 60 | ||
this.#minute += 1 | ||
} | ||
while (this.#second < 0) { | ||
this.#second += 60 | ||
this.#minute -= 1 | ||
} | ||
while (this.#minute >= 60) { | ||
this.#minute -= 60 | ||
this.#hour += 1 | ||
} | ||
while (this.#minute < 0) { | ||
this.#minute += 60 | ||
this.#hour -= 1 | ||
} | ||
while (this.#hour >= 24) { | ||
this.#hour -= 24 | ||
this.#day += 1 | ||
} | ||
while (this.#hour < 0) { | ||
this.#hour += 24 | ||
this.#day -= 1 | ||
} | ||
while (true) { | ||
if (this.#month < 1 || this.#month > 11) setMonth() | ||
while (this.#day < 1) { | ||
this.#month -= 1 | ||
setMonth() | ||
this.#day = this.month.length + this.#day | ||
} | ||
if (this.#day <= this.month.length) break | ||
this.#day -= this.month.length | ||
this.#month++ | ||
} | ||
} | ||
#getLeaps = () => { | ||
if (this.#year === 0) return | ||
let year = this.#year > 0 ? 1 : -1 | ||
let condition = () => this.#year > 0 ? year <= this.#year : this.#year <= year | ||
let increase = () => this.#year > 0 ? year++ : year-- | ||
this.#leaps = [] | ||
switch (this.#calendar) { | ||
case DateObject.calendars.PERSIAN: | ||
let delta = 0.242362 | ||
let offset = 0.2684 | ||
let correct = { 5: 4, 38: 37, 199: 198, 232: 231, 265: 264, 298: 297, 557: 558, 590: 591, 623: 624, 982: 983, 1015: 1016, 1048: 1049, 1081: 1082, 1114: 1115, 1242: 1243, 1374: 1375, 1407: 1408, 1440: 1441, 1506: 1507, 1539: 1540, 1572: 1573, 1605: 1606, 1931: 1932, 1964: 1965, 2063: 2064, 2096: 2097, 2687: 2686, 2720: 2719, 2753: 2752, 2819: 2818, 2852: 2851, 2885: 2884, 3017: 3016, 3112: 3111, 3145: 3144, 3178: 3177, 3211: 3210, 3244: 3243, 3277: 3276, 3310: 3309, 3343: 3342, 3376: 3375, 3409: 3408, 3442: 3441, 3508: 3507, 3541: 3540, 3574: 3573, 3603: 3602, 3607: 3606, 3636: 3635, 3669: 3668, 3702: 3701, 3706: 3705, 3735: 3734, 3768: 3767, 3801: 3800, 3834: 3833, 3867: 3866, 3900: 3899, 3933: 3932, 3966: 3965, 3999: 3998, 4065: 4064, 4094: 4093, 4098: 4097, 4127: 4126, 4131: 4130, 4160: 4159, 4193: 4192, 4226: 4225, 4259: 4258, 4292: 4291, 4325: 4324, 4358: 4357, 4391: 4390, 4585: 4584, 4618: 4617, 4651: 4650, 4750: 4749, 4943: 4944, 4976: 4977, 5009: 5010, 5170: 5171, 5203: 5204, 5236: 5237, 5265: 5266, 5269: 5270, 5298: 5299, 5302: 5303, 5331: 5332, 5335: 5336, 5364: 5365, 5368: 5369, 5393: 5394, 5397: 5398, 5401: 5402, 5426: 5427, 5430: 5431, 5434: 5435, 5459: 5460, 5463: 5464, 5467: 5468, 5492: 5493, 5496: 5497, 5500: 5501, 5521: 5522, 5525: 5526, 5529: 5530, 5554: 5555, 5558: 5559, 5562: 5563, 5587: 5588, 5591: 5592, 5595: 5596, 5616: 5617, 5620: 5621, 5624: 5625, 5628: 5629, 5649: 5650, 5653: 5654, 5657: 5658, 5661: 5662, 5682: 5683, 5686: 5687, 5690: 5691, 5694: 5695, 5715: 5716, 5719: 5720, 5723: 5724, 5727: 5728, 5744: 5745, 5748: 5749, 5752: 5753, 5756: 5757, 5760: 5761, 5777: 5778, 5781: 5782, 5785: 5786, 5789: 5790, 5793: 5794, 5810: 5811, 5814: 5815, 5818: 5819, 5822: 5823, 5826: 5827, 5839: 5840, 5843: 5844, 5847: 5848, 5851: 5852, 5855: 5856, 5859: 5860, 5872: 5873, 5876: 5877, 5880: 5881, 5884: 5885, 5888: 5889, 5892: 5893, 5901: 5902, 5905: 5906, 5909: 5910, 5913: 5914, 5917: 5918, 5921: 5922, 5925: 5926, 5934: 5935, 5938: 5939, 5942: 5943, 5946: 5947, 5950: 5951, 5954: 5955, 5958: 5959, 5967: 5968, 5971: 5972, 5975: 5976, 5979: 5980, 5983: 5984, 5987: 5988, 5991: 5992, 5996: 5997, 6000: 6001, 6004: 6005, 6008: 6009, 6012: 6013, 6016: 6017, 6020: 6021, 6029: 6030, 6033: 6034, 6037: 6038, 6041: 6042, 6045: 6046, 6049: 6050, 6053: 6054, 6058: 6059, 6062: 6063, 6066: 6067, 6070: 6071, 6074: 6075, 6078: 6079, 6082: 6083, 6086: 6087, 6091: 6092, 6095: 6096, 6099: 6100, 6103: 6104, 6107: 6108, 6111: 6112, 6115: 6116, 6119: 6120, 6124: 6125, 6128: 6129, 6132: 6133, 6136: 6137, 6140: 6141, 6144: 6145, 6148: 6149, 6152: 6154, 6157: 6158, 6161: 6162, 6165: 6166, 6169: 6170, 6173: 6174, 6177: 6178, 6181: 6182, 6185: 6187, 6190: 6191, 6194: 6195, 6198: 6199, 6202: 6203, 6206: 6207, 6210: 6211, 6214: 6215, 6218: 6220, 6223: 6224, 6227: 6228, 6231: 6232, 6235: 6236, 6239: 6240, 6243: 6244, 6247: 6249, 6251: 6253, 6256: 6257, 6260: 6261, 6264: 6265, 6268: 6269, 6272: 6273, 6276: 6277, 6280: 6282, 6284: 6286, 6289: 6290, 6293: 6294, 6297: 6298, 6301: 6302, 6305: 6306, 6309: 6310, 6313: 6315, 6317: 6319, 6322: 6323, 6326: 6327, 6330: 6331, 6334: 6335, 6338: 6339, 6342: 6344, 6346: 6348, 6350: 6352, 6355: 6356, 6359: 6360, 6363: 6364, 6367: 6368, 6371: 6372, 6375: 6377, 6379: 6381, 6383: 6385, 6388: 6389, 6392: 6393, 6396: 6397, 6400: 6401, 6404: 6406, 6408: 6410, 6412: 6414, 6416: 6418, 6421: 6422, 6425: 6426, 6429: 6430, 6433: 6434, 6437: 6439, 6441: 6443, 6445: 6447, 6449: 6451, 6454: 6455, 6458: 6459, 6462: 6463, 6466: 6468, 6470: 6472, 6474: 6476, 6478: 6480, 6482: 6484, 6487: 6488, 6491: 6492, 6495: 6496 } | ||
while (condition()) { | ||
offset = offset + (this.#year > 0 ? delta : (-1 * delta)) | ||
if (offset > 1) offset -= 1 | ||
if (offset < 0) offset += 1 | ||
if (offset >= 0.257800926 && offset <= 0.5) { | ||
let $correct = correct[year] || year | ||
if (this.#year > 0 && $correct <= this.#year) this.#leaps.push($correct) | ||
if (this.#year < 0) this.#leaps.push($correct) | ||
} | ||
increase() | ||
} | ||
break | ||
default: | ||
while (condition()) { | ||
if (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)) this.#leaps.push(year) | ||
increase() | ||
} | ||
} | ||
} | ||
convert(calendar = DateObject.calendars.GEORGIAN) { | ||
calendar = DateObject.calendars[calendar.toUpperCase()] | ||
if (!calendar) throw new Error("calendar not found") | ||
if (calendar === this.#calendar) return this | ||
const yearEpoch = () => { | ||
let yearEpoch = 0 | ||
switch (this.#calendar + "->" + calendar) { | ||
case "PERSIAN->GEORGIAN": | ||
case "GEORGIAN->PERSIAN": | ||
if (this.#month < 10 || (this.#month === 10 && this.#day <= (this.isLeap ? 11 : 10))) { | ||
yearEpoch = calendar === DateObject.calendars.GEORGIAN ? 621 : -621 | ||
} else { | ||
yearEpoch = calendar === DateObject.calendars.GEORGIAN ? 622 : -622 | ||
} | ||
break | ||
default: yearEpoch = 0 | ||
} | ||
return yearEpoch | ||
} | ||
let year = this.#year | ||
let days = this.dayOfBeginning | ||
let month = undefined | ||
let target = undefined | ||
days += this.#epoch[this.#calendar][calendar] | ||
target = new DateObject({ | ||
calendar, | ||
year: year + yearEpoch(), | ||
month: 1, | ||
day: 1 | ||
}) | ||
days -= target.isLeap ? (target.leaps.length - 1) : target.leaps.length | ||
year = ~~(days / 365) + 1 | ||
days = days % 365 | ||
month = 0 | ||
this.#year = year | ||
this.#month = month | ||
this.#day = ~~days | ||
this.#calendar = calendar | ||
this.#getLeaps() | ||
this.#fix() | ||
return this | ||
} | ||
format(format) { | ||
if (!format) format = this.#format || "YYYY/MM/DD" | ||
let index = 100 //can be any number | ||
let object = {} | ||
for (let key in this.#types) { | ||
while (format.includes(key)) { | ||
format = format.replace(key, index) | ||
object[index] = this.getProperty(key) | ||
console.log(object[index], key, this.getProperty(key)); | ||
index++ | ||
} | ||
} | ||
for (let key in object) { | ||
format = format.replace(key, object[key]) | ||
} | ||
if (this.#local !== DateObject.locals.en) { | ||
let digits = this.#digits[this.#local] | ||
format = format.replace(/[0-9]/g, w => digits[w]) | ||
} | ||
return format | ||
} | ||
getProperty(key) { | ||
const pad = number => number < 10 ? "0" + number : number | ||
switch (key) { | ||
case "YYYY": return this.year | ||
case "YY": return this.year.toString().substring(2, 4) | ||
case "MMMM": return this.month.name | ||
case "MMM": return this.month.shortName | ||
case "MM": return pad(this.month.number) | ||
case "M": return this.month.number | ||
case "DDDD": return this.dayOfYear | ||
case "DDD": return this.dayOfYear | ||
case "DD": return pad(this.day) | ||
case "D": return this.day | ||
case "HH": return pad(this.hour) | ||
case "H": return this.hour | ||
case "dddd": return this.weekDay.name | ||
case "ddd": return this.weekDay.shortName | ||
case "hh": return pad(this.hour > 12 ? this.hour - 12 : this.hour) | ||
case "h": return this.hour > 12 ? this.hour - 12 : this.hour | ||
case "mm": return pad(this.minute) | ||
case "m": return this.minute | ||
case "ss": return pad(this.second) | ||
case "s": return this.second | ||
case "SSS": return this.#millisecond | ||
case "SS": return this.#millisecond.toString().substring(0, 2) | ||
case "S": return this.#millisecond.toString().substring(0, 1) | ||
case "a": return this.hour >= 12 ? this.#meridiems[this.#local][1].shortName : this.#meridiems[this.#local][0].shortName | ||
case "A": return this.hour >= 12 ? this.#meridiems[this.#local][1].name : this.#meridiems[this.#local][0].name | ||
default: return "" | ||
} | ||
} | ||
setYear(number) { | ||
this.year = number | ||
return this | ||
} | ||
setMonth(number) { | ||
this.month = number | ||
return this | ||
} | ||
setDay(number) { | ||
this.day = number | ||
return this | ||
} | ||
setHour(number) { | ||
this.hour = number | ||
return this | ||
} | ||
setMinute(number) { | ||
this.minute = number | ||
return this | ||
} | ||
setSecond(number) { | ||
this.second = number | ||
return this | ||
} | ||
setMillisecond(number) { | ||
this.millisecond = number | ||
return this | ||
} | ||
setFormat(format) { | ||
this.#format = format | ||
return this | ||
} | ||
setLocal(local) { | ||
this.local = local | ||
return this | ||
} | ||
setCalendar(calendar) { | ||
this.calendar = calendar | ||
return this | ||
} | ||
toFirstOfYear() { | ||
this.month = 1 | ||
this.day = 1 | ||
return this | ||
} | ||
toLastOfYear() { | ||
if (this.day >= 29) this.day = 29 | ||
this.month = 12 | ||
this.toLastOfMonth() | ||
return this | ||
} | ||
toFirstOfMonth() { | ||
this.#day = 1 | ||
return this | ||
} | ||
toLastOfMonth() { | ||
this.#day = 0 | ||
this.#month += 1 | ||
this.#fix() | ||
return this | ||
} | ||
toFirstOfWeek() { | ||
this.day -= this.weekDay.index | ||
return this | ||
} | ||
toLastOfWeek() { | ||
this.day += 6 - this.weekDay.index | ||
return this | ||
} | ||
toFirstWeekOfYear() { | ||
this.toFirstOfYear() | ||
if (this.weekDay.index === 0) return this | ||
return this.toLastOfWeek().setDay(this.day + 1) | ||
} | ||
toLastWeekOfYear() { | ||
return this.toLastOfYear().toFirstOfWeek() | ||
} | ||
toString() { | ||
return this.format() | ||
} | ||
toDate() { | ||
if (this.#calendar !== DateObject.calendars.GEORGIAN) this.convert(DateObject.calendars.GEORGIAN) | ||
return new Date(this.#year, this.#month, this.#day, this.#hour, this.#second) | ||
} | ||
get dayOfBeginning() { | ||
let days = (this.#year > 0 ? (this.#year - 1) : this.#year) * 365 | ||
let leapsLength = this.isLeap ? (this.leaps.length - 1) : this.leaps.length | ||
if (this.#year > 0) days += leapsLength | ||
if (this.#year < 0) days -= leapsLength | ||
days += this.dayOfYear | ||
return days | ||
} | ||
get dayOfYear() { | ||
let days = this.#day | ||
let months = this.months | ||
for (let i = 0; i < months.length; i++) { | ||
if (i >= this.#month) break | ||
days += months[i].length | ||
} | ||
return days | ||
} | ||
get weekOfYear() { | ||
return ~~(this.dayOfYear / 7) + 1 | ||
} | ||
get daysLeft() { | ||
let days = this.isLeap ? 366 : 365 | ||
return days - this.dayOfYear | ||
} | ||
get year() { | ||
return this.#year | ||
} | ||
get month() { | ||
let month = this.months[this.#month] | ||
if (!month) return [] | ||
month.index = this.#month | ||
month.number = month.index + 1 | ||
month.toString = function () { | ||
return this.number | ||
} | ||
return month | ||
} | ||
get day() { | ||
return this.#day | ||
} | ||
get weekDay() { | ||
let index = this.dayOfBeginning % 7 | ||
if (index < 0) index += 7 | ||
let weekDay = this.#weeks[this.#calendar][index] | ||
if (!weekDay) return {} | ||
weekDay = { | ||
index: weekDay.index, | ||
number: weekDay.index + 1, | ||
toString: function () { return this.number }, | ||
...weekDay.locals[this.#local] | ||
} | ||
return weekDay | ||
} | ||
get hour() { | ||
return this.#hour | ||
} | ||
get minute() { | ||
return this.#minute | ||
} | ||
get second() { | ||
return this.#second | ||
} | ||
get millisecond() { | ||
return this.#millisecond | ||
} | ||
get months() { | ||
let months = this.#months[this.#calendar] | ||
switch (this.#calendar) { | ||
case DateObject.calendars.PERSIAN: | ||
months[11].length = this.isLeap ? 30 : 29 | ||
break | ||
default: | ||
months[1].length = this.isLeap ? 29 : 28 | ||
} | ||
months = months.map(month => { | ||
return { | ||
length: month.length, | ||
...month.locals[this.#local] | ||
} | ||
}) | ||
return months | ||
} | ||
get weeks() { | ||
let weeks = this.#weeks[this.#calendar] | ||
weeks.sort((a, b) => a.index - b.index) | ||
weeks = weeks.map(week => { return { index: week.index, number: week.index + 1, ...week.locals[this.#local] } }) | ||
return weeks | ||
} | ||
get leaps() { | ||
return this.#leaps | ||
} | ||
get calendar() { | ||
return this.#calendar.toLowerCase() | ||
} | ||
get local() { | ||
return this.#local.toLowerCase() | ||
} | ||
get meridiems() { | ||
return this.#meridiems[this.#local] | ||
} | ||
get digits() { | ||
return this.#digits[this.#local] | ||
} | ||
get _format() { | ||
return this.#format | ||
} | ||
get isLeap() { | ||
return this.#leaps.includes(this.#year) | ||
} | ||
set year(value) { | ||
this.#year = value | ||
this.#getLeaps() | ||
this.#fix() | ||
} | ||
set month(value) { | ||
this.#month = value - 1 | ||
this.#fix() | ||
} | ||
set day(value) { | ||
this.#day = value | ||
this.#fix() | ||
} | ||
set hour(value) { | ||
this.#hour = value | ||
this.#fix() | ||
} | ||
set minute(value) { | ||
this.#minute = value | ||
this.#fix() | ||
} | ||
set second(value) { | ||
this.#second = value | ||
this.#fix() | ||
} | ||
set millisecond(value) { | ||
this.#millisecond = value | ||
this.#fix() | ||
} | ||
set calendar(calendar) { | ||
this.convert(calendar) | ||
} | ||
set local(local) { | ||
local = local.toUpperCase() | ||
if (!DateObject.locals[local]) local = DateObject.locals.en | ||
this.#local = local | ||
} | ||
set _format(format) { | ||
this.#format = format | ||
} | ||
} | ||
export default DateObject |
{ | ||
"name": "react-date-object", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "JavaScript library for working with Date and Time in different calendars and locals", | ||
@@ -39,3 +39,3 @@ "main": "./dist/index.js", | ||
"babel-preset-env": "^1.7.0", | ||
"date-object": "^0.1.5", | ||
"date-object": "^0.1.6", | ||
"webpack": "^4.44.1", | ||
@@ -42,0 +42,0 @@ "webpack-cli": "^3.3.12", |
@@ -9,4 +9,12 @@ # Date Object | ||
# example | ||
React: [react-date-object](https://github.com/shahabyazdi/react-date-object) | ||
# Install | ||
```shell | ||
npm install date-object --save | ||
``` | ||
# Example | ||
## 1- new instance | ||
@@ -26,5 +34,13 @@ | ||
### 1-2- JavaScript Date | ||
### 1-2- Number (unix timestamp) | ||
```javascript | ||
var date = new DateObject(1597994736); | ||
date.format("dddd DD MMMM @ hh:mm:ss.SSS a"); //Friday 21 August @ 11:55:36.0 am | ||
``` | ||
### 1-3- JavaScript Date | ||
```javascript | ||
var $date = new Date(2019, 8, 20); | ||
@@ -37,3 +53,3 @@ | ||
### 1-3- DateObject | ||
### 1-4- DateObject | ||
@@ -48,9 +64,9 @@ ```javascript | ||
### 1-4- Object | ||
### 1-5- Object | ||
#### 1-4-1- | ||
#### 1-5-1- | ||
```javascript | ||
{ | ||
date: String or JavaScript Date or DateObject, //default new Date() | ||
date: String , Number(unix timestamp), JavaScript Date or DateObject, //default new Date() | ||
calendar: `georgian` or `persian`, //default `georgian` | ||
@@ -90,3 +106,3 @@ local: `en` or `fa`, //default `en` | ||
#### 1-4-2- | ||
#### 1-5-2- | ||
@@ -237,2 +253,3 @@ ```javascript | ||
date.weekOfYear; //34 | ||
date.unix; //1597951800 | ||
@@ -244,3 +261,3 @@ date.weeks; // array [{ name: 'Sunday', shortName: 'Sun', ...}] | ||
## 4- other methods | ||
## 4- parse method | ||
@@ -250,2 +267,22 @@ ```javascript | ||
date._format = "dddd DD MMMM YYYY"; | ||
date.parse("Monday 24 August 2020"); | ||
date.format("YYYY/MM/DD"); //2020/08/24 | ||
date.parse("Friday 07 August 2020"); | ||
date.format("YYYY-MM-DD"); //2020-08-07 | ||
date.setCalendar("persian").setFormat("YYYY/MM/DD").parse("1399/06/03"); | ||
date.format(); //1399/06/03 | ||
date.setFormat("YYYY/MM/DD HH:mm").parse("1399/06/03 12:32"); | ||
date.format("dddd DD MMMM @ hh:mm a"); //Doshanbeh 03 Shahrivar @ 12:32 am | ||
``` | ||
## 5- other methods | ||
```javascript | ||
var date = new DateObject(); | ||
date.toFirstOfWeek(); //2020/08/16 | ||
@@ -262,2 +299,3 @@ date.toFirstOfMonth(); //2020/08/01 | ||
date.toDate(); //instanceof Date | ||
date.toUnix(); //1609014600 | ||
``` | ||
@@ -264,0 +302,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
311
34255
25