@subrotosaha/datekit 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +19 -9
- package/dist/index.d.ts +19 -9
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -106,24 +106,27 @@ declare class DateKit {
|
|
|
106
106
|
toString(): string;
|
|
107
107
|
format(formatStr: string): string;
|
|
108
108
|
/**
|
|
109
|
-
* Parses a timezone-aware date
|
|
109
|
+
* Parses a timezone-aware date and formats it in the original timezone
|
|
110
110
|
* without applying timezone conversion. This ensures the local date components
|
|
111
111
|
* remain unchanged regardless of the timezone offset.
|
|
112
112
|
*
|
|
113
|
-
* @param
|
|
113
|
+
* @param dateInput - The timezone-aware date (can be Date, string, or number/timestamp)
|
|
114
114
|
* @param formatStr - The format string for the output (e.g., "DD-MM-YYYY")
|
|
115
115
|
* @returns The formatted date string preserving the original timezone's date
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* DateKit.formatFromTimezoneString("Sun Aug 31 2025 00:00:00 GMT+0600 (Bangladesh Standard Time)", "DD-MM-YYYY")
|
|
119
119
|
* // Returns: "31-08-2025"
|
|
120
|
+
* @example
|
|
121
|
+
* DateKit.formatFromTimezoneString(new Date("2025-08-31T00:00:00+06:00"), "DD-MM-YYYY")
|
|
122
|
+
* // Returns: "31-08-2025"
|
|
120
123
|
*/
|
|
121
|
-
static formatFromTimezoneString(
|
|
124
|
+
static formatFromTimezoneString(dateInput: DateInput, formatStr: string): string;
|
|
122
125
|
/**
|
|
123
|
-
* Static method: Formats a timezone-aware date
|
|
126
|
+
* Static method: Formats a timezone-aware date with explicit GMT offset.
|
|
124
127
|
* Preserves the local date components from the specified timezone.
|
|
125
128
|
*
|
|
126
|
-
* @param input - The timezone-aware date
|
|
129
|
+
* @param input - The timezone-aware date (can be Date, string, or number/timestamp)
|
|
127
130
|
* @param outputFormat - The format string for the output (default: "DD-MM-YYYY")
|
|
128
131
|
* @param locale - The locale for formatting (default: "en")
|
|
129
132
|
* @returns The formatted date string preserving the original timezone's date
|
|
@@ -131,13 +134,16 @@ declare class DateKit {
|
|
|
131
134
|
* @example
|
|
132
135
|
* DateKit.formatZonedDate("Sun Aug 31 2025 00:00:00 GMT+0600 (Bangladesh Standard Time)", "DD-MM-YYYY")
|
|
133
136
|
* // Returns: "31-08-2025"
|
|
137
|
+
* @example
|
|
138
|
+
* DateKit.formatZonedDate(new Date("2025-08-31T00:00:00+06:00"), "DD-MM-YYYY")
|
|
139
|
+
* // Returns: "31-08-2025"
|
|
134
140
|
*/
|
|
135
|
-
static formatZonedDate(input:
|
|
141
|
+
static formatZonedDate(input: DateInput, outputFormat?: string, locale?: string): string;
|
|
136
142
|
/**
|
|
137
|
-
* Instance method: Formats a timezone-aware date
|
|
143
|
+
* Instance method: Formats a timezone-aware date using the instance's locale.
|
|
138
144
|
* Convenience wrapper around the static formatZonedDate method.
|
|
139
145
|
*
|
|
140
|
-
* @param input - The timezone-aware date string
|
|
146
|
+
* @param input - The timezone-aware date (can be Date, string, or number/timestamp)
|
|
141
147
|
* @param outputFormat - The format string for the output (default: "DD-MM-YYYY")
|
|
142
148
|
* @returns The formatted date string preserving the original timezone's date
|
|
143
149
|
*
|
|
@@ -145,8 +151,12 @@ declare class DateKit {
|
|
|
145
151
|
* const dk = new DateKit('2025-01-15', { locale: 'es' });
|
|
146
152
|
* dk.formatZonedDate("Sun Aug 31 2025 00:00:00 GMT+0600", "DD-MM-YYYY")
|
|
147
153
|
* // Returns: "31-08-2025" (uses 'es' locale from instance)
|
|
154
|
+
* @example
|
|
155
|
+
* const dk = new DateKit('2025-01-15', { locale: 'es' });
|
|
156
|
+
* dk.formatZonedDate(new Date("2025-08-31T00:00:00+06:00"), "DD-MM-YYYY")
|
|
157
|
+
* // Returns: "31-08-2025"
|
|
148
158
|
*/
|
|
149
|
-
formatZonedDate(input:
|
|
159
|
+
formatZonedDate(input: DateInput, outputFormat?: string): string;
|
|
150
160
|
/**
|
|
151
161
|
* Converts a date from one IANA timezone to another and formats it.
|
|
152
162
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -106,24 +106,27 @@ declare class DateKit {
|
|
|
106
106
|
toString(): string;
|
|
107
107
|
format(formatStr: string): string;
|
|
108
108
|
/**
|
|
109
|
-
* Parses a timezone-aware date
|
|
109
|
+
* Parses a timezone-aware date and formats it in the original timezone
|
|
110
110
|
* without applying timezone conversion. This ensures the local date components
|
|
111
111
|
* remain unchanged regardless of the timezone offset.
|
|
112
112
|
*
|
|
113
|
-
* @param
|
|
113
|
+
* @param dateInput - The timezone-aware date (can be Date, string, or number/timestamp)
|
|
114
114
|
* @param formatStr - The format string for the output (e.g., "DD-MM-YYYY")
|
|
115
115
|
* @returns The formatted date string preserving the original timezone's date
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* DateKit.formatFromTimezoneString("Sun Aug 31 2025 00:00:00 GMT+0600 (Bangladesh Standard Time)", "DD-MM-YYYY")
|
|
119
119
|
* // Returns: "31-08-2025"
|
|
120
|
+
* @example
|
|
121
|
+
* DateKit.formatFromTimezoneString(new Date("2025-08-31T00:00:00+06:00"), "DD-MM-YYYY")
|
|
122
|
+
* // Returns: "31-08-2025"
|
|
120
123
|
*/
|
|
121
|
-
static formatFromTimezoneString(
|
|
124
|
+
static formatFromTimezoneString(dateInput: DateInput, formatStr: string): string;
|
|
122
125
|
/**
|
|
123
|
-
* Static method: Formats a timezone-aware date
|
|
126
|
+
* Static method: Formats a timezone-aware date with explicit GMT offset.
|
|
124
127
|
* Preserves the local date components from the specified timezone.
|
|
125
128
|
*
|
|
126
|
-
* @param input - The timezone-aware date
|
|
129
|
+
* @param input - The timezone-aware date (can be Date, string, or number/timestamp)
|
|
127
130
|
* @param outputFormat - The format string for the output (default: "DD-MM-YYYY")
|
|
128
131
|
* @param locale - The locale for formatting (default: "en")
|
|
129
132
|
* @returns The formatted date string preserving the original timezone's date
|
|
@@ -131,13 +134,16 @@ declare class DateKit {
|
|
|
131
134
|
* @example
|
|
132
135
|
* DateKit.formatZonedDate("Sun Aug 31 2025 00:00:00 GMT+0600 (Bangladesh Standard Time)", "DD-MM-YYYY")
|
|
133
136
|
* // Returns: "31-08-2025"
|
|
137
|
+
* @example
|
|
138
|
+
* DateKit.formatZonedDate(new Date("2025-08-31T00:00:00+06:00"), "DD-MM-YYYY")
|
|
139
|
+
* // Returns: "31-08-2025"
|
|
134
140
|
*/
|
|
135
|
-
static formatZonedDate(input:
|
|
141
|
+
static formatZonedDate(input: DateInput, outputFormat?: string, locale?: string): string;
|
|
136
142
|
/**
|
|
137
|
-
* Instance method: Formats a timezone-aware date
|
|
143
|
+
* Instance method: Formats a timezone-aware date using the instance's locale.
|
|
138
144
|
* Convenience wrapper around the static formatZonedDate method.
|
|
139
145
|
*
|
|
140
|
-
* @param input - The timezone-aware date string
|
|
146
|
+
* @param input - The timezone-aware date (can be Date, string, or number/timestamp)
|
|
141
147
|
* @param outputFormat - The format string for the output (default: "DD-MM-YYYY")
|
|
142
148
|
* @returns The formatted date string preserving the original timezone's date
|
|
143
149
|
*
|
|
@@ -145,8 +151,12 @@ declare class DateKit {
|
|
|
145
151
|
* const dk = new DateKit('2025-01-15', { locale: 'es' });
|
|
146
152
|
* dk.formatZonedDate("Sun Aug 31 2025 00:00:00 GMT+0600", "DD-MM-YYYY")
|
|
147
153
|
* // Returns: "31-08-2025" (uses 'es' locale from instance)
|
|
154
|
+
* @example
|
|
155
|
+
* const dk = new DateKit('2025-01-15', { locale: 'es' });
|
|
156
|
+
* dk.formatZonedDate(new Date("2025-08-31T00:00:00+06:00"), "DD-MM-YYYY")
|
|
157
|
+
* // Returns: "31-08-2025"
|
|
148
158
|
*/
|
|
149
|
-
formatZonedDate(input:
|
|
159
|
+
formatZonedDate(input: DateInput, outputFormat?: string): string;
|
|
150
160
|
/**
|
|
151
161
|
* Converts a date from one IANA timezone to another and formats it.
|
|
152
162
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Y=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var J=(r,t)=>{for(var e in t)Y(r,e,{get:t[e],enumerable:!0})},R=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of B(t))!Q.call(r,a)&&a!==e&&Y(r,a,{get:()=>t[a],enumerable:!(n=Z(t,a))||n.enumerable});return r};var V=r=>R(Y({},"__esModule",{value:!0}),r);var P={};J(P,{DateKit:()=>p,Duration:()=>f,en:()=>L,es:()=>x,getLocale:()=>M,registerLocale:()=>W});module.exports=V(P);var L={name:"en",weekdays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],weekdaysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ordinal:r=>{let t=["th","st","nd","rd"],e=r%100;return r+(t[(e-20)%10]||t[e]||t[0])},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"}};var x={name:"es",weekdays:["Domingo","Lunes","Martes","Mi\xE9rcoles","Jueves","Viernes","S\xE1bado"],weekdaysShort:["Dom","Lun","Mar","Mi\xE9","Jue","Vie","S\xE1b"],weekdaysMin:["Do","Lu","Ma","Mi","Ju","Vi","S\xE1"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],ordinal:r=>`${r}\xBA`,relativeTime:{future:"en %s",past:"hace %s",s:"unos segundos",m:"un minuto",mm:"%d minutos",h:"una hora",hh:"%d horas",d:"un d\xEDa",dd:"%d d\xEDas",M:"un mes",MM:"%d meses",y:"un a\xF1o",yy:"%d a\xF1os"},calendar:{sameDay:"[Hoy a las] LT",nextDay:"[Ma\xF1ana a las] LT",nextWeek:"dddd [a las] LT",lastDay:"[Ayer a las] LT",lastWeek:"[El] dddd [pasado a las] LT",sameElse:"L"}};var K={en:L,es:x};function M(r){return K[r]||K.en}function W(r){K[r.name]=r}function E(r,t,e="en"){let n=M(e),a=r.getUTCFullYear(),s=r.getUTCMonth(),o=r.getUTCDate(),i=r.getUTCHours(),c=r.getUTCMinutes(),d=r.getUTCSeconds(),h=r.getUTCMilliseconds(),m=r.getUTCDay(),u=new Date(Date.UTC(a,0,1)),D=Math.floor((r.getTime()-u.getTime())/864e5)+1,g=Math.floor(s/3)+1,T=q(r),k=new Map,w=new Map,y={YYYY:a.toString(),YY:a.toString().slice(-2),Qo:n.ordinal(g),Q:g.toString(),MMMM:n.months[s],MMM:n.monthsShort[s],Mo:n.ordinal(s+1),MM:(s+1).toString().padStart(2,"0"),M:(s+1).toString(),Wo:n.ordinal(T),WW:T.toString().padStart(2,"0"),W:T.toString(),DDDo:n.ordinal(D),DDDD:D.toString().padStart(3,"0"),DDD:D.toString(),Do:n.ordinal(o),DD:o.toString().padStart(2,"0"),D:o.toString(),dddd:n.weekdays[m],ddd:n.weekdaysShort[m],do:n.ordinal(m),dd:n.weekdaysMin[m],d:m.toString(),HH:i.toString().padStart(2,"0"),H:i.toString(),hh:(i%12||12).toString().padStart(2,"0"),h:(i%12||12).toString(),mm:c.toString().padStart(2,"0"),m:c.toString(),ss:d.toString().padStart(2,"0"),s:d.toString(),SSS:h.toString().padStart(3,"0"),SS:h.toString().padStart(2,"0").slice(0,2),S:Math.floor(h/100).toString(),A:i>=12?"PM":"AM",a:i>=12?"pm":"am",Z:v(r.getTimezoneOffset()),ZZ:v(r.getTimezoneOffset()).replace(":",""),X:Math.floor(r.getTime()/1e3).toString(),x:r.getTime().toString()},S=t;return Object.keys(y).sort((b,U)=>U.length-b.length).forEach((b,U)=>{let N=`\0${U}\0`,$=new RegExp(b,"g");S=S.replace($,N),w.set(N,y[b])}),w.forEach((b,U)=>{S=S.replace(new RegExp(U,"g"),b)}),S}function q(r){let t=new Date(r.getTime());t.setUTCHours(0,0,0,0),t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));let e=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-e.getTime())/864e5+1)/7)}function v(r){let t=r<=0?"+":"-",e=Math.abs(r),n=Math.floor(e/60),a=e%60;return`${t}${n.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function l(r){if(r instanceof Date)return new Date(r);if(typeof r=="number")return new Date(r);if(typeof r=="string")return new Date(r);throw new Error("Invalid date input")}function C(r){return r instanceof Date&&!isNaN(r.getTime())}function I(r,t="en",e=!1){let n=M(t),a=r<0,o=Math.abs(r)/1e3,i=o/60,c=i/60,d=c/24,h=d/30.44,m=d/365.25,u;return o<45?u=n.relativeTime.s:o<90?u=n.relativeTime.m:i<45?u=n.relativeTime.mm.replace("%d",Math.round(i).toString()):i<90?u=n.relativeTime.h:c<22?u=n.relativeTime.hh.replace("%d",Math.round(c).toString()):c<36?u=n.relativeTime.d:d<25?u=n.relativeTime.dd.replace("%d",Math.round(d).toString()):d<45?u=n.relativeTime.M:d<345?u=n.relativeTime.MM.replace("%d",Math.round(h).toString()):m<1.5?u=n.relativeTime.y:u=n.relativeTime.yy.replace("%d",Math.round(m).toString()),e?u:(a?n.relativeTime.future:n.relativeTime.past).replace("%s",u)}function H(r,t=new Date,e="en"){let n=M(e),a=new p(r),s=new p(t),o=a.startOf("day").diff(s.startOf("day").toDate(),"day"),i;return o===0?i=n.calendar.sameDay:o===1?i=n.calendar.nextDay:o===-1?i=n.calendar.lastDay:o>1&&o<=7?i=n.calendar.nextWeek:o<-1&&o>=-7?i=n.calendar.lastWeek:i=n.calendar.sameElse,i=i.replace("[","").replace("]","").replace("LT",a.format("HH:mm")).replace("L",a.format("MM/DD/YYYY")).replace("dddd",n.weekdays[r.getUTCDay()]),i}var A=[1,2,3,4,5];function O(r,t=[]){let e=r.getUTCDay();if(!A.includes(e))return!1;let n=r.toISOString().split("T")[0];return!t.some(a=>a.toISOString().split("T")[0]===n)}function F(r,t,e=[]){let n=new Date(r),a=Math.abs(t),s=t>0?1:-1;for(;a>0;)n.setUTCDate(n.getUTCDate()+s),O(n,e)&&a--;return n}function z(r,t,e=[]){let n=0,a=new Date(r),s=new Date(t);for(;a<=s;)O(a,e)&&n++,a.setUTCDate(a.getUTCDate()+1);return n}var f=class r{constructor(t,e="milliseconds"){typeof t=="number"?this._milliseconds=this.convertToMilliseconds(t,e):this._milliseconds=this.objectToMilliseconds(t)}convertToMilliseconds(t,e){return t*({milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5}[e]||1)}objectToMilliseconds(t){let e=0;return t.years&&(e+=t.years*365.25*864e5),t.months&&(e+=t.months*30.44*864e5),t.weeks&&(e+=t.weeks*6048e5),t.days&&(e+=t.days*864e5),t.hours&&(e+=t.hours*36e5),t.minutes&&(e+=t.minutes*6e4),t.seconds&&(e+=t.seconds*1e3),t.milliseconds&&(e+=t.milliseconds),e}asMilliseconds(){return this._milliseconds}asSeconds(){return this._milliseconds/1e3}asMinutes(){return this._milliseconds/6e4}asHours(){return this._milliseconds/36e5}asDays(){return this._milliseconds/864e5}asWeeks(){return this._milliseconds/6048e5}asMonths(){return this._milliseconds/(30.44*864e5)}asYears(){return this._milliseconds/(365.25*864e5)}humanize(t="en"){let e=Math.abs(this.asSeconds()),n=Math.abs(this.asMinutes()),a=Math.abs(this.asHours()),s=Math.abs(this.asDays()),o=Math.abs(this.asMonths()),i=Math.abs(this.asYears());return e<45?"a few seconds":e<90?"a minute":n<45?`${Math.round(n)} minutes`:n<90?"an hour":a<22?`${Math.round(a)} hours`:a<36?"a day":s<25?`${Math.round(s)} days`:s<45?"a month":s<345?`${Math.round(o)} months`:i<1.5?"a year":`${Math.round(i)} years`}toObject(){let t=Math.abs(this._milliseconds),e=Math.floor(t/(365.25*864e5));t-=e*365.25*864e5;let n=Math.floor(t/(30.44*864e5));t-=n*30.44*864e5;let a=Math.floor(t/864e5);t-=a*864e5;let s=Math.floor(t/36e5);t-=s*36e5;let o=Math.floor(t/6e4);t-=o*6e4;let i=Math.floor(t/1e3);t-=i*1e3;let c=Math.floor(t);return{years:e,months:n,days:a,hours:s,minutes:o,seconds:i,milliseconds:c}}add(t){return new r(this._milliseconds+t.asMilliseconds())}subtract(t){return new r(this._milliseconds-t.asMilliseconds())}static between(t,e){return new r(Math.abs(e.getTime()-t.getTime()))}};var p=class r{constructor(t,e){if(this.config={locale:"en",weekStartsOn:0,strictParsing:!1,...e},this.date=t?l(t):new Date,!C(this.date))throw new Error("Invalid date provided")}toDate(){return new Date(this.date)}toISOString(){return this.date.toISOString()}toUnix(){return Math.floor(this.date.getTime()/1e3)}valueOf(){return this.date.getTime()}toArray(){return[this.date.getUTCFullYear(),this.date.getUTCMonth(),this.date.getUTCDate(),this.date.getUTCHours(),this.date.getUTCMinutes(),this.date.getUTCSeconds(),this.date.getUTCMilliseconds()]}toObject(){return{year:this.date.getUTCFullYear(),month:this.date.getUTCMonth(),date:this.date.getUTCDate(),hour:this.date.getUTCHours(),minute:this.date.getUTCMinutes(),second:this.date.getUTCSeconds(),millisecond:this.date.getUTCMilliseconds()}}toJSON(){return this.toISOString()}toString(){return this.date.toString()}format(t){return E(this.date,t,this.config.locale)}static formatFromTimezoneString(t,e){let n=new Date(t);if(isNaN(n.getTime()))throw new Error("Invalid date string provided");let a=t.match(/GMT([+-]\d{2}):?(\d{2})|UTC([+-]\d{2}):?(\d{2})/i),s=0;if(a){let w=(a[1]||a[3])[0],y=parseInt((a[1]||a[3]).substring(1)),S=parseInt(a[2]||a[4]||"0");s=(y*60+S)*(w==="+"?1:-1)}else s=-n.getTimezoneOffset();let i=n.getTime()+s*60*1e3,c=new Date(i),d=c.getUTCFullYear(),h=c.getUTCMonth(),m=c.getUTCDate(),u=c.getUTCHours(),D=c.getUTCMinutes(),g=c.getUTCSeconds(),T=c.getUTCMilliseconds();return new r(Date.UTC(d,h,m,u,D,g,T)).format(e)}static formatZonedDate(t,e="DD-MM-YYYY",n="en"){if(typeof t!="string")throw new Error("formatZonedDate expects input as a string with explicit GMT offset");let a=t.match(/GMT([+-])(\d{2}):?(\d{2})/i),s=new Date(t);if(isNaN(s.getTime()))throw new Error("Invalid date input for formatZonedDate");let o=s;if(a){let i=a[1]==="-"?-1:1,c=parseInt(a[2],10),d=parseInt(a[3],10),h=i*(c*60+d),m=s.getTime()+h*6e4;o=new Date(m)}return E(o,e,n)}formatZonedDate(t,e="DD-MM-YYYY"){let n=this.config?.locale??"en";return r.formatZonedDate(t,e,n)}static convertTimezone(t,e,n,a){let s=l(t);if(!C(s))throw new Error("Invalid date provided");let o,i,c,d,h,m;if(typeof t=="string"&&!t.includes("Z")&&!t.includes("+")&&!t.includes("GMT")){let u=t.match(/(\d{4})-(\d{2})-(\d{2})[T\s](\d{2}):(\d{2}):(\d{2})/);u?(o=parseInt(u[1]),i=parseInt(u[2]),c=parseInt(u[3]),d=parseInt(u[4]),h=parseInt(u[5]),m=parseInt(u[6])):(o=s.getUTCFullYear(),i=s.getUTCMonth()+1,c=s.getUTCDate(),d=s.getUTCHours(),h=s.getUTCMinutes(),m=s.getUTCSeconds());let D=`${o}-${i.toString().padStart(2,"0")}-${c.toString().padStart(2,"0")}T${d.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}:${m.toString().padStart(2,"0")}`,g=new Date(Date.UTC(o,i-1,c,d,h,m)),T=new Date(g.toLocaleString("en-US",{timeZone:e})),k=new Date(g.toLocaleString("en-US",{timeZone:"UTC"})),w=T.getTime()-k.getTime(),y=g.getTime()-w,S=new Date(y);return r.formatInTimezone(S,n,a)}else return r.formatInTimezone(s,n,a)}static formatInTimezone(t,e,n){let a=l(t);if(!C(a))throw new Error("Invalid date provided");let o=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(a),i={};return o.forEach(d=>{d.type!=="literal"&&(i[d.type]=d.value)}),new r(Date.UTC(parseInt(i.year),parseInt(i.month)-1,parseInt(i.day),parseInt(i.hour),parseInt(i.minute),parseInt(i.second))).format(n)}static fromTimezone(t,e,n,a=0,s=0,o=0,i="UTC"){let c=`${t}-${e.toString().padStart(2,"0")}-${n.toString().padStart(2,"0")}T${a.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}`,d=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),h=new Date(c),m=new Date(Date.UTC(t,e-1,n,a,s,o)),u=new Date(m.toLocaleString("en-US",{timeZone:i})),D=new Date(m.toLocaleString("en-US",{timeZone:"UTC"})),g=u.getTime()-D.getTime(),T=m.getTime()-g;return new r(T)}static getTimezoneOffset(t,e=new Date){let n=new Date(e.toLocaleString("en-US",{timeZone:"UTC"}));return(new Date(e.toLocaleString("en-US",{timeZone:t})).getTime()-n.getTime())/6e4}year(){return this.date.getUTCFullYear()}month(){return this.date.getUTCMonth()}getDate(){return this.date.getUTCDate()}day(){return this.date.getUTCDay()}hour(){return this.date.getUTCHours()}minute(){return this.date.getUTCMinutes()}second(){return this.date.getUTCSeconds()}millisecond(){return this.date.getUTCMilliseconds()}quarter(){return Math.floor(this.date.getUTCMonth()/3)+1}week(){return this.isoWeek()}isoWeek(){let t=new Date(this.date.getTime());t.setUTCHours(0,0,0,0),t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));let e=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-e.getTime())/864e5+1)/7)}weekday(){return(this.date.getUTCDay()+7-this.config.weekStartsOn)%7}isoWeekday(){return this.date.getUTCDay()||7}dayOfYear(){let t=new Date(Date.UTC(this.date.getUTCFullYear(),0,1));return Math.floor((this.date.getTime()-t.getTime())/864e5)+1}weekYear(){let t=new Date(this.date.getTime());return t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7)),t.getUTCFullYear()}set(t){let e=new Date(this.date);return t.year!==void 0&&e.setUTCFullYear(t.year),t.month!==void 0&&e.setUTCMonth(t.month),t.date!==void 0&&e.setUTCDate(t.date),t.hour!==void 0&&e.setUTCHours(t.hour),t.minute!==void 0&&e.setUTCMinutes(t.minute),t.second!==void 0&&e.setUTCSeconds(t.second),t.millisecond!==void 0&&e.setUTCMilliseconds(t.millisecond),new r(e,this.config)}setYear(t){return this.set({year:t})}setMonth(t){return this.set({month:t})}setDate(t){return this.set({date:t})}setHour(t){return this.set({hour:t})}setMinute(t){return this.set({minute:t})}setSecond(t){return this.set({second:t})}setMillisecond(t){return this.set({millisecond:t})}setQuarter(t){let e=(t-1)*3;return this.set({month:e})}add(t,e){let n=new Date(this.date);switch(e){case"millisecond":n.setUTCMilliseconds(n.getUTCMilliseconds()+t);break;case"second":n.setUTCSeconds(n.getUTCSeconds()+t);break;case"minute":n.setUTCMinutes(n.getUTCMinutes()+t);break;case"hour":n.setUTCHours(n.getUTCHours()+t);break;case"day":n.setUTCDate(n.getUTCDate()+t);break;case"week":n.setUTCDate(n.getUTCDate()+t*7);break;case"month":n.setUTCMonth(n.getUTCMonth()+t);break;case"quarter":n.setUTCMonth(n.getUTCMonth()+t*3);break;case"year":n.setUTCFullYear(n.getUTCFullYear()+t);break}return new r(n,this.config)}subtract(t,e){return this.add(-t,e)}startOf(t){let e=new Date(this.date);switch(t){case"year":e.setUTCMonth(0);case"quarter":if(t==="quarter"){let s=this.quarter();e.setUTCMonth((s-1)*3)}case"month":e.setUTCDate(1);case"day":e.setUTCHours(0);case"hour":e.setUTCMinutes(0);case"minute":e.setUTCSeconds(0);case"second":e.setUTCMilliseconds(0);break;case"week":let n=e.getUTCDay(),a=(n<this.config.weekStartsOn?7:0)+n-this.config.weekStartsOn;e.setUTCDate(e.getUTCDate()-a),e.setUTCHours(0,0,0,0);break}return new r(e,this.config)}endOf(t){return this.startOf(t).add(1,t).subtract(1,"millisecond")}isBefore(t,e){return e?this.startOf(e).valueOf()<new r(t).startOf(e).valueOf():this.date.getTime()<l(t).getTime()}isAfter(t,e){return e?this.startOf(e).valueOf()>new r(t).startOf(e).valueOf():this.date.getTime()>l(t).getTime()}isSame(t,e){if(!e)return this.date.getTime()===l(t).getTime();let n=this.startOf(e),a=new r(t,this.config).startOf(e);return n.date.getTime()===a.date.getTime()}isSameOrBefore(t,e){return this.isSame(t,e)||this.isBefore(t,e)}isSameOrAfter(t,e){return this.isSame(t,e)||this.isAfter(t,e)}isBetween(t,e,n,a="()"){let s=n?new r(t).startOf(n).valueOf():l(t).getTime(),o=n?new r(e).startOf(n).valueOf():l(e).getTime(),i=n?this.startOf(n).valueOf():this.date.getTime(),c=a[0]==="["?i>=s:i>s,d=a[1]==="]"?i<=o:i<o;return c&&d}isToday(){return this.isSame(new Date,"day")}isTomorrow(){let t=new r().add(1,"day");return this.isSame(t.toDate(),"day")}isYesterday(){let t=new r().subtract(1,"day");return this.isSame(t.toDate(),"day")}isThisWeek(){return this.isSame(new Date,"week")}isThisMonth(){return this.isSame(new Date,"month")}isThisQuarter(){return this.isSame(new Date,"quarter")}isThisYear(){return this.isSame(new Date,"year")}isWeekend(){let t=this.date.getUTCDay();return t===0||t===6}isWeekday(){return!this.isWeekend()}isLeapYear(){let t=this.date.getUTCFullYear();return t%4===0&&t%100!==0||t%400===0}isDST(){let t=new Date(this.year(),0,1),e=new Date(this.year(),6,1),n=Math.max(t.getTimezoneOffset(),e.getTimezoneOffset());return this.date.getTimezoneOffset()<n}diff(t,e="millisecond",n=!1){let a=l(t),s=this.date.getTime()-a.getTime(),o=1;switch(e){case"millisecond":return s;case"second":o=1e3;break;case"minute":o=1e3*60;break;case"hour":o=1e3*60*60;break;case"day":o=1e3*60*60*24;break;case"week":o=1e3*60*60*24*7;break;case"month":return n?s/(1e3*60*60*24*30.436875):this.diffMonth(a);case"quarter":return n?s/(1e3*60*60*24*91.3125):Math.floor(this.diffMonth(a)/3);case"year":return n?s/(1e3*60*60*24*365.25):this.diffYear(a)}let i=s/o;return n?i:Math.floor(i)}diffMonth(t){let e=this.date.getUTCFullYear()-t.getUTCFullYear(),n=this.date.getUTCMonth()-t.getUTCMonth();return e*12+n}diffYear(t){return this.date.getUTCFullYear()-t.getUTCFullYear()}fromNow(t=!1){let e=Date.now()-this.date.getTime();return I(e,this.config.locale,t)}toNow(t=!1){let e=this.date.getTime()-Date.now();return I(e,this.config.locale,t)}from(t,e=!1){let n=l(t).getTime()-this.date.getTime();return I(n,this.config.locale,e)}to(t,e=!1){let n=this.date.getTime()-l(t).getTime();return I(n,this.config.locale,e)}calendar(t){let e=t?l(t):new Date;return H(this.date,e,this.config.locale)}duration(t){return t?f.between(this.date,l(t)):new f(this.date.getTime())}daysInMonth(){return new Date(Date.UTC(this.date.getUTCFullYear(),this.date.getUTCMonth()+1,0)).getUTCDate()}weeksInYear(){let t=new Date(Date.UTC(this.year(),11,31)),n=new r(t).isoWeek();return n===1?52:n}age(t){let e=t?l(t):new Date,n=this.date,a=e.getUTCFullYear()-n.getUTCFullYear(),s=n.getUTCMonth(),o=n.getUTCDate(),i=e.getUTCMonth(),c=e.getUTCDate();return(i<s||i===s&&c<o)&&a--,a}clone(){return new r(this.date,this.config)}isBusinessDay(t=[]){return O(this.date,t)}addBusinessDays(t,e=[]){return new r(F(this.date,t,e),this.config)}subtractBusinessDays(t,e=[]){return new r(F(this.date,-t,e),this.config)}businessDaysUntil(t,e=[]){return z(this.date,l(t),e)}locale(t){return t===void 0?this.config.locale:new r(this.date,{...this.config,locale:t})}static eachDayOfInterval(t){let e=new r(t.start),n=new r(t.end),a=[],s=e.clone();for(;s.isSameOrBefore(n.toDate(),"day");)a.push(s.clone()),s=s.add(1,"day");return a}static eachWeekOfInterval(t){let e=new r(t.start).startOf("week"),n=new r(t.end),a=[],s=e.clone();for(;s.isSameOrBefore(n.toDate(),"week");)a.push(s.clone()),s=s.add(1,"week");return a}static eachMonthOfInterval(t){let e=new r(t.start).startOf("month"),n=new r(t.end),a=[],s=e.clone();for(;s.isSameOrBefore(n.toDate(),"month");)a.push(s.clone()),s=s.add(1,"month");return a}static now(){return new r}static utc(t){return t?new r(t):new r(new Date)}static unix(t){return new r(t*1e3)}static isValid(t){try{return C(l(t))}catch{return!1}}static max(...t){let e=t.map(n=>l(n).getTime());return new r(Math.max(...e))}static min(...t){let e=t.map(n=>l(n).getTime());return new r(Math.min(...e))}static isDuration(t){return t instanceof f}static duration(t,e){return typeof t=="number"&&e?new f(t,e):new f(t)}};0&&(module.exports={DateKit,Duration,en,es,getLocale,registerLocale});
|
|
1
|
+
"use strict";var Y=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)Y(r,t,{get:e[t],enumerable:!0})},V=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Q(e))!J.call(r,a)&&a!==t&&Y(r,a,{get:()=>e[a],enumerable:!(n=Z(e,a))||n.enumerable});return r};var q=r=>V(Y({},"__esModule",{value:!0}),r);var G={};R(G,{DateKit:()=>w,Duration:()=>f,en:()=>L,es:()=>x,getLocale:()=>M,registerLocale:()=>v});module.exports=q(G);var L={name:"en",weekdays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],weekdaysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ordinal:r=>{let e=["th","st","nd","rd"],t=r%100;return r+(e[(t-20)%10]||e[t]||e[0])},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"}};var x={name:"es",weekdays:["Domingo","Lunes","Martes","Mi\xE9rcoles","Jueves","Viernes","S\xE1bado"],weekdaysShort:["Dom","Lun","Mar","Mi\xE9","Jue","Vie","S\xE1b"],weekdaysMin:["Do","Lu","Ma","Mi","Ju","Vi","S\xE1"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],ordinal:r=>`${r}\xBA`,relativeTime:{future:"en %s",past:"hace %s",s:"unos segundos",m:"un minuto",mm:"%d minutos",h:"una hora",hh:"%d horas",d:"un d\xEDa",dd:"%d d\xEDas",M:"un mes",MM:"%d meses",y:"un a\xF1o",yy:"%d a\xF1os"},calendar:{sameDay:"[Hoy a las] LT",nextDay:"[Ma\xF1ana a las] LT",nextWeek:"dddd [a las] LT",lastDay:"[Ayer a las] LT",lastWeek:"[El] dddd [pasado a las] LT",sameElse:"L"}};var K={en:L,es:x};function M(r){return K[r]||K.en}function v(r){K[r.name]=r}function E(r,e,t="en"){let n=M(t),a=r.getUTCFullYear(),s=r.getUTCMonth(),o=r.getUTCDate(),i=r.getUTCHours(),d=r.getUTCMinutes(),c=r.getUTCSeconds(),h=r.getUTCMilliseconds(),m=r.getUTCDay(),u=new Date(Date.UTC(a,0,1)),D=Math.floor((r.getTime()-u.getTime())/864e5)+1,g=Math.floor(s/3)+1,T=P(r),O=new Map,p=new Map,y={YYYY:a.toString(),YY:a.toString().slice(-2),Qo:n.ordinal(g),Q:g.toString(),MMMM:n.months[s],MMM:n.monthsShort[s],Mo:n.ordinal(s+1),MM:(s+1).toString().padStart(2,"0"),M:(s+1).toString(),Wo:n.ordinal(T),WW:T.toString().padStart(2,"0"),W:T.toString(),DDDo:n.ordinal(D),DDDD:D.toString().padStart(3,"0"),DDD:D.toString(),Do:n.ordinal(o),DD:o.toString().padStart(2,"0"),D:o.toString(),dddd:n.weekdays[m],ddd:n.weekdaysShort[m],do:n.ordinal(m),dd:n.weekdaysMin[m],d:m.toString(),HH:i.toString().padStart(2,"0"),H:i.toString(),hh:(i%12||12).toString().padStart(2,"0"),h:(i%12||12).toString(),mm:d.toString().padStart(2,"0"),m:d.toString(),ss:c.toString().padStart(2,"0"),s:c.toString(),SSS:h.toString().padStart(3,"0"),SS:h.toString().padStart(2,"0").slice(0,2),S:Math.floor(h/100).toString(),A:i>=12?"PM":"AM",a:i>=12?"pm":"am",Z:H(r.getTimezoneOffset()),ZZ:H(r.getTimezoneOffset()).replace(":",""),X:Math.floor(r.getTime()/1e3).toString(),x:r.getTime().toString()},S=e;return Object.keys(y).sort((b,U)=>U.length-b.length).forEach((b,U)=>{let W=`\0${U}\0`,B=new RegExp(b,"g");S=S.replace(B,W),p.set(W,y[b])}),p.forEach((b,U)=>{S=S.replace(new RegExp(U,"g"),b)}),S}function P(r){let e=new Date(r.getTime());e.setUTCHours(0,0,0,0),e.setUTCDate(e.getUTCDate()+4-(e.getUTCDay()||7));let t=new Date(Date.UTC(e.getUTCFullYear(),0,1));return Math.ceil(((e.getTime()-t.getTime())/864e5+1)/7)}function H(r){let e=r<=0?"+":"-",t=Math.abs(r),n=Math.floor(t/60),a=t%60;return`${e}${n.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function l(r){if(r instanceof Date)return new Date(r);if(typeof r=="number")return new Date(r);if(typeof r=="string")return new Date(r);throw new Error("Invalid date input")}function C(r){return r instanceof Date&&!isNaN(r.getTime())}function I(r,e="en",t=!1){let n=M(e),a=r<0,o=Math.abs(r)/1e3,i=o/60,d=i/60,c=d/24,h=c/30.44,m=c/365.25,u;return o<45?u=n.relativeTime.s:o<90?u=n.relativeTime.m:i<45?u=n.relativeTime.mm.replace("%d",Math.round(i).toString()):i<90?u=n.relativeTime.h:d<22?u=n.relativeTime.hh.replace("%d",Math.round(d).toString()):d<36?u=n.relativeTime.d:c<25?u=n.relativeTime.dd.replace("%d",Math.round(c).toString()):c<45?u=n.relativeTime.M:c<345?u=n.relativeTime.MM.replace("%d",Math.round(h).toString()):m<1.5?u=n.relativeTime.y:u=n.relativeTime.yy.replace("%d",Math.round(m).toString()),t?u:(a?n.relativeTime.future:n.relativeTime.past).replace("%s",u)}function A(r,e=new Date,t="en"){let n=M(t),a=new w(r),s=new w(e),o=a.startOf("day").diff(s.startOf("day").toDate(),"day"),i;return o===0?i=n.calendar.sameDay:o===1?i=n.calendar.nextDay:o===-1?i=n.calendar.lastDay:o>1&&o<=7?i=n.calendar.nextWeek:o<-1&&o>=-7?i=n.calendar.lastWeek:i=n.calendar.sameElse,i=i.replace("[","").replace("]","").replace("LT",a.format("HH:mm")).replace("L",a.format("MM/DD/YYYY")).replace("dddd",n.weekdays[r.getUTCDay()]),i}var z=[1,2,3,4,5];function k(r,e=[]){let t=r.getUTCDay();if(!z.includes(t))return!1;let n=r.toISOString().split("T")[0];return!e.some(a=>a.toISOString().split("T")[0]===n)}function F(r,e,t=[]){let n=new Date(r),a=Math.abs(e),s=e>0?1:-1;for(;a>0;)n.setUTCDate(n.getUTCDate()+s),k(n,t)&&a--;return n}function $(r,e,t=[]){let n=0,a=new Date(r),s=new Date(e);for(;a<=s;)k(a,t)&&n++,a.setUTCDate(a.getUTCDate()+1);return n}var f=class r{constructor(e,t="milliseconds"){typeof e=="number"?this._milliseconds=this.convertToMilliseconds(e,t):this._milliseconds=this.objectToMilliseconds(e)}convertToMilliseconds(e,t){return e*({milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5}[t]||1)}objectToMilliseconds(e){let t=0;return e.years&&(t+=e.years*365.25*864e5),e.months&&(t+=e.months*30.44*864e5),e.weeks&&(t+=e.weeks*6048e5),e.days&&(t+=e.days*864e5),e.hours&&(t+=e.hours*36e5),e.minutes&&(t+=e.minutes*6e4),e.seconds&&(t+=e.seconds*1e3),e.milliseconds&&(t+=e.milliseconds),t}asMilliseconds(){return this._milliseconds}asSeconds(){return this._milliseconds/1e3}asMinutes(){return this._milliseconds/6e4}asHours(){return this._milliseconds/36e5}asDays(){return this._milliseconds/864e5}asWeeks(){return this._milliseconds/6048e5}asMonths(){return this._milliseconds/(30.44*864e5)}asYears(){return this._milliseconds/(365.25*864e5)}humanize(e="en"){let t=Math.abs(this.asSeconds()),n=Math.abs(this.asMinutes()),a=Math.abs(this.asHours()),s=Math.abs(this.asDays()),o=Math.abs(this.asMonths()),i=Math.abs(this.asYears());return t<45?"a few seconds":t<90?"a minute":n<45?`${Math.round(n)} minutes`:n<90?"an hour":a<22?`${Math.round(a)} hours`:a<36?"a day":s<25?`${Math.round(s)} days`:s<45?"a month":s<345?`${Math.round(o)} months`:i<1.5?"a year":`${Math.round(i)} years`}toObject(){let e=Math.abs(this._milliseconds),t=Math.floor(e/(365.25*864e5));e-=t*365.25*864e5;let n=Math.floor(e/(30.44*864e5));e-=n*30.44*864e5;let a=Math.floor(e/864e5);e-=a*864e5;let s=Math.floor(e/36e5);e-=s*36e5;let o=Math.floor(e/6e4);e-=o*6e4;let i=Math.floor(e/1e3);e-=i*1e3;let d=Math.floor(e);return{years:t,months:n,days:a,hours:s,minutes:o,seconds:i,milliseconds:d}}add(e){return new r(this._milliseconds+e.asMilliseconds())}subtract(e){return new r(this._milliseconds-e.asMilliseconds())}static between(e,t){return new r(Math.abs(t.getTime()-e.getTime()))}};var w=class r{constructor(e,t){if(this.config={locale:"en",weekStartsOn:0,strictParsing:!1,...t},this.date=e?l(e):new Date,!C(this.date))throw new Error("Invalid date provided")}toDate(){return new Date(this.date)}toISOString(){return this.date.toISOString()}toUnix(){return Math.floor(this.date.getTime()/1e3)}valueOf(){return this.date.getTime()}toArray(){return[this.date.getUTCFullYear(),this.date.getUTCMonth(),this.date.getUTCDate(),this.date.getUTCHours(),this.date.getUTCMinutes(),this.date.getUTCSeconds(),this.date.getUTCMilliseconds()]}toObject(){return{year:this.date.getUTCFullYear(),month:this.date.getUTCMonth(),date:this.date.getUTCDate(),hour:this.date.getUTCHours(),minute:this.date.getUTCMinutes(),second:this.date.getUTCSeconds(),millisecond:this.date.getUTCMilliseconds()}}toJSON(){return this.toISOString()}toString(){return this.date.toString()}format(e){return E(this.date,e,this.config.locale)}static formatFromTimezoneString(e,t){let n,a;if(e instanceof Date?(a=e,n=e.toString()):typeof e=="number"?(a=new Date(e),n=a.toString()):(n=e,a=new Date(e)),isNaN(a.getTime()))throw new Error("Invalid date provided");let s=n.match(/GMT([+-]\d{2}):?(\d{2})|UTC([+-]\d{2}):?(\d{2})/i),o=0;if(s){let y=(s[1]||s[3])[0],S=parseInt((s[1]||s[3]).substring(1)),N=parseInt(s[2]||s[4]||"0");o=(S*60+N)*(y==="+"?1:-1)}else o=-a.getTimezoneOffset();let d=a.getTime()+o*60*1e3,c=new Date(d),h=c.getUTCFullYear(),m=c.getUTCMonth(),u=c.getUTCDate(),D=c.getUTCHours(),g=c.getUTCMinutes(),T=c.getUTCSeconds(),O=c.getUTCMilliseconds();return new r(Date.UTC(h,m,u,D,g,T,O)).format(t)}static formatZonedDate(e,t="DD-MM-YYYY",n="en"){let a,s;if(e instanceof Date?(s=e,a=e.toString()):typeof e=="number"?(s=new Date(e),a=s.toString()):(a=e,s=new Date(e)),isNaN(s.getTime()))throw new Error("Invalid date input for formatZonedDate");let o=a.match(/GMT([+-])(\d{2}):?(\d{2})/i),i=s;if(o){let d=o[1]==="-"?-1:1,c=parseInt(o[2],10),h=parseInt(o[3],10),m=d*(c*60+h),u=s.getTime()+m*6e4;i=new Date(u)}return E(i,t,n)}formatZonedDate(e,t="DD-MM-YYYY"){let n=this.config?.locale??"en";return r.formatZonedDate(e,t,n)}static convertTimezone(e,t,n,a){let s=l(e);if(!C(s))throw new Error("Invalid date provided");let o,i,d,c,h,m;if(typeof e=="string"&&!e.includes("Z")&&!e.includes("+")&&!e.includes("GMT")){let u=e.match(/(\d{4})-(\d{2})-(\d{2})[T\s](\d{2}):(\d{2}):(\d{2})/);u?(o=parseInt(u[1]),i=parseInt(u[2]),d=parseInt(u[3]),c=parseInt(u[4]),h=parseInt(u[5]),m=parseInt(u[6])):(o=s.getUTCFullYear(),i=s.getUTCMonth()+1,d=s.getUTCDate(),c=s.getUTCHours(),h=s.getUTCMinutes(),m=s.getUTCSeconds());let D=`${o}-${i.toString().padStart(2,"0")}-${d.toString().padStart(2,"0")}T${c.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}:${m.toString().padStart(2,"0")}`,g=new Date(Date.UTC(o,i-1,d,c,h,m)),T=new Date(g.toLocaleString("en-US",{timeZone:t})),O=new Date(g.toLocaleString("en-US",{timeZone:"UTC"})),p=T.getTime()-O.getTime(),y=g.getTime()-p,S=new Date(y);return r.formatInTimezone(S,n,a)}else return r.formatInTimezone(s,n,a)}static formatInTimezone(e,t,n){let a=l(e);if(!C(a))throw new Error("Invalid date provided");let o=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(a),i={};return o.forEach(c=>{c.type!=="literal"&&(i[c.type]=c.value)}),new r(Date.UTC(parseInt(i.year),parseInt(i.month)-1,parseInt(i.day),parseInt(i.hour),parseInt(i.minute),parseInt(i.second))).format(n)}static fromTimezone(e,t,n,a=0,s=0,o=0,i="UTC"){let d=`${e}-${t.toString().padStart(2,"0")}-${n.toString().padStart(2,"0")}T${a.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}`,c=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),h=new Date(d),m=new Date(Date.UTC(e,t-1,n,a,s,o)),u=new Date(m.toLocaleString("en-US",{timeZone:i})),D=new Date(m.toLocaleString("en-US",{timeZone:"UTC"})),g=u.getTime()-D.getTime(),T=m.getTime()-g;return new r(T)}static getTimezoneOffset(e,t=new Date){let n=new Date(t.toLocaleString("en-US",{timeZone:"UTC"}));return(new Date(t.toLocaleString("en-US",{timeZone:e})).getTime()-n.getTime())/6e4}year(){return this.date.getUTCFullYear()}month(){return this.date.getUTCMonth()}getDate(){return this.date.getUTCDate()}day(){return this.date.getUTCDay()}hour(){return this.date.getUTCHours()}minute(){return this.date.getUTCMinutes()}second(){return this.date.getUTCSeconds()}millisecond(){return this.date.getUTCMilliseconds()}quarter(){return Math.floor(this.date.getUTCMonth()/3)+1}week(){return this.isoWeek()}isoWeek(){let e=new Date(this.date.getTime());e.setUTCHours(0,0,0,0),e.setUTCDate(e.getUTCDate()+4-(e.getUTCDay()||7));let t=new Date(Date.UTC(e.getUTCFullYear(),0,1));return Math.ceil(((e.getTime()-t.getTime())/864e5+1)/7)}weekday(){return(this.date.getUTCDay()+7-this.config.weekStartsOn)%7}isoWeekday(){return this.date.getUTCDay()||7}dayOfYear(){let e=new Date(Date.UTC(this.date.getUTCFullYear(),0,1));return Math.floor((this.date.getTime()-e.getTime())/864e5)+1}weekYear(){let e=new Date(this.date.getTime());return e.setUTCDate(e.getUTCDate()+4-(e.getUTCDay()||7)),e.getUTCFullYear()}set(e){let t=new Date(this.date);return e.year!==void 0&&t.setUTCFullYear(e.year),e.month!==void 0&&t.setUTCMonth(e.month),e.date!==void 0&&t.setUTCDate(e.date),e.hour!==void 0&&t.setUTCHours(e.hour),e.minute!==void 0&&t.setUTCMinutes(e.minute),e.second!==void 0&&t.setUTCSeconds(e.second),e.millisecond!==void 0&&t.setUTCMilliseconds(e.millisecond),new r(t,this.config)}setYear(e){return this.set({year:e})}setMonth(e){return this.set({month:e})}setDate(e){return this.set({date:e})}setHour(e){return this.set({hour:e})}setMinute(e){return this.set({minute:e})}setSecond(e){return this.set({second:e})}setMillisecond(e){return this.set({millisecond:e})}setQuarter(e){let t=(e-1)*3;return this.set({month:t})}add(e,t){let n=new Date(this.date);switch(t){case"millisecond":n.setUTCMilliseconds(n.getUTCMilliseconds()+e);break;case"second":n.setUTCSeconds(n.getUTCSeconds()+e);break;case"minute":n.setUTCMinutes(n.getUTCMinutes()+e);break;case"hour":n.setUTCHours(n.getUTCHours()+e);break;case"day":n.setUTCDate(n.getUTCDate()+e);break;case"week":n.setUTCDate(n.getUTCDate()+e*7);break;case"month":n.setUTCMonth(n.getUTCMonth()+e);break;case"quarter":n.setUTCMonth(n.getUTCMonth()+e*3);break;case"year":n.setUTCFullYear(n.getUTCFullYear()+e);break}return new r(n,this.config)}subtract(e,t){return this.add(-e,t)}startOf(e){let t=new Date(this.date);switch(e){case"year":t.setUTCMonth(0);case"quarter":if(e==="quarter"){let s=this.quarter();t.setUTCMonth((s-1)*3)}case"month":t.setUTCDate(1);case"day":t.setUTCHours(0);case"hour":t.setUTCMinutes(0);case"minute":t.setUTCSeconds(0);case"second":t.setUTCMilliseconds(0);break;case"week":let n=t.getUTCDay(),a=(n<this.config.weekStartsOn?7:0)+n-this.config.weekStartsOn;t.setUTCDate(t.getUTCDate()-a),t.setUTCHours(0,0,0,0);break}return new r(t,this.config)}endOf(e){return this.startOf(e).add(1,e).subtract(1,"millisecond")}isBefore(e,t){return t?this.startOf(t).valueOf()<new r(e).startOf(t).valueOf():this.date.getTime()<l(e).getTime()}isAfter(e,t){return t?this.startOf(t).valueOf()>new r(e).startOf(t).valueOf():this.date.getTime()>l(e).getTime()}isSame(e,t){if(!t)return this.date.getTime()===l(e).getTime();let n=this.startOf(t),a=new r(e,this.config).startOf(t);return n.date.getTime()===a.date.getTime()}isSameOrBefore(e,t){return this.isSame(e,t)||this.isBefore(e,t)}isSameOrAfter(e,t){return this.isSame(e,t)||this.isAfter(e,t)}isBetween(e,t,n,a="()"){let s=n?new r(e).startOf(n).valueOf():l(e).getTime(),o=n?new r(t).startOf(n).valueOf():l(t).getTime(),i=n?this.startOf(n).valueOf():this.date.getTime(),d=a[0]==="["?i>=s:i>s,c=a[1]==="]"?i<=o:i<o;return d&&c}isToday(){return this.isSame(new Date,"day")}isTomorrow(){let e=new r().add(1,"day");return this.isSame(e.toDate(),"day")}isYesterday(){let e=new r().subtract(1,"day");return this.isSame(e.toDate(),"day")}isThisWeek(){return this.isSame(new Date,"week")}isThisMonth(){return this.isSame(new Date,"month")}isThisQuarter(){return this.isSame(new Date,"quarter")}isThisYear(){return this.isSame(new Date,"year")}isWeekend(){let e=this.date.getUTCDay();return e===0||e===6}isWeekday(){return!this.isWeekend()}isLeapYear(){let e=this.date.getUTCFullYear();return e%4===0&&e%100!==0||e%400===0}isDST(){let e=new Date(this.year(),0,1),t=new Date(this.year(),6,1),n=Math.max(e.getTimezoneOffset(),t.getTimezoneOffset());return this.date.getTimezoneOffset()<n}diff(e,t="millisecond",n=!1){let a=l(e),s=this.date.getTime()-a.getTime(),o=1;switch(t){case"millisecond":return s;case"second":o=1e3;break;case"minute":o=1e3*60;break;case"hour":o=1e3*60*60;break;case"day":o=1e3*60*60*24;break;case"week":o=1e3*60*60*24*7;break;case"month":return n?s/(1e3*60*60*24*30.436875):this.diffMonth(a);case"quarter":return n?s/(1e3*60*60*24*91.3125):Math.floor(this.diffMonth(a)/3);case"year":return n?s/(1e3*60*60*24*365.25):this.diffYear(a)}let i=s/o;return n?i:Math.floor(i)}diffMonth(e){let t=this.date.getUTCFullYear()-e.getUTCFullYear(),n=this.date.getUTCMonth()-e.getUTCMonth();return t*12+n}diffYear(e){return this.date.getUTCFullYear()-e.getUTCFullYear()}fromNow(e=!1){let t=Date.now()-this.date.getTime();return I(t,this.config.locale,e)}toNow(e=!1){let t=this.date.getTime()-Date.now();return I(t,this.config.locale,e)}from(e,t=!1){let n=l(e).getTime()-this.date.getTime();return I(n,this.config.locale,t)}to(e,t=!1){let n=this.date.getTime()-l(e).getTime();return I(n,this.config.locale,t)}calendar(e){let t=e?l(e):new Date;return A(this.date,t,this.config.locale)}duration(e){return e?f.between(this.date,l(e)):new f(this.date.getTime())}daysInMonth(){return new Date(Date.UTC(this.date.getUTCFullYear(),this.date.getUTCMonth()+1,0)).getUTCDate()}weeksInYear(){let e=new Date(Date.UTC(this.year(),11,31)),n=new r(e).isoWeek();return n===1?52:n}age(e){let t=e?l(e):new Date,n=this.date,a=t.getUTCFullYear()-n.getUTCFullYear(),s=n.getUTCMonth(),o=n.getUTCDate(),i=t.getUTCMonth(),d=t.getUTCDate();return(i<s||i===s&&d<o)&&a--,a}clone(){return new r(this.date,this.config)}isBusinessDay(e=[]){return k(this.date,e)}addBusinessDays(e,t=[]){return new r(F(this.date,e,t),this.config)}subtractBusinessDays(e,t=[]){return new r(F(this.date,-e,t),this.config)}businessDaysUntil(e,t=[]){return $(this.date,l(e),t)}locale(e){return e===void 0?this.config.locale:new r(this.date,{...this.config,locale:e})}static eachDayOfInterval(e){let t=new r(e.start),n=new r(e.end),a=[],s=t.clone();for(;s.isSameOrBefore(n.toDate(),"day");)a.push(s.clone()),s=s.add(1,"day");return a}static eachWeekOfInterval(e){let t=new r(e.start).startOf("week"),n=new r(e.end),a=[],s=t.clone();for(;s.isSameOrBefore(n.toDate(),"week");)a.push(s.clone()),s=s.add(1,"week");return a}static eachMonthOfInterval(e){let t=new r(e.start).startOf("month"),n=new r(e.end),a=[],s=t.clone();for(;s.isSameOrBefore(n.toDate(),"month");)a.push(s.clone()),s=s.add(1,"month");return a}static now(){return new r}static utc(e){return e?new r(e):new r(new Date)}static unix(e){return new r(e*1e3)}static isValid(e){try{return C(l(e))}catch{return!1}}static max(...e){let t=e.map(n=>l(n).getTime());return new r(Math.max(...t))}static min(...e){let t=e.map(n=>l(n).getTime());return new r(Math.min(...t))}static isDuration(e){return e instanceof f}static duration(e,t){return typeof e=="number"&&t?new f(e,t):new f(e)}};0&&(module.exports={DateKit,Duration,en,es,getLocale,registerLocale});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var E={name:"en",weekdays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],weekdaysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ordinal:r=>{let t=["th","st","nd","rd"],e=r%100;return r+(t[(e-20)%10]||t[e]||t[0])},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"}};var F={name:"es",weekdays:["Domingo","Lunes","Martes","Mi\xE9rcoles","Jueves","Viernes","S\xE1bado"],weekdaysShort:["Dom","Lun","Mar","Mi\xE9","Jue","Vie","S\xE1b"],weekdaysMin:["Do","Lu","Ma","Mi","Ju","Vi","S\xE1"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],ordinal:r=>`${r}\xBA`,relativeTime:{future:"en %s",past:"hace %s",s:"unos segundos",m:"un minuto",mm:"%d minutos",h:"una hora",hh:"%d horas",d:"un d\xEDa",dd:"%d d\xEDas",M:"un mes",MM:"%d meses",y:"un a\xF1o",yy:"%d a\xF1os"},calendar:{sameDay:"[Hoy a las] LT",nextDay:"[Ma\xF1ana a las] LT",nextWeek:"dddd [a las] LT",lastDay:"[Ayer a las] LT",lastWeek:"[El] dddd [pasado a las] LT",sameElse:"L"}};var Y={en:E,es:F};function M(r){return Y[r]||Y.en}function z(r){Y[r.name]=r}function L(r,t,e="en"){let n=M(e),a=r.getUTCFullYear(),s=r.getUTCMonth(),o=r.getUTCDate(),i=r.getUTCHours(),c=r.getUTCMinutes(),d=r.getUTCSeconds(),h=r.getUTCMilliseconds(),m=r.getUTCDay(),u=new Date(Date.UTC(a,0,1)),f=Math.floor((r.getTime()-u.getTime())/864e5)+1,g=Math.floor(s/3)+1,D=$(r),k=new Map,p=new Map,w={YYYY:a.toString(),YY:a.toString().slice(-2),Qo:n.ordinal(g),Q:g.toString(),MMMM:n.months[s],MMM:n.monthsShort[s],Mo:n.ordinal(s+1),MM:(s+1).toString().padStart(2,"0"),M:(s+1).toString(),Wo:n.ordinal(D),WW:D.toString().padStart(2,"0"),W:D.toString(),DDDo:n.ordinal(f),DDDD:f.toString().padStart(3,"0"),DDD:f.toString(),Do:n.ordinal(o),DD:o.toString().padStart(2,"0"),D:o.toString(),dddd:n.weekdays[m],ddd:n.weekdaysShort[m],do:n.ordinal(m),dd:n.weekdaysMin[m],d:m.toString(),HH:i.toString().padStart(2,"0"),H:i.toString(),hh:(i%12||12).toString().padStart(2,"0"),h:(i%12||12).toString(),mm:c.toString().padStart(2,"0"),m:c.toString(),ss:d.toString().padStart(2,"0"),s:d.toString(),SSS:h.toString().padStart(3,"0"),SS:h.toString().padStart(2,"0").slice(0,2),S:Math.floor(h/100).toString(),A:i>=12?"PM":"AM",a:i>=12?"pm":"am",Z:N(r.getTimezoneOffset()),ZZ:N(r.getTimezoneOffset()).replace(":",""),X:Math.floor(r.getTime()/1e3).toString(),x:r.getTime().toString()},T=t;return Object.keys(w).sort((y,U)=>U.length-y.length).forEach((y,U)=>{let K=`\0${U}\0`,A=new RegExp(y,"g");T=T.replace(A,K),p.set(K,w[y])}),p.forEach((y,U)=>{T=T.replace(new RegExp(U,"g"),y)}),T}function $(r){let t=new Date(r.getTime());t.setUTCHours(0,0,0,0),t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));let e=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-e.getTime())/864e5+1)/7)}function N(r){let t=r<=0?"+":"-",e=Math.abs(r),n=Math.floor(e/60),a=e%60;return`${t}${n.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function l(r){if(r instanceof Date)return new Date(r);if(typeof r=="number")return new Date(r);if(typeof r=="string")return new Date(r);throw new Error("Invalid date input")}function C(r){return r instanceof Date&&!isNaN(r.getTime())}function I(r,t="en",e=!1){let n=M(t),a=r<0,o=Math.abs(r)/1e3,i=o/60,c=i/60,d=c/24,h=d/30.44,m=d/365.25,u;return o<45?u=n.relativeTime.s:o<90?u=n.relativeTime.m:i<45?u=n.relativeTime.mm.replace("%d",Math.round(i).toString()):i<90?u=n.relativeTime.h:c<22?u=n.relativeTime.hh.replace("%d",Math.round(c).toString()):c<36?u=n.relativeTime.d:d<25?u=n.relativeTime.dd.replace("%d",Math.round(d).toString()):d<45?u=n.relativeTime.M:d<345?u=n.relativeTime.MM.replace("%d",Math.round(h).toString()):m<1.5?u=n.relativeTime.y:u=n.relativeTime.yy.replace("%d",Math.round(m).toString()),e?u:(a?n.relativeTime.future:n.relativeTime.past).replace("%s",u)}function W(r,t=new Date,e="en"){let n=M(e),a=new b(r),s=new b(t),o=a.startOf("day").diff(s.startOf("day").toDate(),"day"),i;return o===0?i=n.calendar.sameDay:o===1?i=n.calendar.nextDay:o===-1?i=n.calendar.lastDay:o>1&&o<=7?i=n.calendar.nextWeek:o<-1&&o>=-7?i=n.calendar.lastWeek:i=n.calendar.sameElse,i=i.replace("[","").replace("]","").replace("LT",a.format("HH:mm")).replace("L",a.format("MM/DD/YYYY")).replace("dddd",n.weekdays[r.getUTCDay()]),i}var v=[1,2,3,4,5];function O(r,t=[]){let e=r.getUTCDay();if(!v.includes(e))return!1;let n=r.toISOString().split("T")[0];return!t.some(a=>a.toISOString().split("T")[0]===n)}function x(r,t,e=[]){let n=new Date(r),a=Math.abs(t),s=t>0?1:-1;for(;a>0;)n.setUTCDate(n.getUTCDate()+s),O(n,e)&&a--;return n}function H(r,t,e=[]){let n=0,a=new Date(r),s=new Date(t);for(;a<=s;)O(a,e)&&n++,a.setUTCDate(a.getUTCDate()+1);return n}var S=class r{constructor(t,e="milliseconds"){typeof t=="number"?this._milliseconds=this.convertToMilliseconds(t,e):this._milliseconds=this.objectToMilliseconds(t)}convertToMilliseconds(t,e){return t*({milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5}[e]||1)}objectToMilliseconds(t){let e=0;return t.years&&(e+=t.years*365.25*864e5),t.months&&(e+=t.months*30.44*864e5),t.weeks&&(e+=t.weeks*6048e5),t.days&&(e+=t.days*864e5),t.hours&&(e+=t.hours*36e5),t.minutes&&(e+=t.minutes*6e4),t.seconds&&(e+=t.seconds*1e3),t.milliseconds&&(e+=t.milliseconds),e}asMilliseconds(){return this._milliseconds}asSeconds(){return this._milliseconds/1e3}asMinutes(){return this._milliseconds/6e4}asHours(){return this._milliseconds/36e5}asDays(){return this._milliseconds/864e5}asWeeks(){return this._milliseconds/6048e5}asMonths(){return this._milliseconds/(30.44*864e5)}asYears(){return this._milliseconds/(365.25*864e5)}humanize(t="en"){let e=Math.abs(this.asSeconds()),n=Math.abs(this.asMinutes()),a=Math.abs(this.asHours()),s=Math.abs(this.asDays()),o=Math.abs(this.asMonths()),i=Math.abs(this.asYears());return e<45?"a few seconds":e<90?"a minute":n<45?`${Math.round(n)} minutes`:n<90?"an hour":a<22?`${Math.round(a)} hours`:a<36?"a day":s<25?`${Math.round(s)} days`:s<45?"a month":s<345?`${Math.round(o)} months`:i<1.5?"a year":`${Math.round(i)} years`}toObject(){let t=Math.abs(this._milliseconds),e=Math.floor(t/(365.25*864e5));t-=e*365.25*864e5;let n=Math.floor(t/(30.44*864e5));t-=n*30.44*864e5;let a=Math.floor(t/864e5);t-=a*864e5;let s=Math.floor(t/36e5);t-=s*36e5;let o=Math.floor(t/6e4);t-=o*6e4;let i=Math.floor(t/1e3);t-=i*1e3;let c=Math.floor(t);return{years:e,months:n,days:a,hours:s,minutes:o,seconds:i,milliseconds:c}}add(t){return new r(this._milliseconds+t.asMilliseconds())}subtract(t){return new r(this._milliseconds-t.asMilliseconds())}static between(t,e){return new r(Math.abs(e.getTime()-t.getTime()))}};var b=class r{constructor(t,e){if(this.config={locale:"en",weekStartsOn:0,strictParsing:!1,...e},this.date=t?l(t):new Date,!C(this.date))throw new Error("Invalid date provided")}toDate(){return new Date(this.date)}toISOString(){return this.date.toISOString()}toUnix(){return Math.floor(this.date.getTime()/1e3)}valueOf(){return this.date.getTime()}toArray(){return[this.date.getUTCFullYear(),this.date.getUTCMonth(),this.date.getUTCDate(),this.date.getUTCHours(),this.date.getUTCMinutes(),this.date.getUTCSeconds(),this.date.getUTCMilliseconds()]}toObject(){return{year:this.date.getUTCFullYear(),month:this.date.getUTCMonth(),date:this.date.getUTCDate(),hour:this.date.getUTCHours(),minute:this.date.getUTCMinutes(),second:this.date.getUTCSeconds(),millisecond:this.date.getUTCMilliseconds()}}toJSON(){return this.toISOString()}toString(){return this.date.toString()}format(t){return L(this.date,t,this.config.locale)}static formatFromTimezoneString(t,e){let n=new Date(t);if(isNaN(n.getTime()))throw new Error("Invalid date string provided");let a=t.match(/GMT([+-]\d{2}):?(\d{2})|UTC([+-]\d{2}):?(\d{2})/i),s=0;if(a){let p=(a[1]||a[3])[0],w=parseInt((a[1]||a[3]).substring(1)),T=parseInt(a[2]||a[4]||"0");s=(w*60+T)*(p==="+"?1:-1)}else s=-n.getTimezoneOffset();let i=n.getTime()+s*60*1e3,c=new Date(i),d=c.getUTCFullYear(),h=c.getUTCMonth(),m=c.getUTCDate(),u=c.getUTCHours(),f=c.getUTCMinutes(),g=c.getUTCSeconds(),D=c.getUTCMilliseconds();return new r(Date.UTC(d,h,m,u,f,g,D)).format(e)}static formatZonedDate(t,e="DD-MM-YYYY",n="en"){if(typeof t!="string")throw new Error("formatZonedDate expects input as a string with explicit GMT offset");let a=t.match(/GMT([+-])(\d{2}):?(\d{2})/i),s=new Date(t);if(isNaN(s.getTime()))throw new Error("Invalid date input for formatZonedDate");let o=s;if(a){let i=a[1]==="-"?-1:1,c=parseInt(a[2],10),d=parseInt(a[3],10),h=i*(c*60+d),m=s.getTime()+h*6e4;o=new Date(m)}return L(o,e,n)}formatZonedDate(t,e="DD-MM-YYYY"){let n=this.config?.locale??"en";return r.formatZonedDate(t,e,n)}static convertTimezone(t,e,n,a){let s=l(t);if(!C(s))throw new Error("Invalid date provided");let o,i,c,d,h,m;if(typeof t=="string"&&!t.includes("Z")&&!t.includes("+")&&!t.includes("GMT")){let u=t.match(/(\d{4})-(\d{2})-(\d{2})[T\s](\d{2}):(\d{2}):(\d{2})/);u?(o=parseInt(u[1]),i=parseInt(u[2]),c=parseInt(u[3]),d=parseInt(u[4]),h=parseInt(u[5]),m=parseInt(u[6])):(o=s.getUTCFullYear(),i=s.getUTCMonth()+1,c=s.getUTCDate(),d=s.getUTCHours(),h=s.getUTCMinutes(),m=s.getUTCSeconds());let f=`${o}-${i.toString().padStart(2,"0")}-${c.toString().padStart(2,"0")}T${d.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}:${m.toString().padStart(2,"0")}`,g=new Date(Date.UTC(o,i-1,c,d,h,m)),D=new Date(g.toLocaleString("en-US",{timeZone:e})),k=new Date(g.toLocaleString("en-US",{timeZone:"UTC"})),p=D.getTime()-k.getTime(),w=g.getTime()-p,T=new Date(w);return r.formatInTimezone(T,n,a)}else return r.formatInTimezone(s,n,a)}static formatInTimezone(t,e,n){let a=l(t);if(!C(a))throw new Error("Invalid date provided");let o=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(a),i={};return o.forEach(d=>{d.type!=="literal"&&(i[d.type]=d.value)}),new r(Date.UTC(parseInt(i.year),parseInt(i.month)-1,parseInt(i.day),parseInt(i.hour),parseInt(i.minute),parseInt(i.second))).format(n)}static fromTimezone(t,e,n,a=0,s=0,o=0,i="UTC"){let c=`${t}-${e.toString().padStart(2,"0")}-${n.toString().padStart(2,"0")}T${a.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}`,d=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),h=new Date(c),m=new Date(Date.UTC(t,e-1,n,a,s,o)),u=new Date(m.toLocaleString("en-US",{timeZone:i})),f=new Date(m.toLocaleString("en-US",{timeZone:"UTC"})),g=u.getTime()-f.getTime(),D=m.getTime()-g;return new r(D)}static getTimezoneOffset(t,e=new Date){let n=new Date(e.toLocaleString("en-US",{timeZone:"UTC"}));return(new Date(e.toLocaleString("en-US",{timeZone:t})).getTime()-n.getTime())/6e4}year(){return this.date.getUTCFullYear()}month(){return this.date.getUTCMonth()}getDate(){return this.date.getUTCDate()}day(){return this.date.getUTCDay()}hour(){return this.date.getUTCHours()}minute(){return this.date.getUTCMinutes()}second(){return this.date.getUTCSeconds()}millisecond(){return this.date.getUTCMilliseconds()}quarter(){return Math.floor(this.date.getUTCMonth()/3)+1}week(){return this.isoWeek()}isoWeek(){let t=new Date(this.date.getTime());t.setUTCHours(0,0,0,0),t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));let e=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-e.getTime())/864e5+1)/7)}weekday(){return(this.date.getUTCDay()+7-this.config.weekStartsOn)%7}isoWeekday(){return this.date.getUTCDay()||7}dayOfYear(){let t=new Date(Date.UTC(this.date.getUTCFullYear(),0,1));return Math.floor((this.date.getTime()-t.getTime())/864e5)+1}weekYear(){let t=new Date(this.date.getTime());return t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7)),t.getUTCFullYear()}set(t){let e=new Date(this.date);return t.year!==void 0&&e.setUTCFullYear(t.year),t.month!==void 0&&e.setUTCMonth(t.month),t.date!==void 0&&e.setUTCDate(t.date),t.hour!==void 0&&e.setUTCHours(t.hour),t.minute!==void 0&&e.setUTCMinutes(t.minute),t.second!==void 0&&e.setUTCSeconds(t.second),t.millisecond!==void 0&&e.setUTCMilliseconds(t.millisecond),new r(e,this.config)}setYear(t){return this.set({year:t})}setMonth(t){return this.set({month:t})}setDate(t){return this.set({date:t})}setHour(t){return this.set({hour:t})}setMinute(t){return this.set({minute:t})}setSecond(t){return this.set({second:t})}setMillisecond(t){return this.set({millisecond:t})}setQuarter(t){let e=(t-1)*3;return this.set({month:e})}add(t,e){let n=new Date(this.date);switch(e){case"millisecond":n.setUTCMilliseconds(n.getUTCMilliseconds()+t);break;case"second":n.setUTCSeconds(n.getUTCSeconds()+t);break;case"minute":n.setUTCMinutes(n.getUTCMinutes()+t);break;case"hour":n.setUTCHours(n.getUTCHours()+t);break;case"day":n.setUTCDate(n.getUTCDate()+t);break;case"week":n.setUTCDate(n.getUTCDate()+t*7);break;case"month":n.setUTCMonth(n.getUTCMonth()+t);break;case"quarter":n.setUTCMonth(n.getUTCMonth()+t*3);break;case"year":n.setUTCFullYear(n.getUTCFullYear()+t);break}return new r(n,this.config)}subtract(t,e){return this.add(-t,e)}startOf(t){let e=new Date(this.date);switch(t){case"year":e.setUTCMonth(0);case"quarter":if(t==="quarter"){let s=this.quarter();e.setUTCMonth((s-1)*3)}case"month":e.setUTCDate(1);case"day":e.setUTCHours(0);case"hour":e.setUTCMinutes(0);case"minute":e.setUTCSeconds(0);case"second":e.setUTCMilliseconds(0);break;case"week":let n=e.getUTCDay(),a=(n<this.config.weekStartsOn?7:0)+n-this.config.weekStartsOn;e.setUTCDate(e.getUTCDate()-a),e.setUTCHours(0,0,0,0);break}return new r(e,this.config)}endOf(t){return this.startOf(t).add(1,t).subtract(1,"millisecond")}isBefore(t,e){return e?this.startOf(e).valueOf()<new r(t).startOf(e).valueOf():this.date.getTime()<l(t).getTime()}isAfter(t,e){return e?this.startOf(e).valueOf()>new r(t).startOf(e).valueOf():this.date.getTime()>l(t).getTime()}isSame(t,e){if(!e)return this.date.getTime()===l(t).getTime();let n=this.startOf(e),a=new r(t,this.config).startOf(e);return n.date.getTime()===a.date.getTime()}isSameOrBefore(t,e){return this.isSame(t,e)||this.isBefore(t,e)}isSameOrAfter(t,e){return this.isSame(t,e)||this.isAfter(t,e)}isBetween(t,e,n,a="()"){let s=n?new r(t).startOf(n).valueOf():l(t).getTime(),o=n?new r(e).startOf(n).valueOf():l(e).getTime(),i=n?this.startOf(n).valueOf():this.date.getTime(),c=a[0]==="["?i>=s:i>s,d=a[1]==="]"?i<=o:i<o;return c&&d}isToday(){return this.isSame(new Date,"day")}isTomorrow(){let t=new r().add(1,"day");return this.isSame(t.toDate(),"day")}isYesterday(){let t=new r().subtract(1,"day");return this.isSame(t.toDate(),"day")}isThisWeek(){return this.isSame(new Date,"week")}isThisMonth(){return this.isSame(new Date,"month")}isThisQuarter(){return this.isSame(new Date,"quarter")}isThisYear(){return this.isSame(new Date,"year")}isWeekend(){let t=this.date.getUTCDay();return t===0||t===6}isWeekday(){return!this.isWeekend()}isLeapYear(){let t=this.date.getUTCFullYear();return t%4===0&&t%100!==0||t%400===0}isDST(){let t=new Date(this.year(),0,1),e=new Date(this.year(),6,1),n=Math.max(t.getTimezoneOffset(),e.getTimezoneOffset());return this.date.getTimezoneOffset()<n}diff(t,e="millisecond",n=!1){let a=l(t),s=this.date.getTime()-a.getTime(),o=1;switch(e){case"millisecond":return s;case"second":o=1e3;break;case"minute":o=1e3*60;break;case"hour":o=1e3*60*60;break;case"day":o=1e3*60*60*24;break;case"week":o=1e3*60*60*24*7;break;case"month":return n?s/(1e3*60*60*24*30.436875):this.diffMonth(a);case"quarter":return n?s/(1e3*60*60*24*91.3125):Math.floor(this.diffMonth(a)/3);case"year":return n?s/(1e3*60*60*24*365.25):this.diffYear(a)}let i=s/o;return n?i:Math.floor(i)}diffMonth(t){let e=this.date.getUTCFullYear()-t.getUTCFullYear(),n=this.date.getUTCMonth()-t.getUTCMonth();return e*12+n}diffYear(t){return this.date.getUTCFullYear()-t.getUTCFullYear()}fromNow(t=!1){let e=Date.now()-this.date.getTime();return I(e,this.config.locale,t)}toNow(t=!1){let e=this.date.getTime()-Date.now();return I(e,this.config.locale,t)}from(t,e=!1){let n=l(t).getTime()-this.date.getTime();return I(n,this.config.locale,e)}to(t,e=!1){let n=this.date.getTime()-l(t).getTime();return I(n,this.config.locale,e)}calendar(t){let e=t?l(t):new Date;return W(this.date,e,this.config.locale)}duration(t){return t?S.between(this.date,l(t)):new S(this.date.getTime())}daysInMonth(){return new Date(Date.UTC(this.date.getUTCFullYear(),this.date.getUTCMonth()+1,0)).getUTCDate()}weeksInYear(){let t=new Date(Date.UTC(this.year(),11,31)),n=new r(t).isoWeek();return n===1?52:n}age(t){let e=t?l(t):new Date,n=this.date,a=e.getUTCFullYear()-n.getUTCFullYear(),s=n.getUTCMonth(),o=n.getUTCDate(),i=e.getUTCMonth(),c=e.getUTCDate();return(i<s||i===s&&c<o)&&a--,a}clone(){return new r(this.date,this.config)}isBusinessDay(t=[]){return O(this.date,t)}addBusinessDays(t,e=[]){return new r(x(this.date,t,e),this.config)}subtractBusinessDays(t,e=[]){return new r(x(this.date,-t,e),this.config)}businessDaysUntil(t,e=[]){return H(this.date,l(t),e)}locale(t){return t===void 0?this.config.locale:new r(this.date,{...this.config,locale:t})}static eachDayOfInterval(t){let e=new r(t.start),n=new r(t.end),a=[],s=e.clone();for(;s.isSameOrBefore(n.toDate(),"day");)a.push(s.clone()),s=s.add(1,"day");return a}static eachWeekOfInterval(t){let e=new r(t.start).startOf("week"),n=new r(t.end),a=[],s=e.clone();for(;s.isSameOrBefore(n.toDate(),"week");)a.push(s.clone()),s=s.add(1,"week");return a}static eachMonthOfInterval(t){let e=new r(t.start).startOf("month"),n=new r(t.end),a=[],s=e.clone();for(;s.isSameOrBefore(n.toDate(),"month");)a.push(s.clone()),s=s.add(1,"month");return a}static now(){return new r}static utc(t){return t?new r(t):new r(new Date)}static unix(t){return new r(t*1e3)}static isValid(t){try{return C(l(t))}catch{return!1}}static max(...t){let e=t.map(n=>l(n).getTime());return new r(Math.max(...e))}static min(...t){let e=t.map(n=>l(n).getTime());return new r(Math.min(...e))}static isDuration(t){return t instanceof S}static duration(t,e){return typeof t=="number"&&e?new S(t,e):new S(t)}};export{b as DateKit,S as Duration,E as en,F as es,M as getLocale,z as registerLocale};
|
|
1
|
+
var F={name:"en",weekdays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],weekdaysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ordinal:r=>{let e=["th","st","nd","rd"],t=r%100;return r+(e[(t-20)%10]||e[t]||e[0])},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"}};var N={name:"es",weekdays:["Domingo","Lunes","Martes","Mi\xE9rcoles","Jueves","Viernes","S\xE1bado"],weekdaysShort:["Dom","Lun","Mar","Mi\xE9","Jue","Vie","S\xE1b"],weekdaysMin:["Do","Lu","Ma","Mi","Ju","Vi","S\xE1"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],ordinal:r=>`${r}\xBA`,relativeTime:{future:"en %s",past:"hace %s",s:"unos segundos",m:"un minuto",mm:"%d minutos",h:"una hora",hh:"%d horas",d:"un d\xEDa",dd:"%d d\xEDas",M:"un mes",MM:"%d meses",y:"un a\xF1o",yy:"%d a\xF1os"},calendar:{sameDay:"[Hoy a las] LT",nextDay:"[Ma\xF1ana a las] LT",nextWeek:"dddd [a las] LT",lastDay:"[Ayer a las] LT",lastWeek:"[El] dddd [pasado a las] LT",sameElse:"L"}};var Y={en:F,es:N};function M(r){return Y[r]||Y.en}function $(r){Y[r.name]=r}function L(r,e,t="en"){let n=M(t),s=r.getUTCFullYear(),a=r.getUTCMonth(),o=r.getUTCDate(),i=r.getUTCHours(),d=r.getUTCMinutes(),c=r.getUTCSeconds(),h=r.getUTCMilliseconds(),m=r.getUTCDay(),u=new Date(Date.UTC(s,0,1)),f=Math.floor((r.getTime()-u.getTime())/864e5)+1,g=Math.floor(a/3)+1,D=B(r),O=new Map,p=new Map,w={YYYY:s.toString(),YY:s.toString().slice(-2),Qo:n.ordinal(g),Q:g.toString(),MMMM:n.months[a],MMM:n.monthsShort[a],Mo:n.ordinal(a+1),MM:(a+1).toString().padStart(2,"0"),M:(a+1).toString(),Wo:n.ordinal(D),WW:D.toString().padStart(2,"0"),W:D.toString(),DDDo:n.ordinal(f),DDDD:f.toString().padStart(3,"0"),DDD:f.toString(),Do:n.ordinal(o),DD:o.toString().padStart(2,"0"),D:o.toString(),dddd:n.weekdays[m],ddd:n.weekdaysShort[m],do:n.ordinal(m),dd:n.weekdaysMin[m],d:m.toString(),HH:i.toString().padStart(2,"0"),H:i.toString(),hh:(i%12||12).toString().padStart(2,"0"),h:(i%12||12).toString(),mm:d.toString().padStart(2,"0"),m:d.toString(),ss:c.toString().padStart(2,"0"),s:c.toString(),SSS:h.toString().padStart(3,"0"),SS:h.toString().padStart(2,"0").slice(0,2),S:Math.floor(h/100).toString(),A:i>=12?"PM":"AM",a:i>=12?"pm":"am",Z:W(r.getTimezoneOffset()),ZZ:W(r.getTimezoneOffset()).replace(":",""),X:Math.floor(r.getTime()/1e3).toString(),x:r.getTime().toString()},T=e;return Object.keys(w).sort((y,U)=>U.length-y.length).forEach((y,U)=>{let E=`\0${U}\0`,z=new RegExp(y,"g");T=T.replace(z,E),p.set(E,w[y])}),p.forEach((y,U)=>{T=T.replace(new RegExp(U,"g"),y)}),T}function B(r){let e=new Date(r.getTime());e.setUTCHours(0,0,0,0),e.setUTCDate(e.getUTCDate()+4-(e.getUTCDay()||7));let t=new Date(Date.UTC(e.getUTCFullYear(),0,1));return Math.ceil(((e.getTime()-t.getTime())/864e5+1)/7)}function W(r){let e=r<=0?"+":"-",t=Math.abs(r),n=Math.floor(t/60),s=t%60;return`${e}${n.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`}function l(r){if(r instanceof Date)return new Date(r);if(typeof r=="number")return new Date(r);if(typeof r=="string")return new Date(r);throw new Error("Invalid date input")}function C(r){return r instanceof Date&&!isNaN(r.getTime())}function I(r,e="en",t=!1){let n=M(e),s=r<0,o=Math.abs(r)/1e3,i=o/60,d=i/60,c=d/24,h=c/30.44,m=c/365.25,u;return o<45?u=n.relativeTime.s:o<90?u=n.relativeTime.m:i<45?u=n.relativeTime.mm.replace("%d",Math.round(i).toString()):i<90?u=n.relativeTime.h:d<22?u=n.relativeTime.hh.replace("%d",Math.round(d).toString()):d<36?u=n.relativeTime.d:c<25?u=n.relativeTime.dd.replace("%d",Math.round(c).toString()):c<45?u=n.relativeTime.M:c<345?u=n.relativeTime.MM.replace("%d",Math.round(h).toString()):m<1.5?u=n.relativeTime.y:u=n.relativeTime.yy.replace("%d",Math.round(m).toString()),t?u:(s?n.relativeTime.future:n.relativeTime.past).replace("%s",u)}function v(r,e=new Date,t="en"){let n=M(t),s=new b(r),a=new b(e),o=s.startOf("day").diff(a.startOf("day").toDate(),"day"),i;return o===0?i=n.calendar.sameDay:o===1?i=n.calendar.nextDay:o===-1?i=n.calendar.lastDay:o>1&&o<=7?i=n.calendar.nextWeek:o<-1&&o>=-7?i=n.calendar.lastWeek:i=n.calendar.sameElse,i=i.replace("[","").replace("]","").replace("LT",s.format("HH:mm")).replace("L",s.format("MM/DD/YYYY")).replace("dddd",n.weekdays[r.getUTCDay()]),i}var H=[1,2,3,4,5];function k(r,e=[]){let t=r.getUTCDay();if(!H.includes(t))return!1;let n=r.toISOString().split("T")[0];return!e.some(s=>s.toISOString().split("T")[0]===n)}function x(r,e,t=[]){let n=new Date(r),s=Math.abs(e),a=e>0?1:-1;for(;s>0;)n.setUTCDate(n.getUTCDate()+a),k(n,t)&&s--;return n}function A(r,e,t=[]){let n=0,s=new Date(r),a=new Date(e);for(;s<=a;)k(s,t)&&n++,s.setUTCDate(s.getUTCDate()+1);return n}var S=class r{constructor(e,t="milliseconds"){typeof e=="number"?this._milliseconds=this.convertToMilliseconds(e,t):this._milliseconds=this.objectToMilliseconds(e)}convertToMilliseconds(e,t){return e*({milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5}[t]||1)}objectToMilliseconds(e){let t=0;return e.years&&(t+=e.years*365.25*864e5),e.months&&(t+=e.months*30.44*864e5),e.weeks&&(t+=e.weeks*6048e5),e.days&&(t+=e.days*864e5),e.hours&&(t+=e.hours*36e5),e.minutes&&(t+=e.minutes*6e4),e.seconds&&(t+=e.seconds*1e3),e.milliseconds&&(t+=e.milliseconds),t}asMilliseconds(){return this._milliseconds}asSeconds(){return this._milliseconds/1e3}asMinutes(){return this._milliseconds/6e4}asHours(){return this._milliseconds/36e5}asDays(){return this._milliseconds/864e5}asWeeks(){return this._milliseconds/6048e5}asMonths(){return this._milliseconds/(30.44*864e5)}asYears(){return this._milliseconds/(365.25*864e5)}humanize(e="en"){let t=Math.abs(this.asSeconds()),n=Math.abs(this.asMinutes()),s=Math.abs(this.asHours()),a=Math.abs(this.asDays()),o=Math.abs(this.asMonths()),i=Math.abs(this.asYears());return t<45?"a few seconds":t<90?"a minute":n<45?`${Math.round(n)} minutes`:n<90?"an hour":s<22?`${Math.round(s)} hours`:s<36?"a day":a<25?`${Math.round(a)} days`:a<45?"a month":a<345?`${Math.round(o)} months`:i<1.5?"a year":`${Math.round(i)} years`}toObject(){let e=Math.abs(this._milliseconds),t=Math.floor(e/(365.25*864e5));e-=t*365.25*864e5;let n=Math.floor(e/(30.44*864e5));e-=n*30.44*864e5;let s=Math.floor(e/864e5);e-=s*864e5;let a=Math.floor(e/36e5);e-=a*36e5;let o=Math.floor(e/6e4);e-=o*6e4;let i=Math.floor(e/1e3);e-=i*1e3;let d=Math.floor(e);return{years:t,months:n,days:s,hours:a,minutes:o,seconds:i,milliseconds:d}}add(e){return new r(this._milliseconds+e.asMilliseconds())}subtract(e){return new r(this._milliseconds-e.asMilliseconds())}static between(e,t){return new r(Math.abs(t.getTime()-e.getTime()))}};var b=class r{constructor(e,t){if(this.config={locale:"en",weekStartsOn:0,strictParsing:!1,...t},this.date=e?l(e):new Date,!C(this.date))throw new Error("Invalid date provided")}toDate(){return new Date(this.date)}toISOString(){return this.date.toISOString()}toUnix(){return Math.floor(this.date.getTime()/1e3)}valueOf(){return this.date.getTime()}toArray(){return[this.date.getUTCFullYear(),this.date.getUTCMonth(),this.date.getUTCDate(),this.date.getUTCHours(),this.date.getUTCMinutes(),this.date.getUTCSeconds(),this.date.getUTCMilliseconds()]}toObject(){return{year:this.date.getUTCFullYear(),month:this.date.getUTCMonth(),date:this.date.getUTCDate(),hour:this.date.getUTCHours(),minute:this.date.getUTCMinutes(),second:this.date.getUTCSeconds(),millisecond:this.date.getUTCMilliseconds()}}toJSON(){return this.toISOString()}toString(){return this.date.toString()}format(e){return L(this.date,e,this.config.locale)}static formatFromTimezoneString(e,t){let n,s;if(e instanceof Date?(s=e,n=e.toString()):typeof e=="number"?(s=new Date(e),n=s.toString()):(n=e,s=new Date(e)),isNaN(s.getTime()))throw new Error("Invalid date provided");let a=n.match(/GMT([+-]\d{2}):?(\d{2})|UTC([+-]\d{2}):?(\d{2})/i),o=0;if(a){let w=(a[1]||a[3])[0],T=parseInt((a[1]||a[3]).substring(1)),K=parseInt(a[2]||a[4]||"0");o=(T*60+K)*(w==="+"?1:-1)}else o=-s.getTimezoneOffset();let d=s.getTime()+o*60*1e3,c=new Date(d),h=c.getUTCFullYear(),m=c.getUTCMonth(),u=c.getUTCDate(),f=c.getUTCHours(),g=c.getUTCMinutes(),D=c.getUTCSeconds(),O=c.getUTCMilliseconds();return new r(Date.UTC(h,m,u,f,g,D,O)).format(t)}static formatZonedDate(e,t="DD-MM-YYYY",n="en"){let s,a;if(e instanceof Date?(a=e,s=e.toString()):typeof e=="number"?(a=new Date(e),s=a.toString()):(s=e,a=new Date(e)),isNaN(a.getTime()))throw new Error("Invalid date input for formatZonedDate");let o=s.match(/GMT([+-])(\d{2}):?(\d{2})/i),i=a;if(o){let d=o[1]==="-"?-1:1,c=parseInt(o[2],10),h=parseInt(o[3],10),m=d*(c*60+h),u=a.getTime()+m*6e4;i=new Date(u)}return L(i,t,n)}formatZonedDate(e,t="DD-MM-YYYY"){let n=this.config?.locale??"en";return r.formatZonedDate(e,t,n)}static convertTimezone(e,t,n,s){let a=l(e);if(!C(a))throw new Error("Invalid date provided");let o,i,d,c,h,m;if(typeof e=="string"&&!e.includes("Z")&&!e.includes("+")&&!e.includes("GMT")){let u=e.match(/(\d{4})-(\d{2})-(\d{2})[T\s](\d{2}):(\d{2}):(\d{2})/);u?(o=parseInt(u[1]),i=parseInt(u[2]),d=parseInt(u[3]),c=parseInt(u[4]),h=parseInt(u[5]),m=parseInt(u[6])):(o=a.getUTCFullYear(),i=a.getUTCMonth()+1,d=a.getUTCDate(),c=a.getUTCHours(),h=a.getUTCMinutes(),m=a.getUTCSeconds());let f=`${o}-${i.toString().padStart(2,"0")}-${d.toString().padStart(2,"0")}T${c.toString().padStart(2,"0")}:${h.toString().padStart(2,"0")}:${m.toString().padStart(2,"0")}`,g=new Date(Date.UTC(o,i-1,d,c,h,m)),D=new Date(g.toLocaleString("en-US",{timeZone:t})),O=new Date(g.toLocaleString("en-US",{timeZone:"UTC"})),p=D.getTime()-O.getTime(),w=g.getTime()-p,T=new Date(w);return r.formatInTimezone(T,n,s)}else return r.formatInTimezone(a,n,s)}static formatInTimezone(e,t,n){let s=l(e);if(!C(s))throw new Error("Invalid date provided");let o=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(s),i={};return o.forEach(c=>{c.type!=="literal"&&(i[c.type]=c.value)}),new r(Date.UTC(parseInt(i.year),parseInt(i.month)-1,parseInt(i.day),parseInt(i.hour),parseInt(i.minute),parseInt(i.second))).format(n)}static fromTimezone(e,t,n,s=0,a=0,o=0,i="UTC"){let d=`${e}-${t.toString().padStart(2,"0")}-${n.toString().padStart(2,"0")}T${s.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}`,c=new Intl.DateTimeFormat("en-US",{timeZone:i,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),h=new Date(d),m=new Date(Date.UTC(e,t-1,n,s,a,o)),u=new Date(m.toLocaleString("en-US",{timeZone:i})),f=new Date(m.toLocaleString("en-US",{timeZone:"UTC"})),g=u.getTime()-f.getTime(),D=m.getTime()-g;return new r(D)}static getTimezoneOffset(e,t=new Date){let n=new Date(t.toLocaleString("en-US",{timeZone:"UTC"}));return(new Date(t.toLocaleString("en-US",{timeZone:e})).getTime()-n.getTime())/6e4}year(){return this.date.getUTCFullYear()}month(){return this.date.getUTCMonth()}getDate(){return this.date.getUTCDate()}day(){return this.date.getUTCDay()}hour(){return this.date.getUTCHours()}minute(){return this.date.getUTCMinutes()}second(){return this.date.getUTCSeconds()}millisecond(){return this.date.getUTCMilliseconds()}quarter(){return Math.floor(this.date.getUTCMonth()/3)+1}week(){return this.isoWeek()}isoWeek(){let e=new Date(this.date.getTime());e.setUTCHours(0,0,0,0),e.setUTCDate(e.getUTCDate()+4-(e.getUTCDay()||7));let t=new Date(Date.UTC(e.getUTCFullYear(),0,1));return Math.ceil(((e.getTime()-t.getTime())/864e5+1)/7)}weekday(){return(this.date.getUTCDay()+7-this.config.weekStartsOn)%7}isoWeekday(){return this.date.getUTCDay()||7}dayOfYear(){let e=new Date(Date.UTC(this.date.getUTCFullYear(),0,1));return Math.floor((this.date.getTime()-e.getTime())/864e5)+1}weekYear(){let e=new Date(this.date.getTime());return e.setUTCDate(e.getUTCDate()+4-(e.getUTCDay()||7)),e.getUTCFullYear()}set(e){let t=new Date(this.date);return e.year!==void 0&&t.setUTCFullYear(e.year),e.month!==void 0&&t.setUTCMonth(e.month),e.date!==void 0&&t.setUTCDate(e.date),e.hour!==void 0&&t.setUTCHours(e.hour),e.minute!==void 0&&t.setUTCMinutes(e.minute),e.second!==void 0&&t.setUTCSeconds(e.second),e.millisecond!==void 0&&t.setUTCMilliseconds(e.millisecond),new r(t,this.config)}setYear(e){return this.set({year:e})}setMonth(e){return this.set({month:e})}setDate(e){return this.set({date:e})}setHour(e){return this.set({hour:e})}setMinute(e){return this.set({minute:e})}setSecond(e){return this.set({second:e})}setMillisecond(e){return this.set({millisecond:e})}setQuarter(e){let t=(e-1)*3;return this.set({month:t})}add(e,t){let n=new Date(this.date);switch(t){case"millisecond":n.setUTCMilliseconds(n.getUTCMilliseconds()+e);break;case"second":n.setUTCSeconds(n.getUTCSeconds()+e);break;case"minute":n.setUTCMinutes(n.getUTCMinutes()+e);break;case"hour":n.setUTCHours(n.getUTCHours()+e);break;case"day":n.setUTCDate(n.getUTCDate()+e);break;case"week":n.setUTCDate(n.getUTCDate()+e*7);break;case"month":n.setUTCMonth(n.getUTCMonth()+e);break;case"quarter":n.setUTCMonth(n.getUTCMonth()+e*3);break;case"year":n.setUTCFullYear(n.getUTCFullYear()+e);break}return new r(n,this.config)}subtract(e,t){return this.add(-e,t)}startOf(e){let t=new Date(this.date);switch(e){case"year":t.setUTCMonth(0);case"quarter":if(e==="quarter"){let a=this.quarter();t.setUTCMonth((a-1)*3)}case"month":t.setUTCDate(1);case"day":t.setUTCHours(0);case"hour":t.setUTCMinutes(0);case"minute":t.setUTCSeconds(0);case"second":t.setUTCMilliseconds(0);break;case"week":let n=t.getUTCDay(),s=(n<this.config.weekStartsOn?7:0)+n-this.config.weekStartsOn;t.setUTCDate(t.getUTCDate()-s),t.setUTCHours(0,0,0,0);break}return new r(t,this.config)}endOf(e){return this.startOf(e).add(1,e).subtract(1,"millisecond")}isBefore(e,t){return t?this.startOf(t).valueOf()<new r(e).startOf(t).valueOf():this.date.getTime()<l(e).getTime()}isAfter(e,t){return t?this.startOf(t).valueOf()>new r(e).startOf(t).valueOf():this.date.getTime()>l(e).getTime()}isSame(e,t){if(!t)return this.date.getTime()===l(e).getTime();let n=this.startOf(t),s=new r(e,this.config).startOf(t);return n.date.getTime()===s.date.getTime()}isSameOrBefore(e,t){return this.isSame(e,t)||this.isBefore(e,t)}isSameOrAfter(e,t){return this.isSame(e,t)||this.isAfter(e,t)}isBetween(e,t,n,s="()"){let a=n?new r(e).startOf(n).valueOf():l(e).getTime(),o=n?new r(t).startOf(n).valueOf():l(t).getTime(),i=n?this.startOf(n).valueOf():this.date.getTime(),d=s[0]==="["?i>=a:i>a,c=s[1]==="]"?i<=o:i<o;return d&&c}isToday(){return this.isSame(new Date,"day")}isTomorrow(){let e=new r().add(1,"day");return this.isSame(e.toDate(),"day")}isYesterday(){let e=new r().subtract(1,"day");return this.isSame(e.toDate(),"day")}isThisWeek(){return this.isSame(new Date,"week")}isThisMonth(){return this.isSame(new Date,"month")}isThisQuarter(){return this.isSame(new Date,"quarter")}isThisYear(){return this.isSame(new Date,"year")}isWeekend(){let e=this.date.getUTCDay();return e===0||e===6}isWeekday(){return!this.isWeekend()}isLeapYear(){let e=this.date.getUTCFullYear();return e%4===0&&e%100!==0||e%400===0}isDST(){let e=new Date(this.year(),0,1),t=new Date(this.year(),6,1),n=Math.max(e.getTimezoneOffset(),t.getTimezoneOffset());return this.date.getTimezoneOffset()<n}diff(e,t="millisecond",n=!1){let s=l(e),a=this.date.getTime()-s.getTime(),o=1;switch(t){case"millisecond":return a;case"second":o=1e3;break;case"minute":o=1e3*60;break;case"hour":o=1e3*60*60;break;case"day":o=1e3*60*60*24;break;case"week":o=1e3*60*60*24*7;break;case"month":return n?a/(1e3*60*60*24*30.436875):this.diffMonth(s);case"quarter":return n?a/(1e3*60*60*24*91.3125):Math.floor(this.diffMonth(s)/3);case"year":return n?a/(1e3*60*60*24*365.25):this.diffYear(s)}let i=a/o;return n?i:Math.floor(i)}diffMonth(e){let t=this.date.getUTCFullYear()-e.getUTCFullYear(),n=this.date.getUTCMonth()-e.getUTCMonth();return t*12+n}diffYear(e){return this.date.getUTCFullYear()-e.getUTCFullYear()}fromNow(e=!1){let t=Date.now()-this.date.getTime();return I(t,this.config.locale,e)}toNow(e=!1){let t=this.date.getTime()-Date.now();return I(t,this.config.locale,e)}from(e,t=!1){let n=l(e).getTime()-this.date.getTime();return I(n,this.config.locale,t)}to(e,t=!1){let n=this.date.getTime()-l(e).getTime();return I(n,this.config.locale,t)}calendar(e){let t=e?l(e):new Date;return v(this.date,t,this.config.locale)}duration(e){return e?S.between(this.date,l(e)):new S(this.date.getTime())}daysInMonth(){return new Date(Date.UTC(this.date.getUTCFullYear(),this.date.getUTCMonth()+1,0)).getUTCDate()}weeksInYear(){let e=new Date(Date.UTC(this.year(),11,31)),n=new r(e).isoWeek();return n===1?52:n}age(e){let t=e?l(e):new Date,n=this.date,s=t.getUTCFullYear()-n.getUTCFullYear(),a=n.getUTCMonth(),o=n.getUTCDate(),i=t.getUTCMonth(),d=t.getUTCDate();return(i<a||i===a&&d<o)&&s--,s}clone(){return new r(this.date,this.config)}isBusinessDay(e=[]){return k(this.date,e)}addBusinessDays(e,t=[]){return new r(x(this.date,e,t),this.config)}subtractBusinessDays(e,t=[]){return new r(x(this.date,-e,t),this.config)}businessDaysUntil(e,t=[]){return A(this.date,l(e),t)}locale(e){return e===void 0?this.config.locale:new r(this.date,{...this.config,locale:e})}static eachDayOfInterval(e){let t=new r(e.start),n=new r(e.end),s=[],a=t.clone();for(;a.isSameOrBefore(n.toDate(),"day");)s.push(a.clone()),a=a.add(1,"day");return s}static eachWeekOfInterval(e){let t=new r(e.start).startOf("week"),n=new r(e.end),s=[],a=t.clone();for(;a.isSameOrBefore(n.toDate(),"week");)s.push(a.clone()),a=a.add(1,"week");return s}static eachMonthOfInterval(e){let t=new r(e.start).startOf("month"),n=new r(e.end),s=[],a=t.clone();for(;a.isSameOrBefore(n.toDate(),"month");)s.push(a.clone()),a=a.add(1,"month");return s}static now(){return new r}static utc(e){return e?new r(e):new r(new Date)}static unix(e){return new r(e*1e3)}static isValid(e){try{return C(l(e))}catch{return!1}}static max(...e){let t=e.map(n=>l(n).getTime());return new r(Math.max(...t))}static min(...e){let t=e.map(n=>l(n).getTime());return new r(Math.min(...t))}static isDuration(e){return e instanceof S}static duration(e,t){return typeof e=="number"&&t?new S(e,t):new S(e)}};export{b as DateKit,S as Duration,F as en,N as es,M as getLocale,$ as registerLocale};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subrotosaha/datekit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A modern, lightweight TypeScript library for date manipulation with timezone support, business days, and chainable API.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|