@onemrvapublic/design-system 18.2.16-develop.1 → 18.2.16-develop.10

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.
Files changed (41) hide show
  1. package/esm2022/mat-paginator/src/onemrva-mat-paginator.component.mjs +6 -2
  2. package/esm2022/shared/index.mjs +2 -2
  3. package/esm2022/shared/src/lib/adapters/index.mjs +3 -3
  4. package/esm2022/shared/src/lib/adapters/luxon.date.adapter.mjs +253 -0
  5. package/esm2022/shared/src/lib/adapters/luxon.utils.mjs +23 -0
  6. package/esm2022/shared/src/lib/adapters/native.date.adapter.mjs +66 -0
  7. package/esm2022/shared/src/lib/constants/date.format.mjs +5 -5
  8. package/esm2022/shared/src/lib/providers/index.mjs +5 -0
  9. package/esm2022/shared/src/lib/providers/onemrva.date.luxon.provider.mjs +16 -0
  10. package/esm2022/shared/src/lib/providers/onemrva.date.luxon.year.month.provider.mjs +16 -0
  11. package/esm2022/shared/src/lib/providers/onemrva.date.native.provider.mjs +16 -0
  12. package/esm2022/shared/src/lib/providers/onemrva.date.native.year.month.provider.mjs +16 -0
  13. package/fesm2022/onemrvapublic-design-system-mat-paginator.mjs +5 -1
  14. package/fesm2022/onemrvapublic-design-system-mat-paginator.mjs.map +1 -1
  15. package/fesm2022/onemrvapublic-design-system-shared.mjs +327 -221
  16. package/fesm2022/onemrvapublic-design-system-shared.mjs.map +1 -1
  17. package/mat-paginator/src/onemrva-mat-paginator.component.d.ts +1 -0
  18. package/package.json +1 -1
  19. package/shared/index.d.ts +1 -1
  20. package/shared/src/lib/adapters/index.d.ts +2 -2
  21. package/shared/src/lib/adapters/luxon.date.adapter.d.ts +50 -0
  22. package/shared/src/lib/adapters/luxon.utils.d.ts +26 -0
  23. package/shared/src/lib/adapters/{date.adapter.d.ts → native.date.adapter.d.ts} +6 -5
  24. package/shared/src/lib/providers/index.d.ts +4 -0
  25. package/shared/src/lib/providers/onemrva.date.luxon.provider.d.ts +2 -0
  26. package/shared/src/lib/providers/onemrva.date.luxon.year.month.provider.d.ts +2 -0
  27. package/shared/src/lib/providers/onemrva.date.native.provider.d.ts +2 -0
  28. package/shared/src/lib/providers/onemrva.date.native.year.month.provider.d.ts +2 -0
  29. package/esm2022/shared/src/lib/adapters/date.adapter.mjs +0 -62
  30. package/esm2022/shared/src/lib/adapters/year-month.adapter.mjs +0 -62
  31. package/esm2022/shared/src/lib/modules/index.mjs +0 -5
  32. package/esm2022/shared/src/lib/modules/shared.datepicker.luxon.module.mjs +0 -46
  33. package/esm2022/shared/src/lib/modules/shared.datepicker.luxon.year.month.module.mjs +0 -46
  34. package/esm2022/shared/src/lib/modules/shared.datepicker.native.module.mjs +0 -51
  35. package/esm2022/shared/src/lib/modules/shared.datepicker.native.year.month.module.mjs +0 -51
  36. package/shared/src/lib/adapters/year-month.adapter.d.ts +0 -16
  37. package/shared/src/lib/modules/index.d.ts +0 -4
  38. package/shared/src/lib/modules/shared.datepicker.luxon.module.d.ts +0 -12
  39. package/shared/src/lib/modules/shared.datepicker.luxon.year.month.module.d.ts +0 -12
  40. package/shared/src/lib/modules/shared.datepicker.native.module.d.ts +0 -12
  41. package/shared/src/lib/modules/shared.datepicker.native.year.month.module.d.ts +0 -12
@@ -15,13 +15,10 @@ import { catchError as catchError$1, map, startWith as startWith$1 } from 'rxjs/
15
15
  import * as i1$3 from '@angular/common/http';
16
16
  import { __decorate } from 'tslib';
