@hkdigital/lib-sveltekit 0.1.59 → 0.1.60

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.
@@ -10,9 +10,9 @@
10
10
  * resolves. If this parameter is set, the delay will be chosen randomly
11
11
  * between the values [delayOrMinDelayMs, maxDelayMs]
12
12
  *
13
- * @returns {Promise} promise that resolves after a specified timeout
13
+ * @returns {HkPromise} promise that resolves after a specified timeout
14
14
  */
15
- export function delay(delayOrMinDelayMs: number, maxDelayMs?: number): Promise<any>;
15
+ export function delay(delayOrMinDelayMs: number, maxDelayMs?: number): HkPromise;
16
16
  /**
17
17
  * Get the number of milliseconds since the specified time stamp of the default
18
18
  * reference time stamp TIME_2025_01_01
@@ -53,61 +53,56 @@ export function toDate(dateOrTimestamp: Date | number): Date;
53
53
  export function getWeekNumber(dateOrTimestamp: Date | number): number;
54
54
  /**
55
55
  * Get the name of the month
56
- * - Returns the English name of the month
56
+ * - Returns the month name using Intl.DateTimeFormat
57
+ * - By default uses English locale, but locale can be specified
57
58
  *
58
- * - Use the output as label in combination with the functions
59
- * text() and translate() for international month names
59
+ * @param {Date|number} dateOrTimestamp - Date object or timestamp
60
+ * @param {string} [locale='nl-NL'] - The locale to use for the month name
60
61
  *
61
- * e.g.
62
+ * @param {Object} [options]
63
+ * @param {'numeric'|'2-digit'|'narrow'|'short'|'long'} [options.month='long']
64
+ * @param {string} [options.timeZone] - Optional timezone
62
65
  *
63
- * setTranslations()
64
- * ...
65
- *
66
- * text( getMonthName( new Date() ) );
67
- *
68
- * --
69
- *
70
- * @param {Date|number} dateOrTimestamp
71
- *
72
- * @returns {string} name of the month (English)
66
+ * @returns {string} name of the month in the specified locale
73
67
  */
74
- export function getMonthName(dateOrTimestamp: Date | number): string;
68
+ export function getMonthName(dateOrTimestamp: Date | number, locale?: string, options?: {
69
+ month?: "numeric" | "2-digit" | "narrow" | "short" | "long";
70
+ timeZone?: string;
71
+ }): string;
75
72
  /**
76
- * Get the name of the day
77
- * - Returns the English name of the day
78
- *
79
- * - Use the output as label in combination with the functions
80
- * text() and translate() for international day names
73
+ * Get the name of the day of the week
74
+ * - Returns the day name using Intl.DateTimeFormat
75
+ * - By default uses English locale, but locale can be specified
81
76
  *
82
- * e.g.
77
+ * @param {Date|number} dateOrTimestamp - Date object or timestamp
78
+ * @param {string} [locale='nl-NL'] - The locale to use for the day name
83
79
  *
84
- * setTranslations()
85
- * ...
80
+ * @param {Object} [options]
81
+ * @param {'narrow'|'short'|'long'} [options.weekday='long']
82
+ * @param {string} [options.timeZone] - Optional timezone
86
83
  *
87
- * text( getDayName( new Date() ) );
88
- *
89
- * --
90
- *
91
- * @param {Date|number} dateOrTimestamp
92
- *
93
- * @returns {string} name of the day (English)
84
+ * @returns {string} name of the day in the specified locale
94
85
  */
95
- export function getDayName(dateOrTimestamp: Date | number): string;
86
+ export function getDayName(dateOrTimestamp: Date | number, locale?: string, options?: {
87
+ weekday?: "narrow" | "short" | "long";
88
+ timeZone?: string;
89
+ }): string;
96
90
  /**
97
91
  * Return the timestamp of the start of the day
98
92
  * - Midnight
99
93
  *
100
- * @param {Date|number} dateOrTimestamp
94
+ * @param {Date|number} [dateOrTimestamp]
101
95
  *
102
96
  * @returns {number} timestamp of start of the day (00:00:00:0000)
103
97
  */
104
- export function getTimeAtStartOfDay(dateOrTimestamp: Date | number): number;
98
+ export function getTimeAtStartOfDay(dateOrTimestamp?: Date | number): number;
105
99
  /**
106
100
  * Return the timestamp of the end of the day
107
101
  * - Midnight - 1 millisecond
108
102
  *
109
- * @param {Date|number} dateOrTimestamp
103
+ * @param {Date|number} [dateOrTimestamp]
110
104
  *
111
105
  * @returns {number} timestamp of start of the day
112
106
  */
113
- export function getTimeAtEndOfDay(dateOrTimestamp: Date | number): number;
107
+ export function getTimeAtEndOfDay(dateOrTimestamp?: Date | number): number;
108
+ import { HkPromise } from '../../classes/promise/index.js';
@@ -50,7 +50,7 @@ import { HkPromise } from '../../classes/promise/index.js';
50
50
  * resolves. If this parameter is set, the delay will be chosen randomly
51
51
  * between the values [delayOrMinDelayMs, maxDelayMs]
52
52
  *
53
- * @returns {Promise} promise that resolves after a specified timeout
53
+ * @returns {HkPromise} promise that resolves after a specified timeout
54
54
  */
