@ma.vu/appdate 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -13,6 +13,54 @@ bun run index.ts
13
13
  ```
14
14
 
15
15
  To use:
16
+ - [docs](https://ultrox.github.io/appdate/classes/AppDate.html)
17
+
16
18
  ```
17
19
  npm install @ma.vu/appdate
18
20
  ```
21
+ ## How?
22
+ The pattern follows the Builder/Factory pattern where:
23
+
24
+ Static methods are the "builders" that create new instances
25
+ ```ts
26
+ // These create NEW instances of AppDate
27
+ static now(): AppDate
28
+ static fromDateString(date: string): AppDate
29
+ static fromLocalTime(time: string): AppDate
30
+ static invalid(): AppDate
31
+ ```
32
+
33
+ Instance methods are the "operators" that work with existing instances
34
+
35
+ ```ts
36
+ // These operate on an EXISTING AppDate instance
37
+ add(value: number, unit?: ManipulateType): AppDate
38
+ subtract(value: number, unit?: ManipulateType): AppDate
39
+ isValid(): boolean
40
+ toLocalTime(): string
41
+ ```
42
+
43
+
44
+ ## Why Constructor is private?
45
+
46
+ The constructor is marked as private for several important reasons:
47
+
48
+ It ensures all date creation goes through the static factory methods where proper validation happens
49
+ It prevents creating AppDate with invalid/unexpected formats
50
+ It maintains a single way to create dates, making the code more predictable
51
+ It encapsulates the internal dayjs implementation
52
+
53
+ If we allowed direct construction:
54
+ ```ts
55
+ // If constructor was public:
56
+ const date1 = new AppDate('2024-02-11'); // Is this YYYY-MM-DD?
57
+ const date2 = new AppDate('02/11/2024'); // What about this format?
58
+ const date3 = new AppDate('11.02.2024'); // Or this European format?
59
+ ```
60
+
61
+ Instead, with factory methods:
62
+
63
+ ```ts
64
+ // Clear intention, validated format
65
+ const date = AppDate.fromDateString('2024-02-11'); // Must be YYYY-MM-DD
66
+ ```
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";var T=Object.create;var D=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var w=(a,t)=>{for(var e in t)D(a,e,{get:t[e],enumerable:!0})},c=(a,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!S.call(a,o)&&o!==e&&D(a,o,{get:()=>t[o],enumerable:!(i=L(t,o))||i.enumerable});return a};var s=(a,t,e)=>(e=a!=null?T(M(a)):{},c(t||!a||!a.__esModule?D(e,"default",{value:a,enumerable:!0}):e,a)),Y=a=>c(D({},"__esModule",{value:!0}),a);var U={};w(U,{AppDate:()=>d,formatLocalTime:()=>k,getLocalizedDateString:()=>z,isDateString:()=>h,setAppDateLanguage:()=>O,setTimezone:()=>A});module.exports=Y(U);var r=s(require("dayjs"),1),F=require("dayjs/locale/de"),l=s(require("dayjs/plugin/customParseFormat.js"),1),p=s(require("dayjs/plugin/isBetween.js"),1),y=s(require("dayjs/plugin/localizedFormat.js"),1),f=s(require("dayjs/plugin/timezone.js"),1),g=s(require("dayjs/plugin/utc.js"),1);r.default.extend(g.default);r.default.extend(f.default);r.default.extend(l.default);r.default.extend(p.default);r.default.extend(y.default);r.default.locale("de");async function O(a){switch(a){case"de":{let t=await import("dayjs/locale/de-ch");r.default.locale(t.default);break}case"fr":{let t=await import("dayjs/locale/fr-ch");r.default.locale(t.default);break}case"en":default:{let t=await import("dayjs/locale/en");r.default.locale(t.default);break}}}var n="Europe/Zurich";function A(a){n=a}var m="HH:mm",u="HH:mm:ssZ",d=class a{timezone;dayjsDate;static INVALID_DATE=(0,r.default)("");constructor(t,e,{invalid:i}={invalid:!1}){if(this.timezone=t,i){this.dayjsDate=a.INVALID_DATE;return}try{if(typeof e=="string"&&!h(e))throw new Error("Invalid Date string, we expect YYYY-DD-MM");this.dayjsDate=r.default.tz(e,t)}catch{console.warn("Could not parse date:",e),this.dayjsDate=a.INVALID_DATE}}static invalid(){return new a(n,"",{invalid:!0})}static now(){return new a(n,(0,r.default)())}static fromDateString(t){return new a(n,t)}static fromLocalTime(t){try{let e=r.default.tz(t,m,n);return new a(n,e)}catch(e){return e instanceof Error&&console.warn(`fromLocalTime(): ${e.message}`),a.invalid()}}static fromUtcString(t){let e=r.default.utc(t);return new a(n,e)}static fromUtcTime(t){let e=r.default.utc(t,u);return new a(n,e)}static minDate(){return a.fromDateString("1900-01-01")}static maxDate(){return a.fromDateString("2200-12-31")}add(t,e){let i=this.dayjsDate.add(t,e);return new a(n,i)}subtract(t,e){let i=this.dayjsDate.subtract(t,e);return new a(n,i)}startOf(t){let e=this.dayjsDate.startOf(t);return new a(n,e)}endOf(t){let e=this.dayjsDate.endOf(t);return new a(n,e)}tomorrow(){return this.add(1,"day")}isValid(){return this.dayjsDate.isValid()}isBefore(t,e){return this.dayjsDate.isBefore(t.dayjsDate,e)}isSame(t,e){return this.dayjsDate.isSame(t.dayjsDate,e)}isToday(){return this.dayjsDate.endOf("d").isSame((0,r.default)().endOf("d"))}isAfter(t,e){return this.dayjsDate.isAfter(t.dayjsDate,e)}isBetween(t=a.minDate(),e=a.maxDate(),i,o){return this.dayjsDate.isBetween(t.dayjsDate,e.dayjsDate,i,o??"[)")}isFirstDayOfWeek(){return this.dayjsDate.day()===1}isWorkingDay(){return x.includes(this.dayjsDate.day())}nextWorkingDay(){let t=this.add(1,"day");return t.isWorkingDay()?t:t.nextWorkingDay()}previousWorkingDay(){let t=this.subtract(1,"day");return t.isWorkingDay()?t:t.previousWorkingDay()}addWorkingDays(t){return t<=0||!Number.isInteger(t)?this:this.nextWorkingDay().addWorkingDays(t-1)}toLocalTime(){return this.format(m)}toUtcTime(){return this.dayjsDate.utc().format(u)}toDateString(){return this.format("YYYY-MM-DD")}toLocalizedDateString({includeDayOfWeek:t=!1}={}){let e=this.dayjsDate.format("L");return t?this.dayjsDate.format("dd, ")+e:e}toUtcDateString(){return this.dayjsDate.utc().format("YYYY-MM-DD")}toUtcString(){return this.dayjsDate.utc().format()}format(t="YYYY-MM-DDTHH:mm:ssZ[Z]"){return this.dayjsDate.format(t)}formatShort({includeDayOfWeek:t=!0}={}){let e=this.format("DD.MM.");return t?this.format("dd, ")+e:e}formatDateTime({includeDayOfWeek:t=!0}={}){let e=this.toLocalizedDateString({includeDayOfWeek:t}),i=this.toLocalTime();return`${e}, ${i}`}},x=[1,2,3,4,5];function z(a,t){return d.fromDateString(a).toLocalizedDateString(t)}function k(a){return d.fromLocalTime(a).toLocalTime()}function h(a){return a?(0,r.default)(a,"YYYY-MM-DD",!0).isValid():!1}0&&(module.exports={AppDate,formatLocalTime,getLocalizedDateString,isDateString,setAppDateLanguage,setTimezone});
2
+ "use strict";var T=Object.create;var D=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var w=(a,t)=>{for(var e in t)D(a,e,{get:t[e],enumerable:!0})},c=(a,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!S.call(a,o)&&o!==e&&D(a,o,{get:()=>t[o],enumerable:!(i=L(t,o))||i.enumerable});return a};var s=(a,t,e)=>(e=a!=null?T(M(a)):{},c(t||!a||!a.__esModule?D(e,"default",{value:a,enumerable:!0}):e,a)),Y=a=>c(D({},"__esModule",{value:!0}),a);var b={};w(b,{AppDate:()=>d,formatLocalTime:()=>k,getLocalizedDateString:()=>z,isDateString:()=>h,setAppDateLanguage:()=>O,setTimezone:()=>A});module.exports=Y(b);var r=s(require("dayjs"),1),F=require("dayjs/locale/de"),p=s(require("dayjs/plugin/customParseFormat.js"),1),l=s(require("dayjs/plugin/isBetween.js"),1),y=s(require("dayjs/plugin/localizedFormat.js"),1),f=s(require("dayjs/plugin/timezone.js"),1),g=s(require("dayjs/plugin/utc.js"),1);r.default.extend(g.default);r.default.extend(f.default);r.default.extend(p.default);r.default.extend(l.default);r.default.extend(y.default);async function O(a){switch(a){case"de":{let t=await import("dayjs/locale/de-ch");r.default.locale(t.default);break}case"fr":{let t=await import("dayjs/locale/fr-ch");r.default.locale(t.default);break}case"en":default:{let t=await import("dayjs/locale/en");r.default.locale(t.default);break}}}var n="Europe/Zurich";function A(a){n=a}var m="HH:mm",u="HH:mm:ssZ",d=class a{timezone;dayjsDate;static INVALID_DATE=(0,r.default)("");constructor(t,e,{invalid:i}={invalid:!1}){if(this.timezone=t,i){this.dayjsDate=a.INVALID_DATE;return}try{if(typeof e=="string"&&!h(e))throw new Error("Invalid Date string, we expect YYYY-DD-MM");this.dayjsDate=r.default.tz(e,t)}catch{console.warn("Could not parse date:",e),this.dayjsDate=a.INVALID_DATE}}static invalid(){return new a(n,"",{invalid:!0})}static now(){return new a(n,(0,r.default)())}static fromDateString(t){return new a(n,t)}static fromEpochSeconds(t){let e=r.default.unix(t);return new a(n,e)}static fromEpochMillis(t){let e=(0,r.default)(t);return new a(n,e)}static fromLocalTime(t){try{let e=r.default.tz(t,m,n);return new a(n,e)}catch(e){return e instanceof Error&&console.warn(`fromLocalTime(): ${e.message}`),a.invalid()}}static fromUtcString(t){let e=r.default.utc(t);return new a(n,e)}static fromUtcTime(t){let e=r.default.utc(t,u);return new a(n,e)}static minDate(){return a.fromDateString("1900-01-01")}static maxDate(){return a.fromDateString("2200-12-31")}add(t,e){let i=this.dayjsDate.add(t,e);return new a(n,i)}subtract(t,e){let i=this.dayjsDate.subtract(t,e);return new a(n,i)}startOf(t){let e=this.dayjsDate.startOf(t);return new a(n,e)}endOf(t){let e=this.dayjsDate.endOf(t);return new a(n,e)}tomorrow(){return this.add(1,"day")}isValid(){return this.dayjsDate.isValid()}isBefore(t,e){return this.dayjsDate.isBefore(t.dayjsDate,e)}isSame(t,e){return this.dayjsDate.isSame(t.dayjsDate,e)}isToday(){return this.dayjsDate.endOf("d").isSame((0,r.default)().endOf("d"))}isAfter(t,e){return this.dayjsDate.isAfter(t.dayjsDate,e)}isBetween(t=a.minDate(),e=a.maxDate(),i,o){return this.dayjsDate.isBetween(t.dayjsDate,e.dayjsDate,i,o??"[)")}isFirstDayOfWeek(){return this.dayjsDate.day()===1}isWorkingDay(){return x.includes(this.dayjsDate.day())}nextWorkingDay(){let t=this.add(1,"day");return t.isWorkingDay()?t:t.nextWorkingDay()}previousWorkingDay(){let t=this.subtract(1,"day");return t.isWorkingDay()?t:t.previousWorkingDay()}addWorkingDays(t){return t<=0||!Number.isInteger(t)?this:this.nextWorkingDay().addWorkingDays(t-1)}toLocalTime(){return this.format(m)}toUtcTime(){return this.dayjsDate.utc().format(u)}toDateString(){return this.format("YYYY-MM-DD")}toLocalizedDateString({includeDayOfWeek:t=!1}={}){let e=this.dayjsDate.format("L");return t?this.dayjsDate.format("dd, ")+e:e}toUtcDateString(){return this.dayjsDate.utc().format("YYYY-MM-DD")}toUtcString(){return this.dayjsDate.utc().format()}format(t="YYYY-MM-DDTHH:mm:ssZ[Z]"){return this.dayjsDate.format(t)}formatShort({includeDayOfWeek:t=!0}={}){return t?this.format("dd, DD.MM."):this.format("DD.MM.")}formatDateTime({includeDayOfWeek:t=!0}={}){let e=this.toLocalizedDateString({includeDayOfWeek:t}),i=this.toLocalTime();return`${e}, ${i}`}},x=[1,2,3,4,5];function z(a,t){return d.fromDateString(a).toLocalizedDateString(t)}function k(a){return d.fromLocalTime(a).toLocalTime()}function h(a){return a?(0,r.default)(a,"YYYY-MM-DD",!0).isValid():!1}0&&(module.exports={AppDate,formatLocalTime,getLocalizedDateString,isDateString,setAppDateLanguage,setTimezone});
package/dist/index.d.cts CHANGED
@@ -6,7 +6,7 @@ import { Dayjs, ManipulateType, OpUnitType } from 'dayjs';
6
6
  * de: 10.10.2010
7
7
  * en: 10/10/2010
8
8
  */
9
- declare function setAppDateLanguage(lang: 'de' | 'en' | 'fr'): Promise<void>;
9
+ declare function setAppDateLanguage(lang: "de" | "en" | "fr"): Promise<void>;
10
10
  /**
11
11
  * Change zone in runtime
12
12
  */
@@ -67,6 +67,33 @@ declare class AppDate {
67
67
  * const date = AppDate.fromDateString("2023-05-21");
68
68
  */
69
69
  static fromDateString(date: string): AppDate;
70
+ /**
71
+ * Creates a AppDate instance from a epoch seconds.
72
+ *
73
+ * @param seconds - A number representing a epoch seconds.
74
+ * @returns A new AppDate instance set to the given epoch seconds.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const date = AppDate.fromEpochSeconds(1714732800);
79
+ * console.log(date.toLocalizedDateString()); // "04.01.2026"
80
+ * ```
81
+ */
82
+ static fromEpochSeconds(seconds: number): AppDate;
83
+ /**
84
+ * Creates a AppDate instance from a epoch milliseconds.
85
+ *
86
+ * @param ms - A number representing a epoch milliseconds.
87
+ * @returns A new AppDate instance set to the given epoch milliseconds.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const date = AppDate.fromEpochMillis(1714732800000);
92
+ * console.log(date.toLocalizedDateString()); // "04.01.2026"
93
+ * ```
94
+ }
95
+ */
96
+ static fromEpochMillis(ms: number): AppDate;
70
97
  /**
71
98
  * Creates a AppDate instance from a local time string.
72
99
  *
@@ -80,9 +107,49 @@ declare class AppDate {
80
107
  * const date = AppDate.fromLocalTime("14:30"); Today's date, 14:30 or (02:30 PM)
81
108
  */
