@skyux/datetime 9.13.0 → 9.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/documentation.json +2028 -2028
  2. package/esm2022/index.mjs +8 -8
  3. package/esm2022/lib/modules/date-pipe/date.service.mjs +1 -1
  4. package/esm2022/lib/modules/date-pipe/fuzzy-date.pipe.mjs +1 -1
  5. package/esm2022/lib/modules/date-range-picker/date-range-picker-end-date-resource-key.pipe.mjs +1 -1
  6. package/esm2022/lib/modules/date-range-picker/date-range-picker-start-date-resource-key.pipe.mjs +1 -1
  7. package/esm2022/lib/modules/date-range-picker/date-range-picker.component.mjs +1 -1
  8. package/esm2022/lib/modules/date-range-picker/date-range.service.mjs +1 -1
  9. package/esm2022/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.mjs +1 -1
  10. package/esm2022/lib/modules/date-range-picker/types/date-range-calculator-validate-function.mjs +1 -1
  11. package/esm2022/lib/modules/date-range-picker/types/date-range-calculator.mjs +1 -1
  12. package/esm2022/lib/modules/datepicker/date-formatter.mjs +1 -1
  13. package/esm2022/lib/modules/datepicker/datepicker-calendar-inner.component.mjs +1 -1
  14. package/esm2022/lib/modules/datepicker/datepicker-calendar.component.mjs +1 -1
  15. package/esm2022/lib/modules/datepicker/datepicker-input-fuzzy.directive.mjs +1 -1
  16. package/esm2022/lib/modules/datepicker/datepicker-input.directive.mjs +1 -1
  17. package/esm2022/lib/modules/datepicker/datepicker.component.mjs +1 -1
  18. package/esm2022/lib/modules/datepicker/daypicker-cell.component.mjs +1 -1
  19. package/esm2022/lib/modules/datepicker/daypicker.component.mjs +1 -1
  20. package/esm2022/lib/modules/datepicker/fuzzy-date.service.mjs +1 -1
  21. package/esm2022/lib/modules/datepicker/monthpicker.component.mjs +1 -1
  22. package/esm2022/lib/modules/datepicker/yearpicker.component.mjs +1 -1
  23. package/esm2022/lib/modules/shared/sky-datetime-resources.module.mjs +1 -1
  24. package/esm2022/lib/modules/timepicker/timepicker.component.mjs +1 -1
  25. package/esm2022/lib/modules/timepicker/timepicker.directive.mjs +1 -1
  26. package/esm2022/testing/datepicker-fixture.mjs +1 -1
  27. package/esm2022/testing/timepicker-fixture.mjs +1 -1
  28. package/fesm2022/skyux-datetime-testing.mjs.map +1 -1
  29. package/fesm2022/skyux-datetime.mjs +390 -390
  30. package/fesm2022/skyux-datetime.mjs.map +1 -1
  31. package/index.d.ts +10 -10
  32. package/package.json +8 -8
@@ -1,12 +1,12 @@
1
+ import * as i2 from '@angular/common';
2
+ import { CommonModule } from '@angular/common';
1
3
  import * as i0 from '@angular/core';
2
- import { inject, Injectable, Pipe, NgModule, EventEmitter, Component, ViewEncapsulation, Input, Output, ChangeDetectionStrategy, ViewChild, EnvironmentInjector, ElementRef, TemplateRef, Optional, Inject, forwardRef, Directive, HostListener } from '@angular/core';
4
+ import { NgModule, inject, Injectable, Pipe, EventEmitter, Component, ViewEncapsulation, Input, Output, ChangeDetectionStrategy, ViewChild, EnvironmentInjector, ElementRef, TemplateRef, Optional, Inject, forwardRef, Directive, HostListener } from '@angular/core';
3
5
  import * as i3 from '@skyux/i18n';
4
- import { SkyAppLocaleProvider, SkyIntlDateFormatter, SkyLibResourcesService, getLibStringForLocale, SkyI18nModule, SKY_LIB_RESOURCES_PROVIDERS } from '@skyux/i18n';
6
+ import { SkyLibResourcesService, getLibStringForLocale, SkyI18nModule, SKY_LIB_RESOURCES_PROVIDERS, SkyAppLocaleProvider, SkyIntlDateFormatter } from '@skyux/i18n';
5
7
  import { Subject, fromEvent, BehaviorSubject, forkJoin, combineLatest } from 'rxjs';
6
8
  import { takeUntil, debounceTime, distinctUntilChanged, first, map } from 'rxjs/operators';
7
9
  import moment from 'moment';
8
- import * as i2 from '@angular/common';
9
- import { CommonModule } from '@angular/common';
10
10
  import * as i2$2 from '@angular/forms';
11
11
  import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormsModule, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
12
12
  import * as i2$1 from '@skyux/forms';
