@esfaenza/material-dayjs-adapter 16.2.29 → 17.3.15

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.
@@ -1,436 +1,436 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, Inject, NgModule } from '@angular/core';
2
+ import { Inject, Injectable, NgModule } from '@angular/core';
3
3
  import { DateAdapter, MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core';
4
4
 
5
- // Angular
6
- /**
7
- * Adapter per permettere a Material di funzionare senza problemi con DayJs. Per altri provider di date (es. moment) l'adapter viene fornito
8
- * nativamente da Angular. Per DayJs invece bisogna reimplementarselo
9
- */
10
- class DayJsDateAdapter extends DateAdapter {
11
- /**
12
- * Costruttore
13
- *
14
- * @ignore
15
- */
16
- constructor(dateLocale) {
17
- super();
18
- this.setLocale(dateLocale);
19
- }
20
- /**
21
- * Imposta il locale utilizzato per tutte le date
22
- *
23
- * @param {string} locale Locale da impostare
24
- */
25
- setLocale(locale) {
26
- super.setLocale(locale);
27
- // il localeData si potrebbe prendere da this.dayJs().localeData(); ma io voglio usare le date solo nel formato italiano quindi cablo quello
28
- switch (locale.toLowerCase()) {
29
- case 'it-it':
30
- case 'it':
31
- import('dayjs/locale/it').then(mod => { this.loadLoacleDataModule(mod.default); });
32
- break;
33
- // In dayjs, nel locale "en" e basta non esistono i 3/4 delle info perché sono le cose generiche ereditate dai locali en-gb, en-au ecc...
34
- // quindi mi baso sul locale inglese Britannico, ma comunque I'ts Coming Rome
35
- case 'en-us':
36
- case 'en-gb':
37
- case 'en':
38
- import('dayjs/locale/en-gb').then(mod => { this.loadLoacleDataModule(mod.default); });
39
- break;
40
- default: throw `Locale non riconosicuto '${locale}'. Locali consentiti: 'it', 'en'`;
41
- }
42
- }
43
- /**
44
- * Effettua il caricamento del localeData coi nomi dei mesi, giorni ecc partendo dal modulo importato
45
- *
46
- * @param {any} mod Modulo caricato contenente il locale desiderato
47
- */
48
- loadLoacleDataModule(mod) {
49
- this._localeData = {
50
- firstDayOfWeek: mod.weekStart,
51
- longMonths: mod.months,
52
- shortMonths: mod.monthsShort,
53
- dates: this.range(31, (i) => this.createDate(2017, 0, i + 1).format('D')),
54
- longDaysOfWeek: mod.weekdays,
55
- shortDaysOfWeek: mod.weekdaysShort,
56
- narrowDaysOfWeek: mod.weekdaysMin,
57
- };
58
- }
59
- /**
60
- * Ottiene le ore da un DayJs
61
- *
62
- * @param {Dayjs} date Data Dayjs
63
- *
64
- * @returns {number} Ore
65
- */
66
- getHour(date) {
67
- return date.get("hour");
68
- }
69
- /**
70
- * Deserializza una data in DayJs
71
- *
72
- * @param {any} value Valore di data a caso
73
- *
74
- * @returns {Dayjs} data in dayjs
75
- */
76
- deserialize(value) {
77
- if (!value)
78
- return null;
79
- var valueConverted = dayjs(value);
80
- if (valueConverted == null || this.isDateInstance(valueConverted) && this.isValid(valueConverted))
81
- return valueConverted;
82
- return this.invalid();
83
- }
84
- /**
85
- * Ottiene i minuti da un DayJs
86
- *
87
- * @param {Dayjs} date Data Dayjs
88
- *
89
- * @returns {number} Minuti
90
- */
91
- getMinute(date) {
92
- return date.get("minute");
93
- }
94
- /**
95
- * Ottiene i secondi da un DayJs
96
- *
97
- * @param {Dayjs} date Data Dayjs
98
- *
99
- * @returns {number} Secondi
100
- */
101
- getSecond(date) {
102
- return date.get("second");
103
- }
104
- /**
105
- * Imposta le ore di una data Dayjs
106
- *
107
- * @param {Dayjs} date Data da modificare
108
- * @param {number} value Valore da impostare per le ore
109
- */
110
- setHour(date, value) {
111
- date.$H = value;
112
- }
113
- /**
114
- * Imposta i minuti di una data Dayjs
115
- *
116
- * @param {Dayjs} date Data da modificare
117
- * @param {number} value Valore da impostare per i minuti
118
- */
119
- setMinute(date, value) {
120
- date.$m = value;
121
- }
122
- /**
123
- * Imposta i secondi di una data Dayjs
124
- *
125
- * @param {Dayjs} date Data da modificare
126
- * @param {number} value Valore da impostare per i secondi
127
- */
128
- setSecond(date, value) {
129
- date.$s = value;
130
- }
131
- /**
132
- * Ottiene l'anno da un DayJs
133
- *
134
- * @param {Dayjs} date Data Dayjs
135
- *
136
- * @returns {number} Anno
137
- */
138
- getYear(date) {
139
- return date.get("year");
140
- }
141
- /**
142
- * Ottiene il mese da un DayJs
143
- *
144
- * @param {Dayjs} date Data Dayjs
145
- *
146
- * @returns {number} Mese
147
- */
148
- getMonth(date) {
149
- return date.get("month");
150
- }
151
- /**
152
- * Ottiene il giorno da un DayJs
153
- *
154
- * @param {Dayjs} date Data Dayjs
155
- *
156
- * @returns {number} Giorno
157
- */
158
- getDate(date) {
159
- return date.get("date");
160
- }
161
- /**
162
- * Ottiene il giorno della settimana da un DayJs
163
- *
164
- * @param {Dayjs} date Data Dayjs
165
- *
166
- * @returns {number} Giorno della settimana da 1 a 7
167
- */
168
- getDayOfWeek(date) {
169
- return date.get("day");
170
- }
171
- /**
172
- * Ottiene i nomi dei mesi
173
- *
174
- * @param {"long" | "short" | "narrow"} style Stile dei nomi richiesto
175
- *
176
- * @returns {string[]} Lista dei mesi espressi in base al parametro **style**
177
- */
178
- getMonthNames(style) {
179
- return style == 'long' ? this._localeData.longMonths : this._localeData.shortMonths;
180
- }
181
- /**
182
- * Ottiene i nomi dei giorni del mese
183
- *
184
- * @returns {string[]} Lista dei giorni del mese (da '1' a '31')
185
- */
186
- getDateNames() {
187
- return this._localeData.dates;
188
- }
189
- /**
190
- * Ottiene i nomi dei giorni della settimana
191
- *
192
- * @param {"long" | "short" | "narrow"} style Stile dei nomi richiesto
193
- *
194
- * @returns {string[]} Lista dei giorni della settimana espressi in base al parametro **style**
195
- */
196
- getDayOfWeekNames(style) {
197
- if (style == 'long')
198
- return this._localeData.longDaysOfWeek;
199
- else if (style == 'short')
200
- return this._localeData.shortDaysOfWeek;
201
- return this._localeData.narrowDaysOfWeek;
202
- }
203
- /**
204
- * Ottiene il nome dell'anno
205
- *
206
- * @param {Dayjs} date Data Dayjs
207
- *
208
- * @returns {string} Anno
209
- */
210
- getYearName(date) {
211
- return this.getYear(date).toString();
212
- }
213
- /**
214
- * Ottiene il primo giorno della settimana
215
- *
216
- * @returns {number} Indice del primo giorno della settimana
217
- */
218
- getFirstDayOfWeek() {
219
- return this._localeData.firstDayOfWeek;
220
- }
221
- /**
222
- * Ottiene il numero di giorni nel mese corrente
223
- *
224
- * @param {Dayjs} date Data Dayjs
225
- *
226
- * @returns {number} Numero di giorni
227
- */
228
- getNumDaysInMonth(date) {
229
- return date.daysInMonth();
230
- }
231
- /**
232
- * Ottiene il clone di una data Dayjs
233
- *
234
- * @param {Dayjs} Data da clonare
235
- *
236
- * @returns {Dayjs} Clone
237
- */
238
- clone(date) {
239
- // Visto che ho modificato l'istanza originale a manazza (vedi setHour, setMinute, setSecond) l'oggetto è danneggiato e per restituire un clone buono
240
- // devo ricrearlo prendendo pezzo per pezzo
241
- // Il mese è un indice 0-11 quindi devo dargli un +1 qua
242
- return dayjs(`${this.getYear(date)}-${this.getMonth(date) + 1}-${this.getDate(date)} ${this.getHour(date)}:${this.getMinute(date)}:${this.getSecond(date)}`);
243
- }
244
- /**
245
- * Crea una data partendo da anno, mese e giorno
246
- *
247
- * @param {number} year Anno
248
- * @param {number} month Mese
249
- * @param {number} date Giorno
250
- *
251
- * @returns {Dayjs} Oggetto generato in base ai parametri **year**, **month**, e **date**
252
- */
253
- createDate(year, month, date) {
254
- if (month < 0 || month > 11)
255
- throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
256
- if (date < 1)
257
- throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
258
- //Il mese è un indice 0-11 quindi devo dargli un +1 qua
259
- const result = dayjs(`${year}-${month + 1}-${date}`);
260
- if (!result.isValid())
261
- throw Error(`Invalid date "${date}" for month with index "${month}".`);
262
- return result;
263
- }
264
- /**
265
- * Restituisce la data che rappresenta la giornata di oggi
266
- *
267
- * @returns {Dayjs} Oggi
268
- */
269
- today() {
270
- return dayjs();
271
- }
272
- /**
273
- * Effettua il parse di una data, eventualmente in base al formato specificato
274
- *
275
- * @param {any} value Valore da parsare
276
- * @param {string} parseFormat Formato in cui leggere il valore
277
- *
278
- * @returns {Dayjs} Data generata
279
- */
280
- parse(value, parseFormat) {
281
- if (value && typeof value == 'string') {
282
- if (value.length == parseFormat.length)
283
- return dayjs(value, parseFormat);
284
- else
285
- return null;
286
- }
287
- return value ? dayjs(value) : null;
288
- }
289
- /**
290
- * Formatta una data in base al formato specificato
291
- *
292
- * @param {Dayjs} date Data da formattare
293
- * @param {string} displayFormat Formato in cui mostrare la data
294
- *
295
- * @returns {string} Data formattata
296
- */
297
- format(date, displayFormat) {
298
- if (!this.isValid(date))
299
- throw Error('DateAdapter: Cannot format invalid date.');
300
- return date.format(displayFormat);
301
- }
302
- /**
303
- * Aggiunge ad una data il numero specificato di anni
304
- *
305
- * @param {Dayjs} date Data a cui aggiungere gli anni
306
- * @param {number} years Anni da aggiungere
307
- *
308
- * @returns {Dayjs} Data con l'aggiunta degli anni specificati
309
- */
310
- addCalendarYears(date, years) {
311
- return date.add(years, "year");
312
- }
313
- /**
314
- * Aggiunge ad una data il numero specificato di mesi
315
- *
316
- * @param {Dayjs} date Data a cui aggiungere i mesi
317
- * @param {months} months Mesi da aggiungere
318
- *
319
- * @returns {Dayjs} Data con l'aggiunta dei mesi specificati
320
- */
321
- addCalendarMonths(date, months) {
322
- return date.add(months, "month");
323
- }
324
- /**
325
- * Aggiunge ad una data il numero specificato di giorni
326
- *
327
- * @param {Dayjs} date Data a cui aggiungere i giorni
328
- * @param {months} days Giorni da aggiungere
329
- *
330
- * @returns {Dayjs} Data con l'aggiunta dei giorni specificati
331
- */
332
- addCalendarDays(date, days) {
333
- return date.add(days, "day");
334
- }
335
- /**
336
- * Trasforma la data specificata in una stringa ISO8601
337
- *
338
- * @param {Dayjs} date Data
339
- *
340
- * @returns {string} Rappresentazione in ISO8601
341
- */
342
- toIso8601(date) {
343
- return date.toISOString();
344
- }
345
- /**
346
- * Controlla se l'oggetto passato è effettivamente un DayJs
347
- *
348
- * @param {any} obj Oggetto da verificare se è una data o meno
349
- *
350
- * @returns {boolean} **true** se l'oggetto è un DayJs, **false** altrimenti
351
- */
352
- isDateInstance(obj) {
353
- return dayjs.isDayjs(obj);
354
- }
355
- /**
356
- * Controlla il DayJs passato e verifica se è valido
357
- *
358
- * @param {Dayjs} date Data da verificare
359
- *
360
- * @returns {boolean} **true** se il DayJs è valido, **false** altrimenti
361
- */
362
- isValid(date) {
363
- return date.isValid();
364
- }
365
- /**
366
- * Restituisce un DayJs invalido
367
- *
368
- * @returns {DayJs} Data Invalida
369
- */
370
- invalid() {
371
- return dayjs("Invalid Date");
372
- }
373
- /**
374
- * Crea un range di una lunghezza specifica e per ogni indice del range richiama un callback che valorizza l'elemento di quell'indice
375
- *
376
- * @param {number} length Lunghezza del range
377
- * @param {Function} valueFunction Callback che deve generare il valore desiderato per ogni indice
378
- *
379
- * @returns {T[]} Array dei valori generati
380
- */
381
- range(length, valueFunction) {
382
- const valuesArray = Array(length);
383
- for (let i = 0; i < length; i++)
384
- valuesArray[i] = valueFunction(i);
385
- return valuesArray;
386
- }
387
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DayJsDateAdapter, deps: [{ token: MAT_DATE_LOCALE }], target: i0.ɵɵFactoryTarget.Injectable }); }
388
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DayJsDateAdapter }); }
389
- }
390
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DayJsDateAdapter, decorators: [{
391
- type: Injectable
392
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
393
- type: Inject,
394
- args: [MAT_DATE_LOCALE]
395
- }] }]; } });
5
+ // Angular
6
+ /**
7
+ * Adapter per permettere a Material di funzionare senza problemi con DayJs. Per altri provider di date (es. moment) l'adapter viene fornito
8
+ * nativamente da Angular. Per DayJs invece bisogna reimplementarselo
9
+ */
10
+ class DayJsDateAdapter extends DateAdapter {
11
+ /**
12
+ * Costruttore
13
+ *
14
+ * @ignore
15
+ */
16
+ constructor(dateLocale) {
17
+ super();
18
+ this.setLocale(dateLocale);
19
+ }
20
+ /**
21
+ * Imposta il locale utilizzato per tutte le date
22
+ *
23
+ * @param {string} locale Locale da impostare
24
+ */
25
+ setLocale(locale) {
26
+ super.setLocale(locale);
27
+ // il localeData si potrebbe prendere da this.dayJs().localeData(); ma io voglio usare le date solo nel formato italiano quindi cablo quello
28
+ switch (locale.toLowerCase()) {
29
+ case 'it-it':
30
+ case 'it':
31
+ import('dayjs/locale/it').then(mod => { this.loadLoacleDataModule(mod.default); });
32
+ break;
33
+ // In dayjs, nel locale "en" e basta non esistono i 3/4 delle info perché sono le cose generiche ereditate dai locali en-gb, en-au ecc...
34
+ // quindi mi baso sul locale inglese Britannico, ma comunque I'ts Coming Rome
35
+ case 'en-us':
36
+ case 'en-gb':
37
+ case 'en':
38
+ import('dayjs/locale/en-gb').then(mod => { this.loadLoacleDataModule(mod.default); });
39
+ break;
40
+ default: throw `Locale non riconosicuto '${locale}'. Locali consentiti: 'it', 'en'`;
41
+ }
42
+ }
43
+ /**
44
+ * Effettua il caricamento del localeData coi nomi dei mesi, giorni ecc partendo dal modulo importato
45
+ *
46
+ * @param {any} mod Modulo caricato contenente il locale desiderato
47
+ */
48
+ loadLoacleDataModule(mod) {
49
+ this._localeData = {
50
+ firstDayOfWeek: mod.weekStart,
51
+ longMonths: mod.months,
52
+ shortMonths: mod.monthsShort,
53
+ dates: this.range(31, (i) => this.createDate(2017, 0, i + 1).format('D')),
54
+ longDaysOfWeek: mod.weekdays,
55
+ shortDaysOfWeek: mod.weekdaysShort,
56
+ narrowDaysOfWeek: mod.weekdaysMin,
57
+ };
58
+ }
59
+ /**
60
+ * Ottiene le ore da un DayJs
61
+ *
62
+ * @param {Dayjs} date Data Dayjs
63
+ *
64
+ * @returns {number} Ore
65
+ */
66
+ getHour(date) {
67
+ return date.get("hour");
68
+ }
69
+ /**
70
+ * Deserializza una data in DayJs
71
+ *
72
+ * @param {any} value Valore di data a caso
73
+ *
74
+ * @returns {Dayjs} data in dayjs
75
+ */
76
+ deserialize(value) {
77
+ if (!value)
78
+ return null;
79
+ var valueConverted = dayjs(value);
80
+ if (valueConverted == null || this.isDateInstance(valueConverted) && this.isValid(valueConverted))
81
+ return valueConverted;
82
+ return this.invalid();
83
+ }
84
+ /**
85
+ * Ottiene i minuti da un DayJs
86
+ *
87
+ * @param {Dayjs} date Data Dayjs
88
+ *
89
+ * @returns {number} Minuti
90
+ */
91
+ getMinute(date) {
92
+ return date.get("minute");
93
+ }
94
+ /**
95
+ * Ottiene i secondi da un DayJs
96
+ *
97
+ * @param {Dayjs} date Data Dayjs
98
+ *
99
+ * @returns {number} Secondi
100
+ */
101
+ getSecond(date) {
102
+ return date.get("second");
103
+ }
104
+ /**
105
+ * Imposta le ore di una data Dayjs
106
+ *
107
+ * @param {Dayjs} date Data da modificare
108
+ * @param {number} value Valore da impostare per le ore
109
+ */
110
+ setHour(date, value) {
111
+ date.$H = value;
112
+ }
113
+ /**
114
+ * Imposta i minuti di una data Dayjs
115
+ *
116
+ * @param {Dayjs} date Data da modificare
117
+ * @param {number} value Valore da impostare per i minuti
118
+ */
119
+ setMinute(date, value) {
120
+ date.$m = value;
121
+ }
122
+ /**
123
+ * Imposta i secondi di una data Dayjs
124
+ *
125
+ * @param {Dayjs} date Data da modificare
126
+ * @param {number} value Valore da impostare per i secondi
127
+ */
128
+ setSecond(date, value) {
129
+ date.$s = value;
130
+ }
131
+ /**
132
+ * Ottiene l'anno da un DayJs
133
+ *
134
+ * @param {Dayjs} date Data Dayjs
135
+ *
136
+ * @returns {number} Anno
137
+ */
138
+ getYear(date) {
139
+ return date.get("year");
140
+ }
141
+ /**
142
+ * Ottiene il mese da un DayJs
143
+ *
144
+ * @param {Dayjs} date Data Dayjs
145
+ *
146
+ * @returns {number} Mese
147
+ */
148
+ getMonth(date) {
149
+ return date.get("month");
150
+ }
151
+ /**
152
+ * Ottiene il giorno da un DayJs
153
+ *
154
+ * @param {Dayjs} date Data Dayjs
155
+ *
156
+ * @returns {number} Giorno
157
+ */
158
+ getDate(date) {
159
+ return date.get("date");
160
+ }
161
+ /**
162
+ * Ottiene il giorno della settimana da un DayJs
163
+ *
164
+ * @param {Dayjs} date Data Dayjs
165
+ *
166
+ * @returns {number} Giorno della settimana da 1 a 7
167
+ */
168
+ getDayOfWeek(date) {
169
+ return date.get("day");
170
+ }
171
+ /**
172
+ * Ottiene i nomi dei mesi
173
+ *
174
+ * @param {"long" | "short" | "narrow"} style Stile dei nomi richiesto
175
+ *
176
+ * @returns {string[]} Lista dei mesi espressi in base al parametro **style**
177
+ */
178
+ getMonthNames(style) {
179
+ return style == 'long' ? this._localeData.longMonths : this._localeData.shortMonths;
180
+ }
181
+ /**
182
+ * Ottiene i nomi dei giorni del mese
183
+ *
184
+ * @returns {string[]} Lista dei giorni del mese (da '1' a '31')
185
+ */
186
+ getDateNames() {
187
+ return this._localeData.dates;
188
+ }
189
+ /**
190
+ * Ottiene i nomi dei giorni della settimana
191
+ *
192
+ * @param {"long" | "short" | "narrow"} style Stile dei nomi richiesto
193
+ *
194
+ * @returns {string[]} Lista dei giorni della settimana espressi in base al parametro **style**
195
+ */
196
+ getDayOfWeekNames(style) {
197
+ if (style == 'long')
198
+ return this._localeData.longDaysOfWeek;
199
+ else if (style == 'short')
200
+ return this._localeData.shortDaysOfWeek;
201
+ return this._localeData.narrowDaysOfWeek;
202
+ }
203
+ /**
204
+ * Ottiene il nome dell'anno
205
+ *
206
+ * @param {Dayjs} date Data Dayjs
207
+ *
208
+ * @returns {string} Anno
209
+ */
210
+ getYearName(date) {
211
+ return this.getYear(date).toString();
212
+ }
213
+ /**
214
+ * Ottiene il primo giorno della settimana
215
+ *
216
+ * @returns {number} Indice del primo giorno della settimana
217
+ */
218
+ getFirstDayOfWeek() {
219
+ return this._localeData.firstDayOfWeek;
220
+ }
221
+ /**
222
+ * Ottiene il numero di giorni nel mese corrente
223
+ *
224
+ * @param {Dayjs} date Data Dayjs
225
+ *
226
+ * @returns {number} Numero di giorni
227
+ */
228
+ getNumDaysInMonth(date) {
229
+ return date.daysInMonth();
230
+ }
231
+ /**
232
+ * Ottiene il clone di una data Dayjs
233
+ *
234
+ * @param {Dayjs} Data da clonare
235
+ *
236
+ * @returns {Dayjs} Clone
237
+ */
238
+ clone(date) {
239
+ // Visto che ho modificato l'istanza originale a manazza (vedi setHour, setMinute, setSecond) l'oggetto è danneggiato e per restituire un clone buono
240
+ // devo ricrearlo prendendo pezzo per pezzo
241
+ // Il mese è un indice 0-11 quindi devo dargli un +1 qua
242
+ return dayjs(`${this.getYear(date)}-${this.getMonth(date) + 1}-${this.getDate(date)} ${this.getHour(date)}:${this.getMinute(date)}:${this.getSecond(date)}`);
243
+ }
244
+ /**
245
+ * Crea una data partendo da anno, mese e giorno
246
+ *
247
+ * @param {number} year Anno
248
+ * @param {number} month Mese
249
+ * @param {number} date Giorno
250
+ *
251
+ * @returns {Dayjs} Oggetto generato in base ai parametri **year**, **month**, e **date**
252
+ */
253
+ createDate(year, month, date) {
254
+ if (month < 0 || month > 11)
255
+ throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
256
+ if (date < 1)
257
+ throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
258
+ //Il mese è un indice 0-11 quindi devo dargli un +1 qua
259
+ const result = dayjs(`${year}-${month + 1}-${date}`);
260
+ if (!result.isValid())
261
+ throw Error(`Invalid date "${date}" for month with index "${month}".`);
262
+ return result;
263
+ }
264
+ /**
265
+ * Restituisce la data che rappresenta la giornata di oggi
266
+ *
267
+ * @returns {Dayjs} Oggi
268
+ */
269
+ today() {
270
+ return dayjs();
271
+ }
272
+ /**
273
+ * Effettua il parse di una data, eventualmente in base al formato specificato
274
+ *
275
+ * @param {any} value Valore da parsare
276
+ * @param {string} parseFormat Formato in cui leggere il valore
277
+ *
278
+ * @returns {Dayjs} Data generata
279
+ */
280
+ parse(value, parseFormat) {
281
+ if (value && typeof value == 'string') {
282
+ if (value.length == parseFormat.length)
283
+ return dayjs(value, parseFormat);
284
+ else
285
+ return null;
286
+ }
287
+ return value ? dayjs(value) : null;
288
+ }
289
+ /**
290
+ * Formatta una data in base al formato specificato
291
+ *
292
+ * @param {Dayjs} date Data da formattare
293
+ * @param {string} displayFormat Formato in cui mostrare la data
294
+ *
295
+ * @returns {string} Data formattata
296
+ */
297
+ format(date, displayFormat) {
298
+ if (!this.isValid(date))
299
+ throw Error('DateAdapter: Cannot format invalid date.');
300
+ return date.format(displayFormat);
301
+ }
302
+ /**
303
+ * Aggiunge ad una data il numero specificato di anni
304
+ *
305
+ * @param {Dayjs} date Data a cui aggiungere gli anni
306
+ * @param {number} years Anni da aggiungere
307
+ *
308
+ * @returns {Dayjs} Data con l'aggiunta degli anni specificati
309
+ */
310
+ addCalendarYears(date, years) {
311
+ return date.add(years, "year");
312
+ }
313
+ /**
314
+ * Aggiunge ad una data il numero specificato di mesi
315
+ *
316
+ * @param {Dayjs} date Data a cui aggiungere i mesi
317
+ * @param {months} months Mesi da aggiungere
318
+ *
319
+ * @returns {Dayjs} Data con l'aggiunta dei mesi specificati
320
+ */
321
+ addCalendarMonths(date, months) {
322
+ return date.add(months, "month");
323
+ }
324
+ /**
325
+ * Aggiunge ad una data il numero specificato di giorni
326
+ *
327
+ * @param {Dayjs} date Data a cui aggiungere i giorni
328
+ * @param {months} days Giorni da aggiungere
329
+ *
330
+ * @returns {Dayjs} Data con l'aggiunta dei giorni specificati
331
+ */
332
+ addCalendarDays(date, days) {
333
+ return date.add(days, "day");
334
+ }
335
+ /**
336
+ * Trasforma la data specificata in una stringa ISO8601
337
+ *
338
+ * @param {Dayjs} date Data
339
+ *
340
+ * @returns {string} Rappresentazione in ISO8601
341
+ */
342
+ toIso8601(date) {
343
+ return date.toISOString();
344
+ }
345
+ /**
346
+ * Controlla se l'oggetto passato è effettivamente un DayJs
347
+ *
348
+ * @param {any} obj Oggetto da verificare se è una data o meno
349
+ *
350
+ * @returns {boolean} **true** se l'oggetto è un DayJs, **false** altrimenti
351
+ */
352
+ isDateInstance(obj) {
353
+ return dayjs.isDayjs(obj);
354
+ }
355
+ /**
356
+ * Controlla il DayJs passato e verifica se è valido
357
+ *
358
+ * @param {Dayjs} date Data da verificare
359
+ *
360
+ * @returns {boolean} **true** se il DayJs è valido, **false** altrimenti
361
+ */
362
+ isValid(date) {
363
+ return date.isValid();
364
+ }
365
+ /**
366
+ * Restituisce un DayJs invalido
367
+ *
368
+ * @returns {DayJs} Data Invalida
369
+ */
370
+ invalid() {
371
+ return dayjs("Invalid Date");
372
+ }
373
+ /**
374
+ * Crea un range di una lunghezza specifica e per ogni indice del range richiama un callback che valorizza l'elemento di quell'indice
375
+ *
376
+ * @param {number} length Lunghezza del range
377
+ * @param {Function} valueFunction Callback che deve generare il valore desiderato per ogni indice
378
+ *
379
+ * @returns {T[]} Array dei valori generati
380
+ */
381
+ range(length, valueFunction) {
382
+ const valuesArray = Array(length);
383
+ for (let i = 0; i < length; i++)
384
+ valuesArray[i] = valueFunction(i);
385
+ return valuesArray;
386
+ }
387
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DayJsDateAdapter, deps: [{ token: MAT_DATE_LOCALE }], target: i0.ɵɵFactoryTarget.Injectable }); }
388
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DayJsDateAdapter }); }
389
+ }
390
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: DayJsDateAdapter, decorators: [{
391
+ type: Injectable
392
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
393
+ type: Inject,
394
+ args: [MAT_DATE_LOCALE]
395
+ }] }] });
396
396
 
