@js-sugar/date
Version:
A multi-calendar, tree-shakable, extensible, immutable and lightweight date library for JavaScript
1 lines • 2.21 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["jss-date"]=e():t["jss-date"]=e()}(this,(function(){return(this.webpackChunkjss_date=this.webpackChunkjss_date||[]).push([[930],{788:(t,e,n)=>{"use strict";n.r(e),n.d(e,{GregorianCalendar2:()=>GregorianCalendar2});var r=n(157);const a=1461,s=36524,o=146097;function c(t){return t%4==0&&(t%100!=0||t%400==0)}function u(t,e,n){return function(t,e,n){if(t>=1&&t<=r.MAX_YEAR&&e>=1&&e<=12){const a=c(t)?r.DAYS_TO_MONTH_366:r.DAYS_TO_MONTH_365;if(n>=1&&n<=a[e]-a[e-1]){const r=t-1;return 365*r+Math.trunc(r/4)-Math.trunc(r/100)+Math.trunc(r/400)+a[e-1]+n-1}}(0,r.throwInvalidParam)()}(t,e,n)*r.MS_PER_DAY}class GregorianCalendar2 extends r.Calendar{constructor(t){super(t,"gregory")}addMonths(t,e){const n=this.getUnits(t);let a=n.year,s=n.month,o=n.day;const c=s-1+e;c>=0?(s=c%12+1,a=Math.trunc(a+c/12)):(s=12+(c+1)%12,a+=Math.trunc((c-11)/12));const i=this.isLeapYear(a)?r.DAYS_TO_MONTH_366:r.DAYS_TO_MONTH_365,_=i[s]-i[s-1];o>_&&(o=_);const d=u(a,s,o)+(0,r.getCalendarTimestamp)(t)%r.MS_PER_DAY;return(0,r.getJsTimestamp)(d)}addYears(t,e){return this.addMonths(t,12*e)}dayOfYear(t){const e=new Date(t),n=new Date(e.getFullYear(),0,0),a=e.getTime()-n.getTime();return Math.floor(a/r.MS_PER_DAY)}daysInMonth(t,e){const n=this.isLeapYear(t)?r.DAYS_TO_MONTH_366:r.DAYS_TO_MONTH_365;return n[e]-n[e-1]}daysInYear(t){return this.isLeapYear(t)?366:365}isLeapYear(t){return c(t)}getTimestamp(t){const e=t;return Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.ms)}getUnits(t){return t=(0,r.getCalendarTimestamp)(t),Object.assign(Object.assign({},function(t){const e={year:0,month:0,day:0,hour:0,minute:0,second:0,ms:0};let n=Math.trunc(t/r.MS_PER_DAY);const c=Math.trunc(n/o);n-=c*o;let u=Math.trunc(n/s);4==u&&(u=3),n-=u*s;const i=Math.trunc(n/a);n-=i*a;let _=Math.trunc(n/365);4==_&&(_=3),e.year=400*c+100*u+4*i+_+1,n-=365*_;const d=3!=_||24==i&&3!=u?r.DAYS_TO_MONTH_365:r.DAYS_TO_MONTH_366;let h=1+(n>>5);for(;n>=d[h];)h++;return e.month=h,e.day=n-d[h-1]+1,e}(t)),(0,r.getTimeUnits)(t))}}}},t=>{"use strict";var e;return e=788,t(t.s=e)}])}));