@@ -20,138 +20,6 @@ import { SkyPopoverMessageType, SkyPopoverModule } from '@skyux/popovers';
20
20
  import * as i3$2 from '@skyux/theme';
21
21
  import { SkyThemeModule } from '@skyux/theme';
22
22
 
23
- // This class is mostly ported from the Angular 4.x DatePipe in order to maintain the old
24
- // behavior of using the `Intl` API for formatting dates rather than having to register every
25
- // supported locale.
26
- // https://github.com/angular/angular/blob/4.4.x/packages/common/src/pipes/date_pipe.ts
27
- /**
28
- * @internal
29
- */
30
- class SkyDateService {
31
- /* spell-checker:disable */
32
- #ALIASES = {
33
- medium: 'yMMMdjms',
34
- short: 'yMdjm',
35
- fullDate: 'yMMMMEEEEd',
36
- longDate: 'yMMMMd',
37
- mediumDate: 'yMMMd',
38
- shortDate: 'yMd',
39
- mediumTime: 'jms',
40
- shortTime: 'jm',
41
- };
42
- /* spell-checker:enable */
43
- #defaultFormat = 'short';
44
- #defaultLocale = 'en-US';
45
- #ngUnsubscribe = new Subject();
46
- constructor() {
47
- inject(SkyAppLocaleProvider)
48
- .getLocaleInfo()
49
- .pipe(takeUntil(this.#ngUnsubscribe))
50
- .subscribe((localeInfo) => {
51
- this.#defaultLocale = localeInfo.locale;
52
- });
53
- }
54
- ngOnDestroy() {
55
- this.#ngUnsubscribe.next();
56
- this.#ngUnsubscribe.complete();
57
- }
58
- format(value, locale, format) {
59
- let date;
60
- const pattern = format || this.#defaultFormat;
61
- if (isBlank(value) || value !== value) {
62
- return undefined;
63
- }
64
- // Moment will interpret any non-date object as today's date. That would
65
- // introduce a breaking change, so we check for it here. This could probably be removed
66
- // in a future major version.
67
- if (value instanceof Object && !(value instanceof Date)) {
68
- throw new Error('Invalid value: ' + value);
69
- }
70
- // Use moment to avoid inconsistencies between browsers interpreting the value differently.
71
- const momentDate = moment(value);
72
- if (momentDate.isValid()) {
73
- date = momentDate.toDate();
74
- }
75
- else {
76
- throw new Error('Invalid value: ' + value);
77
- }
78
- return SkyIntlDateFormatter.format(date, locale || this.#defaultLocale, this.#ALIASES[pattern] || pattern);
79
- }
80
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
81
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDateService, providedIn: 'root' }); }
82
- }
83
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDateService, decorators: [{
84
- type: Injectable,
85
- args: [{
86
- providedIn: 'root',
87
- }]
88
- }], ctorParameters: function () { return []; } });
89
- function isBlank(obj) {
90
- return !obj;
91
- }
92
-
93
- /**
94
- * Formats date values according to locale rules.
95
- * @example
96
- * ```markup
97
- * {{ myDate | skyDate }}
98
- * {{ myDate | skyDate:'medium' }}
99
- * {{ myDate | skyDate:'medium':'en-CA' }}
100
- * ```
101
- */
102
- class SkyDatePipe {
103
- #dateSvc = inject(SkyDateService);
104
- #defaultFormat = 'short';
105
- #defaultLocale = 'en-US';
106
- #format;
107
- #formattedValue;
108
- #locale;
109
- #ngUnsubscribe = new Subject();
110
- #value;
111
- constructor() {
112
- inject(SkyAppLocaleProvider)
113
- .getLocaleInfo()
114
- .pipe(takeUntil(this.#ngUnsubscribe))
115
- .subscribe((localeInfo) => {
116
- this.#defaultLocale = localeInfo.locale;
117
- this.#updateFormattedValue();
118
- });
119
- }
120
- ngOnDestroy() {
121
- this.#ngUnsubscribe.next();
122
- this.#ngUnsubscribe.complete();
123
- }
124
- /**
125
- * Transforms a date value using locale and format rules.
126
- * @param value Specifies the date value to transform.
127
- * @param format Specifies the format to apply to the transform. The format string is
128
- * constructed by a series of symbols that represent date-time values. The symbols are
129
- * identical to [Angular's `DatePipe`](https://angular.io/api/common/DatePipe#pre-defined-format-options) format options.
130
- * @param locale Specifies the locale code to use in the transform.
131
- */
132
- transform(value, format, locale) {
133
- this.#value = value;
134
- this.#format = format;
135
- this.#locale = locale;
136
- this.#updateFormattedValue();
137
- return this.#formattedValue ?? '';
138
- }
139
- #updateFormattedValue() {
140
- const locale = this.#locale || this.#defaultLocale;
141
- const format = this.#format || this.#defaultFormat;
142
- this.#formattedValue = this.#dateSvc.format(this.#value, locale, format);
143
- }
144
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
145
- static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipe, name: "skyDate", pure: false }); }
146
- }
147
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipe, decorators: [{
148
- type: Pipe,
149
- args: [{
150
- name: 'skyDate',
151
- pure: false,
152
- }]
153
- }], ctorParameters: function () { return []; } });
154
-
155
23
  /* istanbul ignore file */