397
- /**
398
- * Formati di default per la presentazione degli input quali il DatePicker di Angular Material.
399
- * Cablati a quelli italiani ignorando quelli di BurgerLand per non impazzire
400
- */
401
- const MAT_DAYJS_DATE_FORMATS = {
402
- parse: { dateInput: 'DD/MM/YYYY' },
403
- display: {
404
- dateInput: 'DD/MM/YYYY',
405
- monthYearLabel: 'MM YYYY',
406
- dateA11yLabel: 'DD/MM/YYYY',
407
- monthYearA11yLabel: 'MM YYYY',
408
- }
409
- };
410
- class MatDayjsDateModule {
411
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MatDayjsDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
412
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: MatDayjsDateModule }); }
413
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MatDayjsDateModule, providers: [
414
- { provide: MAT_DATE_FORMATS, useValue: MAT_DAYJS_DATE_FORMATS },
415
- { provide: DateAdapter, useClass: DayJsDateAdapter, deps: [MAT_DATE_LOCALE] }
416
- ] }); }
417
- }
418
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MatDayjsDateModule, decorators: [{
419
- type: NgModule,
420
- args: [{
421
- providers: [
422
- { provide: MAT_DATE_FORMATS, useValue: MAT_DAYJS_DATE_FORMATS },
423
- { provide: DateAdapter, useClass: DayJsDateAdapter, deps: [MAT_DATE_LOCALE] }
424
- ],
425
- }]
397
+ /**
398
+ * Formati di default per la presentazione degli input quali il DatePicker di Angular Material.
399
+ * Cablati a quelli italiani ignorando quelli di BurgerLand per non impazzire
400
+ */
401
+ const MAT_DAYJS_DATE_FORMATS = {
402
+ parse: { dateInput: 'DD/MM/YYYY' },
403
+ display: {
404
+ dateInput: 'DD/MM/YYYY',
405
+ monthYearLabel: 'MM YYYY',
406
+ dateA11yLabel: 'DD/MM/YYYY',
407
+ monthYearA11yLabel: 'MM YYYY',
408
+ }
409
+ };
410
+ class MatDayjsDateModule {
411
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MatDayjsDateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
412
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: MatDayjsDateModule }); }
413
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MatDayjsDateModule, providers: [
414
+ { provide: MAT_DATE_FORMATS, useValue: MAT_DAYJS_DATE_FORMATS },
415
+ { provide: DateAdapter, useClass: DayJsDateAdapter, deps: [MAT_DATE_LOCALE] }
416
+ ] }); }
417
+ }
418
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: MatDayjsDateModule, decorators: [{
419
+ type: NgModule,
420
+ args: [{
421
+ providers: [
422
+ { provide: MAT_DATE_FORMATS, useValue: MAT_DAYJS_DATE_FORMATS },
423
+ { provide: DateAdapter, useClass: DayJsDateAdapter, deps: [MAT_DATE_LOCALE] }
424
+ ],
425
+ }]
426
426
  }] });
427
427
 
428
- /*
429
- * Public API Surface of material-dayjs-adapter
428
+ /*
429
+ * Public API Surface of material-dayjs-adapter
430
430
  */
431
431
 
432
- /**
433
- * Generated bundle index. Do not edit.
432
+ /**
433
+ * Generated bundle index. Do not edit.
434
434
  */
435
435
 
436
436
  export { DayJsDateAdapter, MAT_DAYJS_DATE_FORMATS, MatDayjsDateModule };