82
109
  static fromLocalTime(time: string): AppDate;
110
+ /**
111
+ *
112
+ * @param date - A string representing a UTC date in "YYYY-MM-DD" format.
113
+ * @returns A new AppDate instance set to the given UTC date.
114
+ *
115
+ * @example
116
+ * const date = AppDate.fromUtcString("2026-01-04");
117
+ * console.log(date.toLocalizedDateString()); // "04.01.2026"
118
+ * ```
119
+ */
83
120
  static fromUtcString(date?: string): AppDate;
121
+ /**
122
+ * Creates a AppDate instance from a UTC time string.
123
+ *
124
+ * @param time - A string representing a UTC time in "HH:mm:ssZ" format.
125
+ * @returns A new AppDate instance set to the given UTC time.
126
+ *
127
+ * @example
128
+ * const time = AppDate.fromUtcTime("14:30:00+00:00");
129
+ * console.log(time.toLocalizedDateString()); // "04.01.2026"
130
+ * ```
131
+ */
84
132
  static fromUtcTime(time: string): AppDate;
133
+ /**
134
+ *
135
+ * @returns A new AppDate instance set to the minimum supported date (1900-01-01).
136
+ *
137
+ * @example
138
+ * const minDate = AppDate.minDate();
139
+ * console.log(minDate.toLocalizedDateString()); // "01.01.1900"
140
+ * ```
141
+ */
85
142
  static minDate(): AppDate;