156
24
  /**
157
25
  * NOTICE: DO NOT MODIFY THIS FILE!
@@ -285,7 +153,139 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
285
153
  },
286
154
  ],
287
155
  }]
288
- }] });
156
+ }] });
157
+
158
+ // This class is mostly ported from the Angular 4.x DatePipe in order to maintain the old
159
+ // behavior of using the `Intl` API for formatting dates rather than having to register every
160
+ // supported locale.
161
+ // https://github.com/angular/angular/blob/4.4.x/packages/common/src/pipes/date_pipe.ts
162
+ /**
163
+ * @internal
164
+ */
165
+ class SkyDateService {
166
+ /* spell-checker:disable */
167
+ #ALIASES = {
168
+ medium: 'yMMMdjms',
169
+ short: 'yMdjm',
170
+ fullDate: 'yMMMMEEEEd',
171
+ longDate: 'yMMMMd',
172
+ mediumDate: 'yMMMd',
173
+ shortDate: 'yMd',
174
+ mediumTime: 'jms',
175
+ shortTime: 'jm',
176
+ };
177
+ /* spell-checker:enable */
178
+ #defaultFormat = 'short';
179
+ #defaultLocale = 'en-US';
180
+ #ngUnsubscribe = new Subject();
181
+ constructor() {
182
+ inject(SkyAppLocaleProvider)
183
+ .getLocaleInfo()
184
+ .pipe(takeUntil(this.#ngUnsubscribe))
185
+ .subscribe((localeInfo) => {
186
+ this.#defaultLocale = localeInfo.locale;
187
+ });
188
+ }
189
+ ngOnDestroy() {
190
+ this.#ngUnsubscribe.next();
191
+ this.#ngUnsubscribe.complete();
192
+ }
193
+ format(value, locale, format) {
194
+ let date;
195
+ const pattern = format || this.#defaultFormat;
196
+ if (isBlank(value) || value !== value) {
197
+ return undefined;
198
+ }
199
+ // Moment will interpret any non-date object as today's date. That would
200
+ // introduce a breaking change, so we check for it here. This could probably be removed
201
+ // in a future major version.
202
+ if (value instanceof Object && !(value instanceof Date)) {
203
+ throw new Error('Invalid value: ' + value);
204
+ }
205
+ // Use moment to avoid inconsistencies between browsers interpreting the value differently.
206
+ const momentDate = moment(value);
207
+ if (momentDate.isValid()) {
208
+ date = momentDate.toDate();
209
+ }
210
+ else {
211
+ throw new Error('Invalid value: ' + value);
212
+ }
213
+ return SkyIntlDateFormatter.format(date, locale || this.#defaultLocale, this.#ALIASES[pattern] || pattern);
214
+ }
215
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
216
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDateService, providedIn: 'root' }); }
217
+ }
218
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDateService, decorators: [{
219
+ type: Injectable,
220
+ args: [{
221
+ providedIn: 'root',
222
+ }]
223
+ }], ctorParameters: function () { return []; } });
224
+ function isBlank(obj) {
225
+ return !obj;
226
+ }
227
+
228
+ /**
229
+ * Formats date values according to locale rules.
230
+ * @example
231
+ * ```markup
232
+ * {{ myDate | skyDate }}
233
+ * {{ myDate | skyDate:'medium' }}
234
+ * {{ myDate | skyDate:'medium':'en-CA' }}
235
+ * ```
236
+ */
237
+ class SkyDatePipe {
238
+ #dateSvc = inject(SkyDateService);
239
+ #defaultFormat = 'short';
240
+ #defaultLocale = 'en-US';
241
+ #format;
242
+ #formattedValue;
243
+ #locale;
244
+ #ngUnsubscribe = new Subject();
245
+ #value;
246
+ constructor() {
247
+ inject(SkyAppLocaleProvider)
248
+ .getLocaleInfo()
249
+ .pipe(takeUntil(this.#ngUnsubscribe))
250
+ .subscribe((localeInfo) => {
251
+ this.#defaultLocale = localeInfo.locale;
252
+ this.#updateFormattedValue();
253
+ });
254
+ }
255
+ ngOnDestroy() {
256
+ this.#ngUnsubscribe.next();
257
+ this.#ngUnsubscribe.complete();
258
+ }
259
+ /**
260
+ * Transforms a date value using locale and format rules.
261
+ * @param value Specifies the date value to transform.
262
+ * @param format Specifies the format to apply to the transform. The format string is
263
+ * constructed by a series of symbols that represent date-time values. The symbols are
264
+ * identical to [Angular's `DatePipe`](https://angular.io/api/common/DatePipe#pre-defined-format-options) format options.
265
+ * @param locale Specifies the locale code to use in the transform.
266
+ */
267
+ transform(value, format, locale) {
268
+ this.#value = value;
269
+ this.#format = format;
270
+ this.#locale = locale;
271
+ this.#updateFormattedValue();
272
+ return this.#formattedValue ?? '';
273
+ }
274
+ #updateFormattedValue() {
275
+ const locale = this.#locale || this.#defaultLocale;
276
+ const format = this.#format || this.#defaultFormat;
277
+ this.#formattedValue = this.#dateSvc.format(this.#value, locale, format);
278
+ }
279
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
280
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipe, name: "skyDate", pure: false }); }
281
+ }
282
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipe, decorators: [{
283
+ type: Pipe,
284
+ args: [{
285
+ name: 'skyDate',
286
+ pure: false,
287
+ }]
288
+ }], ctorParameters: function () { return []; } });
289
289
 