55
55
  export function delay(delayOrMinDelayMs, maxDelayMs) {
56
56
  expect.number(delayOrMinDelayMs);
@@ -132,7 +132,7 @@ export function timeToString(timeMs) {
132
132
 
133
133
  str += `${minutes.toString().padStart(2, '0')}:`;
134
134
  str += `${seconds.toString().padStart(2, '0')}.`;
135
- str += `${restMs.toString().padEnd(3, '0')}`;
135
+ str += `${restMs.toString().padStart(3, '0')}`;
136
136
 
137
137
  return str;
138
138
  }
@@ -209,64 +209,72 @@ export function getWeekNumber(dateOrTimestamp) {
209
209
  // of the year and the Thursday in the target week
210
210
  // (604800000 = 7 * 24 * 3600 * 1000)
211
211
  //
212
- return 1 + Math.ceil((firstThursday - target) / 604800000);
212
+ return 1 + Math.ceil((firstThursday - target.getTime()) / 604800000);
213
213
  }
214
214
 
215
215
  /**
216
216
  * Get the name of the month
217
- * - Returns the English name of the month
217
+ * - Returns the month name using Intl.DateTimeFormat
218
+ * - By default uses English locale, but locale can be specified
218
219
  *
219
- * - Use the output as label in combination with the functions
220
- * text() and translate() for international month names
220
+ * @param {Date|number} dateOrTimestamp - Date object or timestamp
221
+ * @param {string} [locale='nl-NL'] - The locale to use for the month name
221
222
  *
222
- * e.g.
223
+ * @param {Object} [options]
224
+ * @param {'numeric'|'2-digit'|'narrow'|'short'|'long'} [options.month='long']
225
+ * @param {string} [options.timeZone] - Optional timezone
223
226
  *
224
- * setTranslations()
225
- * ...
226
- *
227
- * text( getMonthName( new Date() ) );
228
- *
229
- * --
230
- *
231
- * @param {Date|number} dateOrTimestamp
232
- *
233
- * @returns {string} name of the month (English)
227
+ * @returns {string} name of the month in the specified locale
234
228
  */
235
- export function getMonthName(dateOrTimestamp) {
236
- throw new Error('Not implemented yet');
237
- // return MONTH_NAME_LABELS_EN[toDate(dateOrTimestamp).getMonth()];
229
+ export function getMonthName(dateOrTimestamp, locale = 'nl-NL',
230
+ options = { month: 'long' }) {
231
+
232
+ const date = toDate(dateOrTimestamp);
233
+
234
+ // Create formatter with provided locale and options
235
+ // @ts-ignore - TypeScript kan hier strikter zijn dan nodig met de options
236
+ const formatter = new Intl.DateTimeFormat(locale, {
237
+ month: options?.month || 'long',
238
+ ...(options?.timeZone ? { timeZone: options.timeZone } : {})
239
+ });
240
+
241
+ return formatter.format(date);
238
242
  }
239
243
 
240
244
  /**
241
- * Get the name of the day
242
- * - Returns the English name of the day
243
- *
244
- * - Use the output as label in combination with the functions
245
- * text() and translate() for international day names
245
+ * Get the name of the day of the week
246
+ * - Returns the day name using Intl.DateTimeFormat
247
+ * - By default uses English locale, but locale can be specified
246
248
  *
247
- * e.g.
249
+ * @param {Date|number} dateOrTimestamp - Date object or timestamp
250
+ * @param {string} [locale='nl-NL'] - The locale to use for the day name
248
251
  *
249
- * setTranslations()
250
- * ...
252
+ * @param {Object} [options]
253
+ * @param {'narrow'|'short'|'long'} [options.weekday='long']
254
+ * @param {string} [options.timeZone] - Optional timezone
251
255
  *
252
- * text( getDayName( new Date() ) );
253
- *
254
- * --
255
- *
256
- * @param {Date|number} dateOrTimestamp
257
- *
258
- * @returns {string} name of the day (English)
256
+ * @returns {string} name of the day in the specified locale
259
257
  */
260
- export function getDayName(dateOrTimestamp) {
261
- throw new Error('Not implemented yet');
262
- // return DAY_NAME_LABELS_EN[toDate(dateOrTimestamp).getDay()];
258
+ export function getDayName(dateOrTimestamp, locale = 'nl-NL',
259
+ options = { weekday: 'long' }) {
260
+
261
+ const date = toDate(dateOrTimestamp);
262
+
263
+ // Create formatter with provided locale and options
264
+ // @ts-ignore - TypeScript kan hier strikter zijn dan nodig met de options
265
+ const formatter = new Intl.DateTimeFormat(locale, {
266
+ weekday: options?.weekday || 'long',
267
+ ...(options?.timeZone ? { timeZone: options.timeZone } : {})
268
+ });
269
+
270
+ return formatter.format(date);
263
271
  }
264
272
 
265
273
  /**
266
274
  * Return the timestamp of the start of the day
267
275
  * - Midnight
268
276
  *
269
- * @param {Date|number} dateOrTimestamp
277
+ * @param {Date|number} [dateOrTimestamp]
270
278
  *
271
279
  * @returns {number} timestamp of start of the day (00:00:00:0000)
272
280
  */
@@ -292,7 +300,7 @@ export function getTimeAtStartOfDay(dateOrTimestamp) {
292
300
  * Return the timestamp of the end of the day
293
301
  * - Midnight - 1 millisecond
294
302
  *
295
- * @param {Date|number} dateOrTimestamp
303
+ * @param {Date|number} [dateOrTimestamp]
296
304
  *
297
305
  * @returns {number} timestamp of start of the day
298
306
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"