143
+ /**
144
+ * Returns the maximum supported date (2200-12-31).
145
+ *
146
+ * @returns A new AppDate instance set to the maximum supported date.
147
+ *
148
+ * @example
149
+ * const maxDate = AppDate.maxDate();
150
+ * console.log(maxDate.toLocalizedDateString()); // "31.12.2200"
151
+ * ```
152
+ */
86
153
  static maxDate(): AppDate;
87
154
  add(value: number, unit?: ManipulateType): AppDate;
88
155
  subtract(value: number, unit?: ManipulateType): AppDate;
@@ -97,7 +164,7 @@ declare class AppDate {
97
164
  */
98
165
  isToday(): boolean;
99
166
  isAfter(other: AppDate, unit?: OpUnitType): boolean;
100
- isBetween(from?: AppDate, to?: AppDate, unit?: OpUnitType, inclusivity?: `${'(' | '['}${')' | ']'}`): boolean;
167
+ isBetween(from?: AppDate, to?: AppDate, unit?: OpUnitType, inclusivity?: `${"(" | "["}${")" | "]"}`): boolean;
101
168
  isFirstDayOfWeek(): boolean;
102
169
  isWorkingDay(): boolean;
103
170
  nextWorkingDay(): AppDate;
@@ -114,6 +181,13 @@ declare class AppDate {
114
181
  toUtcTime(): string;
115
182
  /**
116
183
  * Converts the current date to a string: YYYY-MM-DD
184
+ *
185
+ * @returns A string representing the current date in "YYYY-MM-DD" format.
186
+ *
187
+ * @example
188
+ * const date = AppDate.now();
189
+ * console.log(date.toDateString()); // "2026-01-04"
190
+ * ```
117
191
  */
118
192
  toDateString(): DateString;
119
193
  /**
@@ -139,6 +213,17 @@ declare class AppDate {
139
213
  *
140
214
  */
141
215
  format(template?: FormatTemplate): string;
216
+ /**
217
+ *
218
+ * @param options - Optional settings for short formatting.
219
+ * @returns The short formatted date string.
220
+ *
221
+ * @example
222
+ * const date = AppDate.now();
223
+ * console.log(date.formatShort({ includeDayOfWeek: true })); // "Su, 04.01."
224
+ * console.log(date.formatShort({ includeDayOfWeek: false })); // "04.01."
225
+ * ```
226
+ */
142
227
  formatShort({ includeDayOfWeek }?: LocalizedFormatOptions): string;
143
228
  formatDateTime({ includeDayOfWeek }?: LocalizedFormatOptions): string;
144
229
  }
@@ -156,6 +241,6 @@ declare function formatLocalTime(time: string): string;
156
241
  * otherwise false
157
242
  */
158
243
  declare function isDateString(date: string | undefined | null | Dayjs): date is DateString;
159
- type FormatTemplate = 'YY' | 'YYYY' | 'M' | 'MM' | 'MMM' | 'MMMM' | 'D' | 'DD' | 'd' | 'dd' | 'ddd' | 'dddd' | 'H' | 'HH' | 'h' | 'hh' | 'm' | 'mm' | 's' | 'ss' | 'SSS' | 'Z' | 'ZZ' | 'A' | 'a' | 'LT' | 'LTS' | /* en: 10/10/2020, de: 10.10.2020 */ 'L' | 'LL' | 'LLL' | 'LLLL' | 'l' | 'll' | 'lll' | 'llll' | (string & {});
244
+ type FormatTemplate = "YY" | "YYYY" | "M" | "MM" | "MMM" | "MMMM" | "D" | "DD" | "d" | "dd" | "ddd" | "dddd" | "H" | "HH" | "h" | "hh" | "m" | "mm" | "s" | "ss" | "SSS" | "Z" | "ZZ" | "A" | "a" | "LT" | "LTS" | /* en: 10/10/2020, de: 10.10.2020 */ "L" | "LL" | "LLL" | "LLLL" | "l" | "ll" | "lll" | "llll" | (string & {});
160
245
 
161
246
  export { AppDate, type GetNDaysOptions, type LocalizedFormatOptions, formatLocalTime, getLocalizedDateString, isDateString, setAppDateLanguage, setTimezone };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { Dayjs, ManipulateType, OpUnitType } from 'dayjs';
6
6
  * de: 10.10.2010
7
7
  * en: 10/10/2010
8
8
  */
9
- declare function setAppDateLanguage(lang: 'de' | 'en' | 'fr'): Promise<void>;
9
+ declare function setAppDateLanguage(lang: "de" | "en" | "fr"): Promise<void>;
10
10
  /**
11
11
  * Change zone in runtime
12
12
  */
@@ -67,6 +67,33 @@ declare class AppDate {
67
67
  * const date = AppDate.fromDateString("2023-05-21");
68
68
  */
69
69
  static fromDateString(date: string): AppDate;
70
+ /**
71
+ * Creates a AppDate instance from a epoch seconds.
72
+ *
73
+ * @param seconds - A number representing a epoch seconds.
74
+ * @returns A new AppDate instance set to the given epoch seconds.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const date = AppDate.fromEpochSeconds(1714732800);
79
+ * console.log(date.toLocalizedDateString()); // "04.01.2026"
80
+ * ```
81
+ */
82
+ static fromEpochSeconds(seconds: number): AppDate;
83
+ /**
84
+ * Creates a AppDate instance from a epoch milliseconds.
85
+ *
86
+ * @param ms - A number representing a epoch milliseconds.
87
+ * @returns A new AppDate instance set to the given epoch milliseconds.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const date = AppDate.fromEpochMillis(1714732800000);
92
+ * console.log(date.toLocalizedDateString()); // "04.01.2026"
93
+ * ```
94
+ }
95
+ */
96
+ static fromEpochMillis(ms: number): AppDate;
70
97
  /**
71
98
  * Creates a AppDate instance from a local time string.
72
99
  *
@@ -80,9 +107,49 @@ declare class AppDate {
80
107
  * const date = AppDate.fromLocalTime("14:30"); Today's date, 14:30 or (02:30 PM)
81
108
  */
82
109
  static fromLocalTime(time: string): AppDate;
110
+ /**
111
+ *
112
+ * @param date - A string representing a UTC date in "YYYY-MM-DD" format.
113
+ * @returns A new AppDate instance set to the given UTC date.
114
+ *
115
+ * @example
116
+ * const date = AppDate.fromUtcString("2026-01-04");
117
+ * console.log(date.toLocalizedDateString()); // "04.01.2026"
118
+ * ```
119
+ */
83
120
  static fromUtcString(date?: string): AppDate;
121
+ /**
122
+ * Creates a AppDate instance from a UTC time string.
123
+ *
124
+ * @param time - A string representing a UTC time in "HH:mm:ssZ" format.
125
+ * @returns A new AppDate instance set to the given UTC time.
126
+ *
127
+ * @example
128
+ * const time = AppDate.fromUtcTime("14:30:00+00:00");
129
+ * console.log(time.toLocalizedDateString()); // "04.01.2026"
130
+ * ```
131
+ */
84
132
  static fromUtcTime(time: string): AppDate;
133
+ /**
134
+ *
135
+ * @returns A new AppDate instance set to the minimum supported date (1900-01-01).
136
+ *
137
+ * @example
138
+ * const minDate = AppDate.minDate();
139
+ * console.log(minDate.toLocalizedDateString()); // "01.01.1900"
140
+ * ```
141
+ */
85
142
  static minDate(): AppDate;
143
+ /**
144
+ * Returns the maximum supported date (2200-12-31).
145
+ *
146
+ * @returns A new AppDate instance set to the maximum supported date.
147
+ *
148
+ * @example
149
+ * const maxDate = AppDate.maxDate();
150
+ * console.log(maxDate.toLocalizedDateString()); // "31.12.2200"
151
+ * ```
152
+ */
86
153
  static maxDate(): AppDate;
87
154
  add(value: number, unit?: ManipulateType): AppDate;
88
155
  subtract(value: number, unit?: ManipulateType): AppDate;
@@ -97,7 +164,7 @@ declare class AppDate {
97
164
  */
98
165
  isToday(): boolean;
99
166
  isAfter(other: AppDate, unit?: OpUnitType): boolean;
100
- isBetween(from?: AppDate, to?: AppDate, unit?: OpUnitType, inclusivity?: `${'(' | '['}${')' | ']'}`): boolean;
167
+ isBetween(from?: AppDate, to?: AppDate, unit?: OpUnitType, inclusivity?: `${"(" | "["}${")" | "]"}`): boolean;
101
168
  isFirstDayOfWeek(): boolean;
102
169
  isWorkingDay(): boolean;
103
170
  nextWorkingDay(): AppDate;
@@ -114,6 +181,13 @@ declare class AppDate {
114
181
  toUtcTime(): string;
115
182
  /**
116
183
  * Converts the current date to a string: YYYY-MM-DD
184
+ *
185
+ * @returns A string representing the current date in "YYYY-MM-DD" format.
186
+ *
187
+ * @example
188
+ * const date = AppDate.now();
189
+ * console.log(date.toDateString()); // "2026-01-04"
190
+ * ```
117
191
  */
118
192
  toDateString(): DateString;
119
193
  /**
@@ -139,6 +213,17 @@ declare class AppDate {
139
213
  *
140
214
  */
141
215
  format(template?: FormatTemplate): string;
216
+ /**
217
+ *
218
+ * @param options - Optional settings for short formatting.
219
+ * @returns The short formatted date string.
220
+ *
221
+ * @example
222
+ * const date = AppDate.now();
223
+ * console.log(date.formatShort({ includeDayOfWeek: true })); // "Su, 04.01."
224
+ * console.log(date.formatShort({ includeDayOfWeek: false })); // "04.01."
225
+ * ```
226
+ */
142
227
  formatShort({ includeDayOfWeek }?: LocalizedFormatOptions): string;
143
228
  formatDateTime({ includeDayOfWeek }?: LocalizedFormatOptions): string;
144
229
  }
@@ -156,6 +241,6 @@ declare function formatLocalTime(time: string): string;
156
241
  * otherwise false
157
242
  */
158
243
  declare function isDateString(date: string | undefined | null | Dayjs): date is DateString;
159
- type FormatTemplate = 'YY' | 'YYYY' | 'M' | 'MM' | 'MMM' | 'MMMM' | 'D' | 'DD' | 'd' | 'dd' | 'ddd' | 'dddd' | 'H' | 'HH' | 'h' | 'hh' | 'm' | 'mm' | 's' | 'ss' | 'SSS' | 'Z' | 'ZZ' | 'A' | 'a' | 'LT' | 'LTS' | /* en: 10/10/2020, de: 10.10.2020 */ 'L' | 'LL' | 'LLL' | 'LLLL' | 'l' | 'll' | 'lll' | 'llll' | (string & {});
244
+ type FormatTemplate = "YY" | "YYYY" | "M" | "MM" | "MMM" | "MMMM" | "D" | "DD" | "d" | "dd" | "ddd" | "dddd" | "H" | "HH" | "h" | "hh" | "m" | "mm" | "s" | "ss" | "SSS" | "Z" | "ZZ" | "A" | "a" | "LT" | "LTS" | /* en: 10/10/2020, de: 10.10.2020 */ "L" | "LL" | "LLL" | "LLLL" | "l" | "ll" | "lll" | "llll" | (string & {});
160
245
 
161
246
  export { AppDate, type GetNDaysOptions, type LocalizedFormatOptions, formatLocalTime, getLocalizedDateString, isDateString, setAppDateLanguage, setTimezone };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import r from"dayjs";import"dayjs/locale/de";import c from"dayjs/plugin/customParseFormat.js";import m from"dayjs/plugin/isBetween.js";import u from"dayjs/plugin/localizedFormat.js";import l from"dayjs/plugin/timezone.js";import p from"dayjs/plugin/utc.js";r.extend(p);r.extend(l);r.extend(c);r.extend(m);r.extend(u);r.locale("de");async function w(a){switch(a){case"de":{let t=await import("dayjs/locale/de-ch");r.locale(t.default);break}case"fr":{let t=await import("dayjs/locale/fr-ch");r.locale(t.default);break}case"en":default:{let t=await import("dayjs/locale/en");r.locale(t.default);break}}}var i="Europe/Zurich";function Y(a){i=a}var d="HH:mm",D="HH:mm:ssZ",s=class a{timezone;dayjsDate;static INVALID_DATE=r("");constructor(t,e,{invalid:n}={invalid:!1}){if(this.timezone=t,n){this.dayjsDate=a.INVALID_DATE;return}try{if(typeof e=="string"&&!f(e))throw new Error("Invalid Date string, we expect YYYY-DD-MM");this.dayjsDate=r.tz(e,t)}catch{console.warn("Could not parse date:",e),this.dayjsDate=a.INVALID_DATE}}static invalid(){return new a(i,"",{invalid:!0})}static now(){return new a(i,r())}static fromDateString(t){return new a(i,t)}static fromLocalTime(t){try{let e=r.tz(t,d,i);return new a(i,e)}catch(e){return e instanceof Error&&console.warn(`fromLocalTime(): ${e.message}`),a.invalid()}}static fromUtcString(t){let e=r.utc(t);return new a(i,e)}static fromUtcTime(t){let e=r.utc(t,D);return new a(i,e)}static minDate(){return a.fromDateString("1900-01-01")}static maxDate(){return a.fromDateString("2200-12-31")}add(t,e){let n=this.dayjsDate.add(t,e);return new a(i,n)}subtract(t,e){let n=this.dayjsDate.subtract(t,e);return new a(i,n)}startOf(t){let e=this.dayjsDate.startOf(t);return new a(i,e)}endOf(t){let e=this.dayjsDate.endOf(t);return new a(i,e)}tomorrow(){return this.add(1,"day")}isValid(){return this.dayjsDate.isValid()}isBefore(t,e){return this.dayjsDate.isBefore(t.dayjsDate,e)}isSame(t,e){return this.dayjsDate.isSame(t.dayjsDate,e)}isToday(){return this.dayjsDate.endOf("d").isSame(r().endOf("d"))}isAfter(t,e){return this.dayjsDate.isAfter(t.dayjsDate,e)}isBetween(t=a.minDate(),e=a.maxDate(),n,o){return this.dayjsDate.isBetween(t.dayjsDate,e.dayjsDate,n,o??"[)")}isFirstDayOfWeek(){return this.dayjsDate.day()===1}isWorkingDay(){return y.includes(this.dayjsDate.day())}nextWorkingDay(){let t=this.add(1,"day");return t.isWorkingDay()?t:t.nextWorkingDay()}previousWorkingDay(){let t=this.subtract(1,"day");return t.isWorkingDay()?t:t.previousWorkingDay()}addWorkingDays(t){return t<=0||!Number.isInteger(t)?this:this.nextWorkingDay().addWorkingDays(t-1)}toLocalTime(){return this.format(d)}toUtcTime(){return this.dayjsDate.utc().format(D)}toDateString(){return this.format("YYYY-MM-DD")}toLocalizedDateString({includeDayOfWeek:t=!1}={}){let e=this.dayjsDate.format("L");return t?this.dayjsDate.format("dd, ")+e:e}toUtcDateString(){return this.dayjsDate.utc().format("YYYY-MM-DD")}toUtcString(){return this.dayjsDate.utc().format()}format(t="YYYY-MM-DDTHH:mm:ssZ[Z]"){return this.dayjsDate.format(t)}formatShort({includeDayOfWeek:t=!0}={}){let e=this.format("DD.MM.");return t?this.format("dd, ")+e:e}formatDateTime({includeDayOfWeek:t=!0}={}){let e=this.toLocalizedDateString({includeDayOfWeek:t}),n=this.toLocalTime();return`${e}, ${n}`}},y=[1,2,3,4,5];function O(a,t){return s.fromDateString(a).toLocalizedDateString(t)}function A(a){return s.fromLocalTime(a).toLocalTime()}function f(a){return a?r(a,"YYYY-MM-DD",!0).isValid():!1}export{s as AppDate,A as formatLocalTime,O as getLocalizedDateString,f as isDateString,w as setAppDateLanguage,Y as setTimezone};
2
+ import r from"dayjs";import"dayjs/locale/de";import c from"dayjs/plugin/customParseFormat.js";import m from"dayjs/plugin/isBetween.js";import u from"dayjs/plugin/localizedFormat.js";import p from"dayjs/plugin/timezone.js";import l from"dayjs/plugin/utc.js";r.extend(l);r.extend(p);r.extend(c);r.extend(m);r.extend(u);async function w(a){switch(a){case"de":{let t=await import("dayjs/locale/de-ch");r.locale(t.default);break}case"fr":{let t=await import("dayjs/locale/fr-ch");r.locale(t.default);break}case"en":default:{let t=await import("dayjs/locale/en");r.locale(t.default);break}}}var n="Europe/Zurich";function Y(a){n=a}var d="HH:mm",D="HH:mm:ssZ",s=class a{timezone;dayjsDate;static INVALID_DATE=r("");constructor(t,e,{invalid:i}={invalid:!1}){if(this.timezone=t,i){this.dayjsDate=a.INVALID_DATE;return}try{if(typeof e=="string"&&!f(e))throw new Error("Invalid Date string, we expect YYYY-DD-MM");this.dayjsDate=r.tz(e,t)}catch{console.warn("Could not parse date:",e),this.dayjsDate=a.INVALID_DATE}}static invalid(){return new a(n,"",{invalid:!0})}static now(){return new a(n,r())}static fromDateString(t){return new a(n,t)}static fromEpochSeconds(t){let e=r.unix(t);return new a(n,e)}static fromEpochMillis(t){let e=r(t);return new a(n,e)}static fromLocalTime(t){try{let e=r.tz(t,d,n);return new a(n,e)}catch(e){return e instanceof Error&&console.warn(`fromLocalTime(): ${e.message}`),a.invalid()}}static fromUtcString(t){let e=r.utc(t);return new a(n,e)}static fromUtcTime(t){let e=r.utc(t,D);return new a(n,e)}static minDate(){return a.fromDateString("1900-01-01")}static maxDate(){return a.fromDateString("2200-12-31")}add(t,e){let i=this.dayjsDate.add(t,e);return new a(n,i)}subtract(t,e){let i=this.dayjsDate.subtract(t,e);return new a(n,i)}startOf(t){let e=this.dayjsDate.startOf(t);return new a(n,e)}endOf(t){let e=this.dayjsDate.endOf(t);return new a(n,e)}tomorrow(){return this.add(1,"day")}isValid(){return this.dayjsDate.isValid()}isBefore(t,e){return this.dayjsDate.isBefore(t.dayjsDate,e)}isSame(t,e){return this.dayjsDate.isSame(t.dayjsDate,e)}isToday(){return this.dayjsDate.endOf("d").isSame(r().endOf("d"))}isAfter(t,e){return this.dayjsDate.isAfter(t.dayjsDate,e)}isBetween(t=a.minDate(),e=a.maxDate(),i,o){return this.dayjsDate.isBetween(t.dayjsDate,e.dayjsDate,i,o??"[)")}isFirstDayOfWeek(){return this.dayjsDate.day()===1}isWorkingDay(){return y.includes(this.dayjsDate.day())}nextWorkingDay(){let t=this.add(1,"day");return t.isWorkingDay()?t:t.nextWorkingDay()}previousWorkingDay(){let t=this.subtract(1,"day");return t.isWorkingDay()?t:t.previousWorkingDay()}addWorkingDays(t){return t<=0||!Number.isInteger(t)?this:this.nextWorkingDay().addWorkingDays(t-1)}toLocalTime(){return this.format(d)}toUtcTime(){return this.dayjsDate.utc().format(D)}toDateString(){return this.format("YYYY-MM-DD")}toLocalizedDateString({includeDayOfWeek:t=!1}={}){let e=this.dayjsDate.format("L");return t?this.dayjsDate.format("dd, ")+e:e}toUtcDateString(){return this.dayjsDate.utc().format("YYYY-MM-DD")}toUtcString(){return this.dayjsDate.utc().format()}format(t="YYYY-MM-DDTHH:mm:ssZ[Z]"){return this.dayjsDate.format(t)}formatShort({includeDayOfWeek:t=!0}={}){return t?this.format("dd, DD.MM."):this.format("DD.MM.")}formatDateTime({includeDayOfWeek:t=!0}={}){let e=this.toLocalizedDateString({includeDayOfWeek:t}),i=this.toLocalTime();return`${e}, ${i}`}},y=[1,2,3,4,5];function O(a,t){return s.fromDateString(a).toLocalizedDateString(t)}function A(a){return s.fromLocalTime(a).toLocalTime()}function f(a){return a?r(a,"YYYY-MM-DD",!0).isValid():!1}export{s as AppDate,A as formatLocalTime,O as getLocalizedDateString,f as isDateString,w as setAppDateLanguage,Y as setTimezone};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.5",
2
+ "version": "0.0.7",
3
3
  "name": "@ma.vu/appdate",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
@@ -20,13 +20,16 @@
20
20
  "dist"
21
21
  ],
22
22
  "scripts": {
23
- "publish": "npm run build && npm publish",
24
23
  "build": "tsup",
25
- "test": "bun test"
24
+ "test": "bun test",
25
+ "docs": "typedoc src/index.ts",
26
+ "bump": "npm version patch",
27
+ "prepublishOnly": "bun run build && bun run docs"
26
28
  },
27
29
  "devDependencies": {
28
30
  "bun-types": "latest",
29
31
  "tsup": "~8.2.4",
32
+ "typedoc": "~0.28.15",
30
33
  "vite": "~5.3.5",
31
34
  "vitest": "~2.0.5"
32
35
  },