290
290
  /**
291
291
  * @internal
@@ -691,261 +691,66 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
691
691
  args: [{
692
692
  providedIn: 'root',
693
693
  }]
694
- }], ctorParameters: function () { return [{ type: i3.SkyAppLocaleProvider }]; } });
695
-
696
- /**
697
- * Formats date values using two or more date tokens that represent the day, month,
698
- * and year. The tokens are described in the [moment.js values](https://momentjs.com/docs/#/displaying/).
699
- * @example
700
- * ```markup
701
- * {{ myFuzzyDate | skyFuzzyDate:'MMM Y' }}
702
- * {{ myFuzzyDate | skyFuzzyDate:'MMM Y':'en-CA' }}
703
- * ```
704
- */
705
- class SkyFuzzyDatePipe {
706
- #fuzzyDateService;
707
- constructor(fuzzyDateService) {
708
- this.#fuzzyDateService = fuzzyDateService;
709
- }
710
- /**
711
- * Transforms fuzzy date values using two or more date tokens that represent the day, month,
712
- * and year.
713
- * @param value Specifies the date value to transform.
714
- * @param format Specifies the format to apply to the transform. You construct the format
715
- * string with a two or more tokens that specify the components of date-time value. The
716
- * tokens are described in the [moment.js values](https://momentjs.com/docs/#/displaying/).
717
- * If you don't provide a format, `SkyFuzzyDatePipe` attempts to format fuzzy dates based
718
- * on the browser's default locale.
719
- * @param locale Specifies the locale code to use in the transform.
720
- */
721
- transform(value, format, locale) {
722
- if (!value) {
723
- return '';
724
- }
725
- const fuzzyDateFormat = format || this.#fuzzyDateService.getLocaleShortFormat(locale);
726
- const fuzzyDateLocale = locale || this.#fuzzyDateService.getCurrentLocale();
727
- return this.#fuzzyDateService.format(value, fuzzyDateFormat, fuzzyDateLocale);
728
- }
729
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyFuzzyDatePipe, deps: [{ token: SkyFuzzyDateService }], target: i0.ɵɵFactoryTarget.Pipe }); }
730
- static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: SkyFuzzyDatePipe, name: "skyFuzzyDate", pure: false }); }
731
- }
732
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyFuzzyDatePipe, decorators: [{
733
- type: Pipe,
734
- args: [{
735
- name: 'skyFuzzyDate',
736
- pure: false,
737
- }]
738
- }], ctorParameters: function () { return [{ type: SkyFuzzyDateService }]; } });
739
-
740
- class SkyDatePipeModule {
741
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
742
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, declarations: [SkyDatePipe, SkyFuzzyDatePipe], imports: [CommonModule, SkyDatetimeResourcesModule], exports: [SkyDatePipe, SkyFuzzyDatePipe] }); }
743
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, providers: [SkyDatePipe, SkyFuzzyDatePipe], imports: [CommonModule, SkyDatetimeResourcesModule] }); }
744
- }
745
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, decorators: [{
746
- type: NgModule,
747
- args: [{
748
- declarations: [SkyDatePipe, SkyFuzzyDatePipe],
749
- providers: [SkyDatePipe, SkyFuzzyDatePipe],
750
- imports: [CommonModule, SkyDatetimeResourcesModule],
751
- exports: [SkyDatePipe, SkyFuzzyDatePipe],
752
- }]
753
- }] });
754
-
755
- /**
756
- * Represents the calculator.
757
- */
758
- class SkyDateRangeCalculator {
759
- #config;
760
- constructor(
761
- /**
762
- * The calculator ID that specifies calculator objects that represent date ranges.
763
- */
764
- calculatorId, config) {
765
- this.calculatorId = calculatorId;
766
- this.#config = config;
767
- this.type = config.type;
768
- this.shortDescription = config.shortDescription;
769
- }
770
- /**
771
- * Gets the current value of the calculator.
772
- * @param startDateInput The start date.
773
- * @param endDateInput The end date.
774
- */
775
- getValue(startDateInput, endDateInput) {
776
- const result = this.#config.getValue(startDateInput, endDateInput);
777
- let startDate = null;
778
- if (result.startDate instanceof Date) {
779
- startDate = this.#parseDateWithoutTime(result.startDate);
780
- }
781
- let endDate = null;
782
- if (result.endDate instanceof Date) {
783
- endDate = this.#parseDateWithoutTime(result.endDate);
784
- }
785
- return {
786
- calculatorId: this.calculatorId,
787
- startDate,
788
- endDate,
789
- };
790
- }
791
- /**
792
- * Performs synchronous validation against the control.
793
- */
794
- validate(value) {
795
- if (!this.#config.validate) {
796
- return null;
797
- }
798
- return this.#config.validate(value);
799
- }
800
- /**
801
- * Get a date object without time information.
802
- * See: https://stackoverflow.com/a/38050824/6178885
803
- */
804
- #parseDateWithoutTime(date) {
805
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
806
- }
807
- }
808
-
809
- /**
810
- * `SkyDateRangeCalculatorId` values specify calculator objects that return
811
- * two `Date` objects to represent date ranges. The values populate the options
812
- * in the date range picker's dropdown. SKY UX uses `SkyDateRangeService` to create
813
- * calculators and configures each one with a `validate` function to confirm that dates
814
- * are compatible. For example, `validate` functions ensure that start dates are before
815
- * end dates. SKY UX also configures calculators to call a `getValue` function after
816
- * the `validate` function and return a range of two `Date` objects.
817
- */
818
- var SkyDateRangeCalculatorId;
819
- (function (SkyDateRangeCalculatorId) {
820
- /**
821
- * Selects no dates and considers all dates within the date range. This is the default selection.
822
- */
823
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["AnyTime"] = 0] = "AnyTime";
824
- /**
825
- * Enables users to select an end date with no starting date.
826
- */
827
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Before"] = 1] = "Before";
828
- /**
829
- * Enables users to select a start date with no end date.
830
- */
831
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["After"] = 2] = "After";
832
- /**
833
- * Enables users to select specific start and end dates.
834
- */
835
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["SpecificRange"] = 3] = "SpecificRange";
836
- /**
837
- * Sets the start and end dates to the day before the current day.
838
- */
839
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Yesterday"] = 4] = "Yesterday";
840
- /**
841
- * Sets the start and end dates to the current day.
842
- */
843
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Today"] = 5] = "Today";
844
- /**
845
- * Sets the start and end dates to the day after the current day.
846
- */
847
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Tomorrow"] = 6] = "Tomorrow";
848
- /**
849
- * Sets the start date to Sunday of the week before the current week and
850
- * the end date to Saturday of that week.
851
- */
852
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastWeek"] = 7] = "LastWeek";
853
- /**
854
- * Sets the start date to Sunday of the current week and the end date to Saturday.
855
- */
856
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisWeek"] = 8] = "ThisWeek";
857
- /**
858
- * Sets the start date to Sunday of the week after the current week and
859
- * the end date to Saturday of that week.
860
- */
861
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextWeek"] = 9] = "NextWeek";
862
- /**
863
- * Sets the start date to the first day of the month before the current month and
864
- * the end date to the last day of that month.
865
- */
866
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastMonth"] = 10] = "LastMonth";
867
- /**
868
- * Sets the start date to the first day of the current month and
869
- * the end date to the last day of the month.
870
- */
871
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisMonth"] = 11] = "ThisMonth";
872
- /**
873
- * Sets the start date to the first day of the month after the current month
874
- * and the end date to the last day of that month.
875
- */
876
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextMonth"] = 12] = "NextMonth";
877
- /**
878
- * Sets the start date to the first day of the quarter before the current quarter and
879
- * the end date to the last day of that quarter. Quarters are
880
- * January to March, April to June, July to September, and October to December.
881
- */
882
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastQuarter"] = 13] = "LastQuarter";
883
- /**
884
- * Sets the start date to the first day of the current quarter and
885
- * the end date to the last day of the quarter. Quarters are
886
- * January to March, April to June, July to September, and October to December.
887
- */
888
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisQuarter"] = 14] = "ThisQuarter";
889
- /**
890
- * Sets the start date to the first day of the quarter after the current quarter and
891
- * the end date to the last day of that quarter. Quarters are
892
- * January to March, April to June, July to September, and October to December.
893
- */
894
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextQuarter"] = 15] = "NextQuarter";
895
- /**
896
- * Sets the start date to the first day of the year before the current year
897
- * and the end date to the last day of that year.
898
- */
899
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastCalendarYear"] = 16] = "LastCalendarYear";
900
- /**
901
- * Sets the start date to the first day of the current year and
902
- * the end date to the last day of the year.
903
- */
904
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisCalendarYear"] = 17] = "ThisCalendarYear";
905
- /**
906
- * Sets the start date to the first day of the year after the current year and
907
- * the end date to the last day of that year.
908
- */
909
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextCalendarYear"] = 18] = "NextCalendarYear";
910
- /**
911
- * Sets the start date to the first day of the fiscal year before the current fiscal year and
912
- * the end date to the last day of that fiscal year. The fiscal year is Oct. 1 to Sept. 30.
913
- */
914
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastFiscalYear"] = 19] = "LastFiscalYear";
915
- /**
916
- * Sets the start date to the first day of the current fiscal year and
917
- * the end date to the last day of the fiscal year. The fiscal year is Oct. 1 to Sept. 30.
918
- */
919
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisFiscalYear"] = 20] = "ThisFiscalYear";
920
- /**
921
- * Sets the start date to the first day of the fiscal year after the current fiscal year
922
- * and the end date to the last day of that fiscal year. The fiscal year is Oct. 1 to Sept. 30.
923
- */
924
- SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextFiscalYear"] = 21] = "NextFiscalYear";
925
- })(SkyDateRangeCalculatorId || (SkyDateRangeCalculatorId = {}));
926
-
927
- /**
928
- * The types of calculations available for a date range calculator.
929
- */
930
- var SkyDateRangeCalculatorType;
931
- (function (SkyDateRangeCalculatorType) {
932
- /**
933
- * Includes an input for a date after the current date.
934
- */
935
- SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["After"] = 0] = "After";
936
- /**
937
- * Includes an input for a date before the current date.
938
- */
939
- SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["Before"] = 1] = "Before";
940
- /**
941
- * Includes two inputs for a range of dates.
942
- */
943
- SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["Range"] = 2] = "Range";
694
+ }], ctorParameters: function () { return [{ type: i3.SkyAppLocaleProvider }]; } });
695
+
696
+ /**
697
+ * Formats date values using two or more date tokens that represent the day, month,
698
+ * and year. The tokens are described in the [moment.js values](https://momentjs.com/docs/#/displaying/).
699
+ * @example
700
+ * ```markup
701
+ * {{ myFuzzyDate | skyFuzzyDate:'MMM Y' }}
702
+ * {{ myFuzzyDate | skyFuzzyDate:'MMM Y':'en-CA' }}
703
+ * ```
704
+ */
705
+ class SkyFuzzyDatePipe {
706
+ #fuzzyDateService;
707
+ constructor(fuzzyDateService) {
708
+ this.#fuzzyDateService = fuzzyDateService;
709
+ }
944
710
  /**
945
- * Does not accept any input but calculates a specific range based on the current date.
711
+ * Transforms fuzzy date values using two or more date tokens that represent the day, month,
712
+ * and year.
713
+ * @param value Specifies the date value to transform.
714
+ * @param format Specifies the format to apply to the transform. You construct the format
715
+ * string with a two or more tokens that specify the components of date-time value. The
716
+ * tokens are described in the [moment.js values](https://momentjs.com/docs/#/displaying/).
717
+ * If you don't provide a format, `SkyFuzzyDatePipe` attempts to format fuzzy dates based
718
+ * on the browser's default locale.
719
+ * @param locale Specifies the locale code to use in the transform.
946
720
  */
947
- SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["Relative"] = 3] = "Relative";
948
- })(SkyDateRangeCalculatorType || (SkyDateRangeCalculatorType = {}));
721
+ transform(value, format, locale) {
722
+ if (!value) {
723
+ return '';
724
+ }
725
+ const fuzzyDateFormat = format || this.#fuzzyDateService.getLocaleShortFormat(locale);
726
+ const fuzzyDateLocale = locale || this.#fuzzyDateService.getCurrentLocale();
727
+ return this.#fuzzyDateService.format(value, fuzzyDateFormat, fuzzyDateLocale);
728
+ }
729
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyFuzzyDatePipe, deps: [{ token: SkyFuzzyDateService }], target: i0.ɵɵFactoryTarget.Pipe }); }
730
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: SkyFuzzyDatePipe, name: "skyFuzzyDate", pure: false }); }
731
+ }
732
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyFuzzyDatePipe, decorators: [{
733
+ type: Pipe,
734
+ args: [{
735
+ name: 'skyFuzzyDate',
736
+ pure: false,
737
+ }]
738
+ }], ctorParameters: function () { return [{ type: SkyFuzzyDateService }]; } });
739
+
740
+ class SkyDatePipeModule {
741
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
742
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, declarations: [SkyDatePipe, SkyFuzzyDatePipe], imports: [CommonModule, SkyDatetimeResourcesModule], exports: [SkyDatePipe, SkyFuzzyDatePipe] }); }
743
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, providers: [SkyDatePipe, SkyFuzzyDatePipe], imports: [CommonModule, SkyDatetimeResourcesModule] }); }
744
+ }
745
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SkyDatePipeModule, decorators: [{
746
+ type: NgModule,
747
+ args: [{
748
+ declarations: [SkyDatePipe, SkyFuzzyDatePipe],
749
+ providers: [SkyDatePipe, SkyFuzzyDatePipe],
750
+ imports: [CommonModule, SkyDatetimeResourcesModule],
751
+ exports: [SkyDatePipe, SkyFuzzyDatePipe],
752
+ }]
753
+ }] });
949
754
 