17
17
  import * as i1$4 from '@ngx-translate/core';
18
- import { TranslateModule, TranslateService } from '@ngx-translate/core';
19
18
  import { countrySpecs, validateIBAN, electronicFormatIBAN, ValidationErrorsIBAN } from 'ibantools';
20
- import { DateAdapter, MatNativeDateModule, MAT_DATE_LOCALE, MAT_DATE_FORMATS, NativeDateAdapter } from '@angular/material/core';
21
- import { MatDatepickerModule } from '@angular/material/datepicker';
19
+ import { NativeDateAdapter, DateAdapter, MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core';
20
+ import { DateTime, Info } from 'luxon';
22
21
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
23
- import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter';
24
- import { DateTime } from 'luxon';
25
22
 
26
23
  class ClipboardIconComponent {
27
24
  constructor(_elementRef, clipboardService) {
@@ -104,8 +101,8 @@ const ONEMRVA_MAT_NATIVE_DATE_FORMAT = {
104
101
  },
105
102
  display: {
106
103
  dateInput: 'dd/MM/yyyy',
107
- monthYearLabel: 'MMM yyyy',
108
- dateA11yLabel: 'DDD',
104
+ monthYearLabel: 'LL / yyyy',
105
+ dateA11yLabel: 'LL',
109
106
  monthYearA11yLabel: 'MMMM yyyy',
110
107
  },
111
108
  };
@@ -115,8 +112,8 @@ const ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT = {
115
112
  },
116
113
  display: {
117
114
  dateInput: 'dd/MM/yyyy',
118
- monthYearLabel: 'MMM yyyy',
119
- dateA11yLabel: 'DDD',
115
+ monthYearLabel: 'LL / yyyy',
116
+ dateA11yLabel: 'LL',
120
117
  monthYearA11yLabel: 'MMM yyyy',
121
118
  },
122
119
  };
@@ -1339,198 +1336,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
1339
1336
  }]
1340
1337
  }] });
1341
1338
 