950
755
  class SkyDateFormatter {
951
756
  static { this.defaultLocale = 'en-US'; }
@@ -3330,6 +3135,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
3330
3135
  }]
3331
3136
  }] });
3332
3137
 
3138
+ /**
3139
+ * The types of calculations available for a date range calculator.
3140
+ */
3141
+ var SkyDateRangeCalculatorType;
3142
+ (function (SkyDateRangeCalculatorType) {
3143
+ /**
3144
+ * Includes an input for a date after the current date.
3145
+ */
3146
+ SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["After"] = 0] = "After";
3147
+ /**
3148
+ * Includes an input for a date before the current date.
3149
+ */
3150
+ SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["Before"] = 1] = "Before";
3151
+ /**
3152
+ * Includes two inputs for a range of dates.
3153
+ */
3154
+ SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["Range"] = 2] = "Range";
3155
+ /**
3156
+ * Does not accept any input but calculates a specific range based on the current date.
3157
+ */
3158
+ SkyDateRangeCalculatorType[SkyDateRangeCalculatorType["Relative"] = 3] = "Relative";
3159
+ })(SkyDateRangeCalculatorType || (SkyDateRangeCalculatorType = {}));
3160
+
3333
3161
  class SkyDateRangePickerEndDateResourceKeyPipe {
3334
3162
  transform(calculatorType) {
3335
3163
  if (calculatorType === SkyDateRangeCalculatorType.Range) {
@@ -3364,6 +3192,178 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
3364
3192
  }]
3365
3193
  }] });