1342
- class OnemrvaDatepickerLuxonSharedModule {
1343
- constructor(translateService) {
1344
- this._adapter = inject(DateAdapter);
1345
- translateService.onLangChange
1346
- .pipe(takeUntilDestroyed())
1347
- .subscribe(value => {
1348
- this._adapter.setLocale(value.lang);
1349
- });
1350
- }
1351
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonSharedModule, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.NgModule }); }
1352
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonSharedModule, imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1353
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonSharedModule, providers: [
1354
- {
1355
- provide: MAT_DATE_LOCALE,
1356
- useFactory: (translateService) => translateService.currentLang,
1357
- deps: [TranslateService],
1358
- },
1359
- provideLuxonDateAdapter(ONEMRVA_MAT_LUXON_DATE_FORMATS),
1360
- ], imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1361
- }
1362
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonSharedModule, decorators: [{
1363
- type: NgModule,
1364
- args: [{
1365
- declarations: [],
1366
- imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule],
1367
- exports: [],
1368
- providers: [
1369
- {
1370
- provide: MAT_DATE_LOCALE,
1371
- useFactory: (translateService) => translateService.currentLang,
1372
- deps: [TranslateService],
1373
- },
1374
- provideLuxonDateAdapter(ONEMRVA_MAT_LUXON_DATE_FORMATS),
1375
- ],
1376
- }]
1377
- }], ctorParameters: () => [{ type: i1$4.TranslateService }] });
1378
-
1379
- class OnemrvaDatepickerSharedModule {
1380
- constructor(translateService) {
1381
- this._adapter = inject(DateAdapter);
1382
- translateService.onLangChange
1383
- .pipe(takeUntilDestroyed())
1384
- .subscribe(value => {
1385
- this._adapter.setLocale(value.lang);
1386
- });
1387
- }
1388
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerSharedModule, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.NgModule }); }
1389
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerSharedModule, imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1390
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerSharedModule, providers: [
1391
- {
1392
- provide: MAT_DATE_LOCALE,
1393
- useFactory: (translateService) => translateService.currentLang,
1394
- deps: [TranslateService],
1395
- },
1396
- {
1397
- provide: MAT_DATE_FORMATS,
1398
- useValue: ONEMRVA_MAT_NATIVE_DATE_FORMAT,
1399
- },
1400
- ], imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1401
- }
1402
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerSharedModule, decorators: [{
1403
- type: NgModule,
1404
- args: [{
1405
- declarations: [],
1406
- imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule],
1407
- exports: [],
1408
- providers: [
1409
- {
1410
- provide: MAT_DATE_LOCALE,
1411
- useFactory: (translateService) => translateService.currentLang,
1412
- deps: [TranslateService],
1413
- },
1414
- {
1415
- provide: MAT_DATE_FORMATS,
1416
- useValue: ONEMRVA_MAT_NATIVE_DATE_FORMAT,
1417
- },
1418
- ],
1419
- }]
1420
- }], ctorParameters: () => [{ type: i1$4.TranslateService }] });
1421
-
1422
- class OnemrvaDatepickerYearMonthSharedModule {
1423
- constructor(translateService) {
1424
- this._adapter = inject(DateAdapter);
1425
- translateService.onLangChange
1426
- .pipe(takeUntilDestroyed())
1427
- .subscribe(value => {
1428
- this._adapter.setLocale(value.lang);
1429
- });
1430
- }
1431
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerYearMonthSharedModule, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.NgModule }); }
1432
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerYearMonthSharedModule, imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1433
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerYearMonthSharedModule, providers: [
1434
- {
1435
- provide: MAT_DATE_LOCALE,
1436
- useFactory: (translateService) => translateService.currentLang,
1437
- deps: [TranslateService],
1438
- },
1439
- {
1440
- provide: MAT_DATE_FORMATS,
1441
- useValue: ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT,
1442
- },
1443
- ], imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1444
- }
1445
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerYearMonthSharedModule, decorators: [{
1446
- type: NgModule,
1447
- args: [{
1448
- declarations: [],
1449
- imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule],
1450
- exports: [],
1451
- providers: [
1452
- {
1453
- provide: MAT_DATE_LOCALE,
1454
- useFactory: (translateService) => translateService.currentLang,
1455
- deps: [TranslateService],
1456
- },
1457
- {
1458
- provide: MAT_DATE_FORMATS,
1459
- useValue: ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT,
1460
- },
1461
- ],
1462
- }]
1463
- }], ctorParameters: () => [{ type: i1$4.TranslateService }] });
1464
-
1465
- class OnemrvaDatepickerLuxonYearMonthSharedModule {
1466
- constructor(translateService) {
1467
- this._adapter = inject(DateAdapter);
1468
- translateService.onLangChange
1469
- .pipe(takeUntilDestroyed())
1470
- .subscribe(value => {
1471
- this._adapter.setLocale(value.lang);
1472
- });
1473
- }
1474
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonYearMonthSharedModule, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.NgModule }); }
1475
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonYearMonthSharedModule, imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1476
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonYearMonthSharedModule, providers: [
1477
- {
1478
- provide: MAT_DATE_LOCALE,
1479
- useFactory: (translateService) => translateService.currentLang,
1480
- deps: [TranslateService],
1481
- },
1482
- provideLuxonDateAdapter(ONEMRVA_MAT_LUXON_YEAR_MONTH_FORMATS),
1483
- ], imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule] }); }
1484
- }
1485
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDatepickerLuxonYearMonthSharedModule, decorators: [{
1486
- type: NgModule,
1487
- args: [{
1488
- declarations: [],
1489
- imports: [MatDatepickerModule, TranslateModule, MatNativeDateModule],
1490
- exports: [],
1491
- providers: [
1492
- {
1493
- provide: MAT_DATE_LOCALE,
1494
- useFactory: (translateService) => translateService.currentLang,
1495
- deps: [TranslateService],
1496
- },
1497
- provideLuxonDateAdapter(ONEMRVA_MAT_LUXON_YEAR_MONTH_FORMATS),
1498
- ],
1499
- }]
1500
- }], ctorParameters: () => [{ type: i1$4.TranslateService }] });
1501
-
1502
- class OnemrvaDateAdapter extends NativeDateAdapter {
1339
+ class OnemrvaNativeDateAdapter extends NativeDateAdapter {
1503
1340
  constructor(translateService) {
1504
1341
  super();
1505
1342
  this.translateService = translateService;
1506
- this.dateFormat = ONEMRVA_MAT_NATIVE_DATE_FORMAT.display.dateInput;
1507
1343
  this.destroyNotifier$ = new Subject();
1344
+ this.localeChanges = new Subject();
1508
1345
  this.setLocale(this.translateService.currentLang);
1509
- this.translateService.onLangChange
1510
- .pipe(takeUntil(this.destroyNotifier$))
1511
- .subscribe(({ lang }) => {
1512
- this.setLocale(lang);
1513
- });
1346
+ this.localeChanges.next(this);
1347
+ if (this.translateService !== undefined) {
1348
+ this.translateService.onLangChange
1349
+ .pipe(takeUntil(this.destroyNotifier$))
1350
+ .subscribe(({ lang }) => {
1351
+ this.setLocale(lang);
1352
+ this.localeChanges.next(this);
1353
+ });
1354
+ }
1514
1355
  }
1515
- format(date) {
1356
+ format(date, formats) {
1516
1357
  const dt = DateTime.fromJSDate(date);
1517
- return dt.toFormat(this.dateFormat);
1358
+ return dt.toFormat(formats);
1518
1359
  }
1519
1360
  parse(value) {
1361
+ const formats = ONEMRVA_MAT_NATIVE_DATE_FORMAT;
1520
1362
  if (value && typeof value === 'string') {
1521
1363
  value = value.replace(/\D/g, '/');
1522
1364
  }
1523
1365
  if (value === null || value === '') {
1524
1366
  return null;
1525
1367
  }
1526
- const dt = DateTime.fromFormat(value, this.dateFormat, {
1368
+ const dt = DateTime.fromFormat(value, formats.display.dateInput, {
1527
1369
  locale: this.locale,
1528
1370
  });
1529
1371
  if (dt.isValid) {
1530
1372
  return dt.toJSDate();
1531
1373
  }
1532
- const formats = ['ddMMyyyy', 'd/M/yyyy', 'dd/M/yyyy', 'd/MM/yyyy'];
1533
- for (const format of formats) {
1374
+ for (const format of formats.parse.dateInput) {
1534
1375
  const parsed = DateTime.fromFormat(value, format, {
1535
1376
  locale: this.locale,
1536
1377
  });
@@ -1547,68 +1388,333 @@ class OnemrvaDateAdapter extends NativeDateAdapter {
1547
1388
  this.destroyNotifier$.next();
1548
1389
  this.destroyNotifier$.complete();
1549
1390
  }
1550
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDateAdapter, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1551
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDateAdapter }); }
1391
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaNativeDateAdapter, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1392
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaNativeDateAdapter }); }
1552
1393
  }
1553
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaDateAdapter, decorators: [{
1394
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaNativeDateAdapter, decorators: [{
1554
1395
  type: Injectable
1555
1396
  }], ctorParameters: () => [{ type: i1$4.TranslateService }] });
1556
1397
 
1557
- class OnemrvaYearMonthAdapter extends NativeDateAdapter {
1398
+ /** InjectionToken for LuxonDateAdapter to configure options. */
1399
+ const MAT_LUXON_DATE_ADAPTER_OPTIONS = new InjectionToken('MAT_LUXON_DATE_ADAPTER_OPTIONS', {
1400
+ providedIn: 'root',
1401
+ factory: MAT_LUXON_DATE_ADAPTER_OPTIONS_FACTORY,
1402
+ });
1403
+ /** @docs-private */
1404
+ function MAT_LUXON_DATE_ADAPTER_OPTIONS_FACTORY() {
1405
+ return {
1406
+ useUtc: false,
1407
+ firstDayOfWeek: 0,
1408
+ defaultOutputCalendar: 'gregory',
1409
+ };
1410
+ }
1411
+ /** Creates an array and fills it with values. */
1412
+ function luxonRange(length, valueFunction) {
1413
+ const valuesArray = Array(length);
1414
+ for (let i = 0; i < length; i++) {
1415
+ valuesArray[i] = valueFunction(i);
1416
+ }
1417
+ return valuesArray;
1418
+ }
1419
+
1420
+ /**
1421
+ * @license
1422
+ * Copyright Google LLC All Rights Reserved.
1423
+ *
1424
+ * Use of this source code is governed by an MIT-style license that can be
1425
+ * found in the LICENSE file at https://angular.dev/license
1426
+ */
1427
+ /** Adapts Luxon Dates for use with Angular Material. */
1428
+ class OnemrvaLuxonDateAdapter extends DateAdapter {
1558
1429
  constructor(translateService) {
1559
1430
  super();
1560
1431
  this.translateService = translateService;
1561
- this.dateFormat = ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT.display.monthYearLabel;
1562
- this.destroyNotifier$ = new Subject();
1432
+ const dateLocale = inject(MAT_DATE_LOCALE, { optional: true });
1433
+ const options = inject(MAT_LUXON_DATE_ADAPTER_OPTIONS, {
1434
+ optional: true,
1435
+ });
1436
+ this._useUTC = !!options?.useUtc;
1437
+ this._firstDayOfWeek = options?.firstDayOfWeek || 0;
1438
+ this._defaultOutputCalendar = options?.defaultOutputCalendar || 'gregory';
1439
+ this.setLocale(dateLocale || DateTime.local().locale);
1563
1440
  this.setLocale(this.translateService.currentLang);
1564
- this.translateService.onLangChange
1565
- .pipe(takeUntil(this.destroyNotifier$))
1566
- .subscribe(({ lang }) => {
1567
- this.setLocale(lang);
1441
+ if (this.translateService !== undefined) {
1442
+ this.translateService.onLangChange
1443
+ .pipe(takeUntilDestroyed())
1444
+ .subscribe(({ lang }) => {
1445
+ this.setLocale(lang);
1446
+ });
1447
+ }
1448
+ }
1449
+ getYear(date) {
1450
+ return date.year;
1451
+ }
1452
+ getMonth(date) {
1453
+ // Luxon works with 1-indexed months whereas our code expects 0-indexed.
1454
+ return date.month - 1;
1455
+ }
1456
+ getDate(date) {
1457
+ return date.day;
1458
+ }
1459
+ getDayOfWeek(date) {
1460
+ return date.weekday;
1461
+ }
1462
+ getMonthNames(style) {
1463
+ // Adding outputCalendar option, because LuxonInfo doesn't get effected by LuxonSettings
1464
+ return Info.months(style, {
1465
+ locale: this.locale,
1466
+ outputCalendar: this._defaultOutputCalendar,
1568
1467
  });
1569
1468
  }
1570
- format(date) {
1571
- const dt = DateTime.fromJSDate(date);
1572
- return dt.toFormat(this.dateFormat);
1469
+ getDateNames() {
1470
+ // At the time of writing, Luxon doesn't offer similar
1471
+ // functionality so we have to fall back to the Intl API.
1472
+ const dtf = new Intl.DateTimeFormat(this.locale, {
1473
+ day: 'numeric',
1474
+ timeZone: 'utc',
1475
+ });
1476
+ // Format a UTC date in order to avoid DST issues.
1477
+ return luxonRange(31, i => dtf.format(DateTime.utc(2017, 1, i + 1).toJSDate()));
1573
1478
  }
1574
- parse(value) {
1575
- if (value && typeof value === 'string') {
1576
- value = value.replace(/\D/g, '/');
1479
+ getDayOfWeekNames(style) {
1480
+ // Note that we shift the array once, because Luxon returns Monday as the
1481
+ // first day of the week, whereas our logic assumes that it's Sunday. See:
1482
+ // https://moment.github.io/luxon/api-docs/index.html#infoweekdays
1483
+ const days = Info.weekdays(style, { locale: this.locale });
1484
+ days.unshift(days.pop());
1485
+ return days;
1486
+ }
1487
+ getYearName(date) {
1488
+ return date.toFormat('yyyy', this._getOptions());
1489
+ }
1490
+ getFirstDayOfWeek() {
1491
+ return this._firstDayOfWeek;
1492
+ }
1493
+ getNumDaysInMonth(date) {
1494
+ return date.daysInMonth;
1495
+ }
1496
+ clone(date) {
1497
+ return DateTime.fromObject(date.toObject(), this._getOptions());
1498
+ }
1499
+ createDate(year, month, date) {
1500
+ const options = this._getOptions();
1501
+ if (month < 0 || month > 11) {
1502
+ throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
1577
1503
  }
1578
- if (value === null || value === '') {
1579
- return null;
1504
+ if (date < 1) {
1505
+ throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
1580
1506
  }
1581
- const dt = DateTime.fromFormat(value, this.dateFormat, {
1582
- locale: this.locale,
1583
- });
1584
- if (dt.isValid) {
1585
- return dt.toJSDate();
1507
+ // Luxon uses 1-indexed months so we need to add one to the month.
1508
+ const result = this._useUTC
1509
+ ? DateTime.utc(year, month + 1, date, options)
1510
+ : DateTime.local(year, month + 1, date, options);
1511
+ if (!this.isValid(result)) {
1512
+ throw Error(`Invalid date "${date}". Reason: "${result.invalidReason}".`);
1586
1513
  }
1587
- const formats = ['MMyyyy', 'M/yyyy', 'MM/yyyy'];
1588
- for (const format of formats) {
1589
- const parsed = DateTime.fromFormat(value, format, {
1590
- locale: this.locale,
1591
- });
1592
- if (parsed.isValid) {
1593
- return parsed.toJSDate();
1514
+ return result;
1515
+ }
1516
+ today() {
1517
+ const options = this._getOptions();
1518
+ return this._useUTC
1519
+ ? DateTime.utc(options)
1520
+ : DateTime.local(options);
1521
+ }
1522
+ parse(value, parseFormat) {
1523
+ const options = this._getOptions();
1524
+ if (typeof value == 'string' && value.length > 0) {
1525
+ // This is screwing things up as 062005 would become 05 0602
1526
+ // const iso8601Date = LuxonDateTime.fromISO(value, options);
1527
+ //
1528
+ // if (this.isValid(iso8601Date)) {
1529
+ // console.log(iso8601Date);
1530
+ // return iso8601Date;
1531
+ // }
1532
+ const formats = Array.isArray(parseFormat) ? parseFormat : [parseFormat];
1533
+ if (!parseFormat.length) {
1534
+ throw Error('Formats array must not be empty.');
1594
1535
  }
1536
+ console.log(formats);
1537
+ for (const format of formats) {
1538
+ console.log(format);
1539
+ const fromFormat = DateTime.fromFormat(value, format, options);
1540
+ if (this.isValid(fromFormat)) {
1541
+ return fromFormat;
1542
+ }
1543
+ }
1544
+ return this.invalid();
1595
1545
  }
1596
- return this.invalid();
1546
+ else if (typeof value === 'number') {
1547
+ return DateTime.fromMillis(value, options);
1548
+ }
1549
+ else if (value instanceof Date) {
1550
+ return DateTime.fromJSDate(value, options);
1551
+ }
1552
+ else if (value instanceof DateTime) {
1553
+ return DateTime.fromMillis(value.toMillis(), options);
1554
+ }
1555
+ return null;
1597
1556
  }
1598
- getFirstDayOfWeek() {
1599
- return 1;
1557
+ format(date, displayFormat) {
1558
+ if (!this.isValid(date)) {
1559
+ throw Error('LuxonDateAdapter: Cannot format invalid date.');
1560
+ }
1561
+ if (this._useUTC) {
1562
+ return date.setLocale(this.locale).setZone('utc').toFormat(displayFormat);
1563
+ }
1564
+ else {
1565
+ return date.setLocale(this.locale).toFormat(displayFormat);
1566
+ }
1600
1567
  }
1601
- ngOnDestroy() {
1602
- this.destroyNotifier$.next();
1603
- this.destroyNotifier$.complete();
1568
+ addCalendarYears(date, years) {
1569
+ return date.reconfigure(this._getOptions()).plus({ years });
1570
+ }
1571
+ addCalendarMonths(date, months) {
1572
+ return date.reconfigure(this._getOptions()).plus({ months });
1604
1573
  }
1605
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaYearMonthAdapter, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1606
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaYearMonthAdapter }); }
1574
+ addCalendarDays(date, days) {
1575
+ return date.reconfigure(this._getOptions()).plus({ days });
1576
+ }
1577
+ toIso8601(date) {
1578
+ return date.toISO();
1579
+ }
1580
+ /**
1581
+ * Returns the given value if given a valid Luxon or null. Deserializes valid ISO 8601 strings
1582
+ * (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid DateTime and empty
1583
+ * string into null. Returns an invalid date for all other values.
1584
+ */
1585
+ deserialize(value) {
1586
+ const options = this._getOptions();
1587
+ let date;
1588
+ if (value instanceof Date) {
1589
+ date = DateTime.fromJSDate(value, options);
1590
+ }
1591
+ if (typeof value === 'string') {
1592
+ if (!value) {
1593
+ return null;
1594
+ }
1595
+ date = DateTime.fromISO(value, options);
1596
+ }
1597
+ if (date && this.isValid(date)) {
1598
+ return date;
1599
+ }
1600
+ return super.deserialize(value);
1601
+ }
1602
+ isDateInstance(obj) {
1603
+ return obj instanceof DateTime;
1604
+ }
1605
+ isValid(date) {
1606
+ return date.isValid;
1607
+ }
1608
+ invalid() {
1609
+ return DateTime.invalid('Invalid Luxon DateTime object.');
1610
+ }
1611
+ setTime(target, hours, minutes, seconds) {
1612
+ //if (typeof ngDevMode === 'undefined' || ngDevMode) {
1613
+ if (hours < 0 || hours > 23) {
1614
+ throw Error(`Invalid hours "${hours}". Hours value must be between 0 and 23.`);
1615
+ }
1616
+ if (minutes < 0 || minutes > 59) {
1617
+ throw Error(`Invalid minutes "${minutes}". Minutes value must be between 0 and 59.`);
1618
+ }
1619
+ if (seconds < 0 || seconds > 59) {
1620
+ throw Error(`Invalid seconds "${seconds}". Seconds value must be between 0 and 59.`);
1621
+ }
1622
+ //}
1623
+ return this.clone(target).set({
1624
+ hour: hours,
1625
+ minute: minutes,
1626
+ second: seconds,
1627
+ millisecond: 0,
1628
+ });
1629
+ }
1630
+ getHours(date) {
1631
+ return date.hour;
1632
+ }
1633
+ getMinutes(date) {
1634
+ return date.minute;
1635
+ }
1636
+ getSeconds(date) {
1637
+ return date.second;
1638
+ }
1639
+ parseTime(value, parseFormat) {
1640
+ const result = this.parse(value, parseFormat);
1641
+ if ((!result || !this.isValid(result)) && typeof value === 'string') {
1642
+ // It seems like Luxon doesn't work well cross-browser for strings that have
1643
+ // additional characters around the time. Try parsing without those characters.
1644
+ return (this.parse(value.replace(/[^0-9:(AM|PM)]/gi, ''), parseFormat) || result);
1645
+ }
1646
+ return result;
1647
+ }
1648
+ addSeconds(date, amount) {
1649
+ return date.reconfigure(this._getOptions()).plus({ seconds: amount });
1650
+ }
1651
+ /** Gets the options that should be used when constructing a new `DateTime` object. */
1652
+ _getOptions() {
1653
+ return {
1654
+ zone: this._useUTC ? 'utc' : undefined,
1655
+ locale: this.locale,
1656
+ outputCalendar: this._defaultOutputCalendar,
1657
+ };
1658
+ }
1659
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaLuxonDateAdapter, deps: [{ token: i1$4.TranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1660
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaLuxonDateAdapter }); }
1607
1661
  }
1608
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaYearMonthAdapter, decorators: [{
1662
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: OnemrvaLuxonDateAdapter, decorators: [{
1609
1663
  type: Injectable
1610
1664
  }], ctorParameters: () => [{ type: i1$4.TranslateService }] });
1611
1665
 
1666
+ function onemrvaDateNativeYearMonthProvider() {
1667
+ return [
1668
+ {
1669
+ provide: MAT_DATE_FORMATS,
1670
+ useValue: ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT,
1671
+ },
1672
+ {
1673
+ provide: DateAdapter,
1674
+ useClass: OnemrvaNativeDateAdapter,
1675
+ },
1676
+ ];
1677
+ }
1678
+
1679
+ function onemrvaDateNativeProvider() {
1680
+ return [
1681
+ {
1682
+ provide: MAT_DATE_FORMATS,
1683
+ useValue: ONEMRVA_MAT_NATIVE_DATE_FORMAT,
1684
+ },
1685
+ {
1686
+ provide: DateAdapter,
1687
+ useClass: OnemrvaNativeDateAdapter,
1688
+ },
1689
+ ];
1690
+ }
1691
+
1692
+ function onemrvaDateLuxonProvider() {
1693
+ return [
1694
+ {
1695
+ provide: MAT_DATE_FORMATS,
1696
+ useValue: ONEMRVA_MAT_LUXON_DATE_FORMATS,
1697
+ },
1698
+ {
1699
+ provide: DateAdapter,
1700
+ useClass: OnemrvaLuxonDateAdapter,
1701
+ },
1702
+ ];
1703
+ }
1704
+
1705
+ function onemrvaDateLuxonYearMonthProvider() {
1706
+ return [
1707
+ {
1708
+ provide: MAT_DATE_FORMATS,
1709
+ useValue: ONEMRVA_MAT_LUXON_YEAR_MONTH_FORMATS,
1710
+ },
1711
+ {
1712
+ provide: DateAdapter,
1713
+ useClass: OnemrvaLuxonDateAdapter,
1714
+ },
1715
+ ];
1716
+ }
1717
+
1612
1718
  /*
1613
1719
  * Public API Surface of shared
1614
1720
  */
@@ -1617,5 +1723,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImpor
1617
1723
  * Generated bundle index. Do not edit.
1618
1724
  */
1619
1725
 
1620
- export { CDNUrlModeOptions, CDN_URLS, CDN_URL_MODE, ClipboardIconComponent, CommonCountryLookupService, DefaultStorage, DigitOnlyDirective, HttpRequestCache, IBAN_SUPPORTED_COUNTRIES, IfWidthIsDirective, MatRowClickableDirective, NISS_MASK, ONEMRVA_MAT_LUXON_DATE_FORMATS, ONEMRVA_MAT_LUXON_YEAR_MONTH_FORMATS, ONEMRVA_MAT_NATIVE_DATE_FORMAT, ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT, OnemRvaCDNCountryService, OnemRvaCDNMimeService, OnemRvaCDNService, OnemRvaClipboardDirective, OnemRvaColorDirective, OnemRvaIconRightDirective, OnemrvaBcePipe, OnemrvaDateAdapter, OnemrvaDatepickerLuxonSharedModule, OnemrvaDatepickerLuxonYearMonthSharedModule, OnemrvaDatepickerSharedModule, OnemrvaDatepickerYearMonthSharedModule, OnemrvaMaskDirective, OnemrvaNissPipe, OnemrvaSharedModule, OnemrvaTranslateCDNLoader, OnemrvaTranslateHttpLoader, OnemrvaValidators, OnemrvaYearMonthAdapter, RequestTimes, WebComponentOverlayContainer, bankAccountValidator, directives, setTranslationLanguage, setTranslationLanguageFromWO };
1726
+ export { CDNUrlModeOptions, CDN_URLS, CDN_URL_MODE, ClipboardIconComponent, CommonCountryLookupService, DefaultStorage, DigitOnlyDirective, HttpRequestCache, IBAN_SUPPORTED_COUNTRIES, IfWidthIsDirective, MatRowClickableDirective, NISS_MASK, ONEMRVA_MAT_LUXON_DATE_FORMATS, ONEMRVA_MAT_LUXON_YEAR_MONTH_FORMATS, ONEMRVA_MAT_NATIVE_DATE_FORMAT, ONEMRVA_MAT_NATIVE_YEAR_MONTH_FORMAT, OnemRvaCDNCountryService, OnemRvaCDNMimeService, OnemRvaCDNService, OnemRvaClipboardDirective, OnemRvaColorDirective, OnemRvaIconRightDirective, OnemrvaBcePipe, OnemrvaLuxonDateAdapter, OnemrvaMaskDirective, OnemrvaNativeDateAdapter, OnemrvaNissPipe, OnemrvaSharedModule, OnemrvaTranslateCDNLoader, OnemrvaTranslateHttpLoader, OnemrvaValidators, RequestTimes, WebComponentOverlayContainer, bankAccountValidator, directives, onemrvaDateLuxonProvider, onemrvaDateLuxonYearMonthProvider, onemrvaDateNativeProvider, onemrvaDateNativeYearMonthProvider, setTranslationLanguage, setTranslationLanguageFromWO };
1621
1727
  //# sourceMappingURL=onemrvapublic-design-system-shared.mjs.map