3366
3194
 
3195
+ /**
3196
+ * `SkyDateRangeCalculatorId` values specify calculator objects that return
3197
+ * two `Date` objects to represent date ranges. The values populate the options
3198
+ * in the date range picker's dropdown. SKY UX uses `SkyDateRangeService` to create
3199
+ * calculators and configures each one with a `validate` function to confirm that dates
3200
+ * are compatible. For example, `validate` functions ensure that start dates are before
3201
+ * end dates. SKY UX also configures calculators to call a `getValue` function after
3202
+ * the `validate` function and return a range of two `Date` objects.
3203
+ */
3204
+ var SkyDateRangeCalculatorId;
3205
+ (function (SkyDateRangeCalculatorId) {
3206
+ /**
3207
+ * Selects no dates and considers all dates within the date range. This is the default selection.
3208
+ */
3209
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["AnyTime"] = 0] = "AnyTime";
3210
+ /**
3211
+ * Enables users to select an end date with no starting date.
3212
+ */
3213
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Before"] = 1] = "Before";
3214
+ /**
3215
+ * Enables users to select a start date with no end date.
3216
+ */
3217
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["After"] = 2] = "After";
3218
+ /**
3219
+ * Enables users to select specific start and end dates.
3220
+ */
3221
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["SpecificRange"] = 3] = "SpecificRange";
3222
+ /**
3223
+ * Sets the start and end dates to the day before the current day.
3224
+ */
3225
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Yesterday"] = 4] = "Yesterday";
3226
+ /**
3227
+ * Sets the start and end dates to the current day.
3228
+ */
3229
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Today"] = 5] = "Today";
3230
+ /**
3231
+ * Sets the start and end dates to the day after the current day.
3232
+ */
3233
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["Tomorrow"] = 6] = "Tomorrow";
3234
+ /**
3235
+ * Sets the start date to Sunday of the week before the current week and
3236
+ * the end date to Saturday of that week.
3237
+ */
3238
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastWeek"] = 7] = "LastWeek";
3239
+ /**
3240
+ * Sets the start date to Sunday of the current week and the end date to Saturday.
3241
+ */
3242
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisWeek"] = 8] = "ThisWeek";
3243
+ /**
3244
+ * Sets the start date to Sunday of the week after the current week and
3245
+ * the end date to Saturday of that week.
3246
+ */
3247
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextWeek"] = 9] = "NextWeek";
3248
+ /**
3249
+ * Sets the start date to the first day of the month before the current month and
3250
+ * the end date to the last day of that month.
3251
+ */
3252
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastMonth"] = 10] = "LastMonth";
3253
+ /**
3254
+ * Sets the start date to the first day of the current month and
3255
+ * the end date to the last day of the month.
3256
+ */
3257
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisMonth"] = 11] = "ThisMonth";
3258
+ /**
3259
+ * Sets the start date to the first day of the month after the current month
3260
+ * and the end date to the last day of that month.
3261
+ */
3262
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextMonth"] = 12] = "NextMonth";
3263
+ /**
3264
+ * Sets the start date to the first day of the quarter before the current quarter and
3265
+ * the end date to the last day of that quarter. Quarters are
3266
+ * January to March, April to June, July to September, and October to December.
3267
+ */
3268
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastQuarter"] = 13] = "LastQuarter";
3269
+ /**
3270
+ * Sets the start date to the first day of the current quarter and
3271
+ * the end date to the last day of the quarter. Quarters are
3272
+ * January to March, April to June, July to September, and October to December.
3273
+ */
3274
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisQuarter"] = 14] = "ThisQuarter";
3275
+ /**
3276
+ * Sets the start date to the first day of the quarter after the current quarter and
3277
+ * the end date to the last day of that quarter. Quarters are
3278
+ * January to March, April to June, July to September, and October to December.
3279
+ */
3280
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextQuarter"] = 15] = "NextQuarter";
3281
+ /**
3282
+ * Sets the start date to the first day of the year before the current year
3283
+ * and the end date to the last day of that year.
3284
+ */
3285
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastCalendarYear"] = 16] = "LastCalendarYear";
3286
+ /**
3287
+ * Sets the start date to the first day of the current year and
3288
+ * the end date to the last day of the year.
3289
+ */
3290
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisCalendarYear"] = 17] = "ThisCalendarYear";
3291
+ /**
3292
+ * Sets the start date to the first day of the year after the current year and
3293
+ * the end date to the last day of that year.
3294
+ */
3295
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextCalendarYear"] = 18] = "NextCalendarYear";
3296
+ /**
3297
+ * Sets the start date to the first day of the fiscal year before the current fiscal year and
3298
+ * the end date to the last day of that fiscal year. The fiscal year is Oct. 1 to Sept. 30.
3299
+ */
3300
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["LastFiscalYear"] = 19] = "LastFiscalYear";
3301
+ /**
3302
+ * Sets the start date to the first day of the current fiscal year and
3303
+ * the end date to the last day of the fiscal year. The fiscal year is Oct. 1 to Sept. 30.
3304
+ */
3305
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["ThisFiscalYear"] = 20] = "ThisFiscalYear";
3306
+ /**
3307
+ * Sets the start date to the first day of the fiscal year after the current fiscal year
3308
+ * and the end date to the last day of that fiscal year. The fiscal year is Oct. 1 to Sept. 30.
3309
+ */
3310
+ SkyDateRangeCalculatorId[SkyDateRangeCalculatorId["NextFiscalYear"] = 21] = "NextFiscalYear";
3311
+ })(SkyDateRangeCalculatorId || (SkyDateRangeCalculatorId = {}));
3312
+
3313
+ /**
3314
+ * Represents the calculator.
3315
+ */
3316
+ class SkyDateRangeCalculator {
3317
+ #config;
3318
+ constructor(
3319
+ /**
3320
+ * The calculator ID that specifies calculator objects that represent date ranges.
3321
+ */
3322
+ calculatorId, config) {
3323
+ this.calculatorId = calculatorId;
3324
+ this.#config = config;
3325
+ this.type = config.type;
3326
+ this.shortDescription = config.shortDescription;
3327
+ }
3328
+ /**
3329
+ * Gets the current value of the calculator.
3330
+ * @param startDateInput The start date.
3331
+ * @param endDateInput The end date.
3332
+ */
3333
+ getValue(startDateInput, endDateInput) {
3334
+ const result = this.#config.getValue(startDateInput, endDateInput);
3335
+ let startDate = null;
3336
+ if (result.startDate instanceof Date) {
3337
+ startDate = this.#parseDateWithoutTime(result.startDate);
3338
+ }
3339
+ let endDate = null;
3340
+ if (result.endDate instanceof Date) {
3341
+ endDate = this.#parseDateWithoutTime(result.endDate);
3342
+ }
3343
+ return {
3344
+ calculatorId: this.calculatorId,
3345
+ startDate,
3346
+ endDate,
3347
+ };
3348
+ }
3349
+ /**
3350
+ * Performs synchronous validation against the control.
3351
+ */
3352
+ validate(value) {
3353
+ if (!this.#config.validate) {
3354
+ return null;
3355
+ }
3356
+ return this.#config.validate(value);
3357
+ }
3358
+ /**
3359
+ * Get a date object without time information.
3360
+ * See: https://stackoverflow.com/a/38050824/6178885
3361
+ */
3362
+ #parseDateWithoutTime(date) {
3363
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
3364
+ }
3365
+ }
3366
+
3367
3367
  /**
3368
3368
  * Need to add the following to classes which contain static methods.
3369
3369
  * See: https://github.com/ng-packagr/ng-packagr/issues/641