@skyux/datetime 5.7.2 → 6.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/index.mjs +28 -0
- package/esm2020/lib/modules/date-pipe/date-format-utility.mjs +46 -0
- package/esm2020/lib/modules/date-pipe/date-pipe.module.mjs +21 -0
- package/esm2020/lib/modules/date-pipe/date.pipe.mjs +65 -0
- package/esm2020/lib/modules/date-pipe/fuzzy-date.pipe.mjs +47 -0
- package/esm2020/lib/modules/date-range-picker/date-range-picker.component.mjs +448 -0
- package/esm2020/lib/modules/date-range-picker/date-range-picker.module.mjs +47 -0
- package/esm2020/lib/modules/date-range-picker/date-range.service.mjs +97 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculation.mjs +2 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-config.mjs +2 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.mjs +2 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-id.mjs +118 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-type.mjs +23 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-validate-function.mjs +2 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-calculator.mjs +56 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-default-calculator-config.mjs +2 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-default-calculator-configs.mjs +147 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range-relative-value.mjs +249 -0
- package/esm2020/lib/modules/date-range-picker/types/date-range.mjs +2 -0
- package/esm2020/lib/modules/datepicker/date-formatter.mjs +38 -0
- package/esm2020/lib/modules/datepicker/datepicker-adapter.service.mjs +33 -0
- package/esm2020/lib/modules/datepicker/datepicker-calendar-change.mjs +2 -0
- package/esm2020/lib/modules/datepicker/datepicker-calendar-inner.component.mjs +310 -0
- package/esm2020/lib/modules/datepicker/datepicker-calendar.component.mjs +104 -0
- package/esm2020/lib/modules/datepicker/datepicker-config.service.mjs +21 -0
- package/esm2020/lib/modules/datepicker/datepicker-custom-date.mjs +2 -0
- package/esm2020/lib/modules/datepicker/datepicker-date.mjs +2 -0
- package/esm2020/lib/modules/datepicker/datepicker-input-fuzzy.directive.mjs +466 -0
- package/esm2020/lib/modules/datepicker/datepicker-input.directive.mjs +445 -0
- package/esm2020/lib/modules/datepicker/datepicker.component.mjs +328 -0
- package/esm2020/lib/modules/datepicker/datepicker.module.mjs +95 -0
- package/esm2020/lib/modules/datepicker/datepicker.service.mjs +21 -0
- package/esm2020/lib/modules/datepicker/daypicker-button.component.mjs +22 -0
- package/esm2020/lib/modules/datepicker/daypicker-cell.component.mjs +126 -0
- package/esm2020/lib/modules/datepicker/daypicker.component.mjs +211 -0
- package/esm2020/lib/modules/datepicker/fuzzy-date.mjs +2 -0
- package/esm2020/lib/modules/datepicker/fuzzy-date.service.mjs +403 -0
- package/esm2020/lib/modules/datepicker/monthpicker.component.mjs +80 -0
- package/esm2020/lib/modules/datepicker/yearpicker.component.mjs +86 -0
- package/esm2020/lib/modules/shared/sky-datetime-resources.module.mjs +131 -0
- package/esm2020/lib/modules/timepicker/timepicker.component.mjs +361 -0
- package/esm2020/lib/modules/timepicker/timepicker.directive.mjs +228 -0
- package/esm2020/lib/modules/timepicker/timepicker.interface.mjs +2 -0
- package/esm2020/lib/modules/timepicker/timepicker.module.mjs +46 -0
- package/esm2020/skyux-datetime.mjs +5 -0
- package/esm2020/testing/datepicker-fixture.mjs +54 -0
- package/esm2020/testing/public-api.mjs +3 -0
- package/esm2020/testing/skyux-datetime-testing.mjs +5 -0
- package/esm2020/testing/timepicker-fixture.mjs +50 -0
- package/fesm2015/{skyux-datetime-testing.js → skyux-datetime-testing.mjs} +1 -1
- package/fesm2015/skyux-datetime-testing.mjs.map +1 -0
- package/fesm2015/skyux-datetime.mjs +4726 -0
- package/fesm2015/skyux-datetime.mjs.map +1 -0
- package/{esm2015/testing/datepicker-fixture.js → fesm2020/skyux-datetime-testing.mjs} +57 -2
- package/fesm2020/skyux-datetime-testing.mjs.map +1 -0
- package/{fesm2015/skyux-datetime.js → fesm2020/skyux-datetime.mjs} +110 -158
- package/fesm2020/skyux-datetime.mjs.map +1 -0
- package/package.json +42 -18
- package/testing/package.json +5 -5
- package/bundles/skyux-datetime-testing.umd.js +0 -143
- package/bundles/skyux-datetime.umd.js +0 -5488
- package/esm2015/index.js +0 -28
- package/esm2015/index.js.map +0 -1
- package/esm2015/lib/modules/date-pipe/date-format-utility.js +0 -46
- package/esm2015/lib/modules/date-pipe/date-format-utility.js.map +0 -1
- package/esm2015/lib/modules/date-pipe/date-pipe.module.js +0 -21
- package/esm2015/lib/modules/date-pipe/date-pipe.module.js.map +0 -1
- package/esm2015/lib/modules/date-pipe/date.pipe.js +0 -65
- package/esm2015/lib/modules/date-pipe/date.pipe.js.map +0 -1
- package/esm2015/lib/modules/date-pipe/fuzzy-date.pipe.js +0 -47
- package/esm2015/lib/modules/date-pipe/fuzzy-date.pipe.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/date-range-picker.component.js +0 -453
- package/esm2015/lib/modules/date-range-picker/date-range-picker.component.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/date-range-picker.module.js +0 -47
- package/esm2015/lib/modules/date-range-picker/date-range-picker.module.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/date-range.service.js +0 -97
- package/esm2015/lib/modules/date-range-picker/date-range.service.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculation.js +0 -2
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculation.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-config.js +0 -2
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-config.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.js +0 -2
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-id.js +0 -118
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-id.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-type.js +0 -23
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-type.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-validate-function.js +0 -2
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-validate-function.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator.js +0 -56
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-config.js +0 -2
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-config.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-configs.js +0 -147
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-configs.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range-relative-value.js +0 -249
- package/esm2015/lib/modules/date-range-picker/types/date-range-relative-value.js.map +0 -1
- package/esm2015/lib/modules/date-range-picker/types/date-range.js +0 -2
- package/esm2015/lib/modules/date-range-picker/types/date-range.js.map +0 -1
- package/esm2015/lib/modules/datepicker/date-formatter.js +0 -38
- package/esm2015/lib/modules/datepicker/date-formatter.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-adapter.service.js +0 -33
- package/esm2015/lib/modules/datepicker/datepicker-adapter.service.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-calendar-change.js +0 -2
- package/esm2015/lib/modules/datepicker/datepicker-calendar-change.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-calendar-inner.component.js +0 -315
- package/esm2015/lib/modules/datepicker/datepicker-calendar-inner.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-calendar.component.js +0 -109
- package/esm2015/lib/modules/datepicker/datepicker-calendar.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-config.service.js +0 -21
- package/esm2015/lib/modules/datepicker/datepicker-config.service.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-custom-date.js +0 -2
- package/esm2015/lib/modules/datepicker/datepicker-custom-date.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-date.js +0 -2
- package/esm2015/lib/modules/datepicker/datepicker-date.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-input-fuzzy.directive.js +0 -467
- package/esm2015/lib/modules/datepicker/datepicker-input-fuzzy.directive.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker-input.directive.js +0 -446
- package/esm2015/lib/modules/datepicker/datepicker-input.directive.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker.component.js +0 -333
- package/esm2015/lib/modules/datepicker/datepicker.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker.module.js +0 -95
- package/esm2015/lib/modules/datepicker/datepicker.module.js.map +0 -1
- package/esm2015/lib/modules/datepicker/datepicker.service.js +0 -21
- package/esm2015/lib/modules/datepicker/datepicker.service.js.map +0 -1
- package/esm2015/lib/modules/datepicker/daypicker-button.component.js +0 -26
- package/esm2015/lib/modules/datepicker/daypicker-button.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/daypicker-cell.component.js +0 -130
- package/esm2015/lib/modules/datepicker/daypicker-cell.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/daypicker.component.js +0 -215
- package/esm2015/lib/modules/datepicker/daypicker.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/fuzzy-date.js +0 -2
- package/esm2015/lib/modules/datepicker/fuzzy-date.js.map +0 -1
- package/esm2015/lib/modules/datepicker/fuzzy-date.service.js +0 -403
- package/esm2015/lib/modules/datepicker/fuzzy-date.service.js.map +0 -1
- package/esm2015/lib/modules/datepicker/monthpicker.component.js +0 -84
- package/esm2015/lib/modules/datepicker/monthpicker.component.js.map +0 -1
- package/esm2015/lib/modules/datepicker/yearpicker.component.js +0 -90
- package/esm2015/lib/modules/datepicker/yearpicker.component.js.map +0 -1
- package/esm2015/lib/modules/shared/sky-datetime-resources.module.js +0 -131
- package/esm2015/lib/modules/shared/sky-datetime-resources.module.js.map +0 -1
- package/esm2015/lib/modules/timepicker/timepicker.component.js +0 -367
- package/esm2015/lib/modules/timepicker/timepicker.component.js.map +0 -1
- package/esm2015/lib/modules/timepicker/timepicker.directive.js +0 -228
- package/esm2015/lib/modules/timepicker/timepicker.directive.js.map +0 -1
- package/esm2015/lib/modules/timepicker/timepicker.interface.js +0 -2
- package/esm2015/lib/modules/timepicker/timepicker.interface.js.map +0 -1
- package/esm2015/lib/modules/timepicker/timepicker.module.js +0 -46
- package/esm2015/lib/modules/timepicker/timepicker.module.js.map +0 -1
- package/esm2015/skyux-datetime.js +0 -5
- package/esm2015/skyux-datetime.js.map +0 -1
- package/esm2015/testing/datepicker-fixture.js.map +0 -1
- package/esm2015/testing/public-api.js +0 -3
- package/esm2015/testing/public-api.js.map +0 -1
- package/esm2015/testing/skyux-datetime-testing.js +0 -5
- package/esm2015/testing/skyux-datetime-testing.js.map +0 -1
- package/esm2015/testing/timepicker-fixture.js +0 -50
- package/esm2015/testing/timepicker-fixture.js.map +0 -1
- package/fesm2015/skyux-datetime-testing.js.map +0 -1
- package/fesm2015/skyux-datetime.js.map +0 -1
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { SkyAppLocaleProvider } from '@skyux/i18n';
|
|
3
|
-
import moment from 'moment';
|
|
4
|
-
import { Subject } from 'rxjs';
|
|
5
|
-
import { takeUntil } from 'rxjs/operators';
|
|
6
|
-
import * as i0 from "@angular/core";
|
|
7
|
-
import * as i1 from "@skyux/i18n";
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export class SkyFuzzyDateService {
|
|
12
|
-
constructor(localeProvider) {
|
|
13
|
-
this.localeProvider = localeProvider;
|
|
14
|
-
this.ngUnsubscribe = new Subject();
|
|
15
|
-
this.localeProvider
|
|
16
|
-
.getLocaleInfo()
|
|
17
|
-
.pipe(takeUntil(this.ngUnsubscribe))
|
|
18
|
-
.subscribe((localeInfo) => {
|
|
19
|
-
this.currentLocale = localeInfo.locale;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/* istanbul ignore next */
|
|
23
|
-
ngOnDestroy() {
|
|
24
|
-
this.ngUnsubscribe.next();
|
|
25
|
-
this.ngUnsubscribe.complete();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Returns the browser's current locale string.
|
|
29
|
-
*/
|
|
30
|
-
getCurrentLocale() {
|
|
31
|
-
return this.currentLocale;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns the short format of the provided locale.
|
|
35
|
-
* If not provided, the locale will be taken from the browser's default locale.
|
|
36
|
-
*/
|
|
37
|
-
getLocaleShortFormat(locale) {
|
|
38
|
-
return moment.localeData(locale || this.currentLocale).longDateFormat('L');
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Formats a fuzzy date by using the provided format and locale strings.
|
|
42
|
-
* If not provided, the locale will be taken from the browser's default locale.
|
|
43
|
-
*/
|
|
44
|
-
format(fuzzyDate, format, locale) {
|
|
45
|
-
if (!this.isFuzzyDateValid(fuzzyDate)) {
|
|
46
|
-
return '';
|
|
47
|
-
}
|
|
48
|
-
if (!format) {
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
const separator = this.getDateSeparator(format);
|
|
52
|
-
const dateParts = [];
|
|
53
|
-
const formatTokens = format.split(separator);
|
|
54
|
-
locale = locale || this.currentLocale;
|
|
55
|
-
const fuzzyDateMoment = this.getMomentFromFuzzyDate(fuzzyDate).locale(locale);
|
|
56
|
-
for (let index = 0; index < formatTokens.length; index++) {
|
|
57
|
-
const token = formatTokens[index];
|
|
58
|
-
/* istanbul ignore else */
|
|
59
|
-
if (token) {
|
|
60
|
-
// tslint:disable-next-line: switch-default
|
|
61
|
-
switch (token.substr(0, 1).toLowerCase()) {
|
|
62
|
-
case 'y':
|
|
63
|
-
if (fuzzyDate.year) {
|
|
64
|
-
dateParts.push(fuzzyDateMoment.format(token));
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
case 'm':
|
|
68
|
-
if (fuzzyDate.month) {
|
|
69
|
-
dateParts.push(fuzzyDateMoment.format(token));
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case 'd':
|
|
73
|
-
if (fuzzyDate.day) {
|
|
74
|
-
dateParts.push(fuzzyDateMoment.format(token));
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return dateParts.join(separator);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* If not provided, years will default to current year; months will default to January;
|
|
84
|
-
* days will default to 1st of the month.
|
|
85
|
-
*/
|
|
86
|
-
getMomentFromFuzzyDate(fuzzyDate) {
|
|
87
|
-
if (!fuzzyDate) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const year = fuzzyDate.year || this.getDefaultYear(fuzzyDate);
|
|
91
|
-
const month = fuzzyDate.month > 0 ? fuzzyDate.month - 1 : 0;
|
|
92
|
-
const day = fuzzyDate.day || 1;
|
|
93
|
-
return moment([year, month, day]);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Gets a string instance of a fuzzy date.
|
|
97
|
-
* @deprecated Deprecated in favor of the `format` function.
|
|
98
|
-
*/
|
|
99
|
-
getStringFromFuzzyDate(fuzzyDate, dateFormat) {
|
|
100
|
-
if (!fuzzyDate || !dateFormat) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const separator = this.getDateSeparator(dateFormat);
|
|
104
|
-
const dateFormatIndexes = this.getDateFormatIndexes(dateFormat);
|
|
105
|
-
let dateString = '';
|
|
106
|
-
// Get the components of the date in the order expected of the local format.
|
|
107
|
-
const dateComponents = [
|
|
108
|
-
{ value: fuzzyDate.year || 0, index: dateFormatIndexes.yearIndex },
|
|
109
|
-
{ value: fuzzyDate.month || 0, index: dateFormatIndexes.monthIndex },
|
|
110
|
-
{ value: fuzzyDate.day || 0, index: dateFormatIndexes.dayIndex },
|
|
111
|
-
];
|
|
112
|
-
dateComponents.sort((a, b) => a.index - b.index);
|
|
113
|
-
dateComponents.forEach((component) => {
|
|
114
|
-
if (component.value > 0 && component.index > -1) {
|
|
115
|
-
if (dateString) {
|
|
116
|
-
dateString += separator;
|
|
117
|
-
}
|
|
118
|
-
dateString += component.value.toString();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
return dateString.trim();
|
|
122
|
-
}
|
|
123
|
-
getFuzzyDateFromSelectedDate(selectedDate, dateFormat) {
|
|
124
|
-
if (!selectedDate || !dateFormat) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const fuzzyDate = {};
|
|
128
|
-
const dateFormatIndexes = this.getDateFormatIndexes(dateFormat);
|
|
129
|
-
if (dateFormatIndexes.yearIndex > -1) {
|
|
130
|
-
fuzzyDate.year = selectedDate.getFullYear();
|
|
131
|
-
}
|
|
132
|
-
if (dateFormatIndexes.dayIndex > -1) {
|
|
133
|
-
fuzzyDate.day = selectedDate.getDate();
|
|
134
|
-
}
|
|
135
|
-
if (dateFormatIndexes.monthIndex > -1) {
|
|
136
|
-
fuzzyDate.month = selectedDate.getMonth() + 1; // getMonth() is 0-indexed.
|
|
137
|
-
}
|
|
138
|
-
return fuzzyDate;
|
|
139
|
-
}
|
|
140
|
-
getFuzzyDateFromString(date, dateFormat) {
|
|
141
|
-
if (!date || !dateFormat) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
let day;
|
|
145
|
-
let month;
|
|
146
|
-
let year;
|
|
147
|
-
const dateComponents = this.getDateComponents(date);
|
|
148
|
-
const indexes = this.getDateValueIndexes(date, dateFormat);
|
|
149
|
-
// Look at the date string's component count:
|
|
150
|
-
// 3 indicates a full date
|
|
151
|
-
// 2 indicates a month-year or month-day date
|
|
152
|
-
// 1 indicates a year
|
|
153
|
-
// Other indicates a problem
|
|
154
|
-
switch (dateComponents.length) {
|
|
155
|
-
case 3:
|
|
156
|
-
year = dateComponents[indexes.yearIndex];
|
|
157
|
-
month = dateComponents[indexes.monthIndex];
|
|
158
|
-
day = dateComponents[indexes.dayIndex];
|
|
159
|
-
break;
|
|
160
|
-
case 2:
|
|
161
|
-
// First, check for a 4-digit year. If year exists, then we assume the other component
|
|
162
|
-
// is the month. Otherwise, we can assume the input is mm/dd or mm/yy (2-digit year).
|
|
163
|
-
year = this.get4DigitYearFromDateString(date);
|
|
164
|
-
if (year) {
|
|
165
|
-
month =
|
|
166
|
-
dateComponents[0] === year.toString()
|
|
167
|
-
? dateComponents[1]
|
|
168
|
-
: dateComponents[0];
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
if (indexes.dayIndex > -1) {
|
|
172
|
-
// mm/dd
|
|
173
|
-
month =
|
|
174
|
-
indexes.monthIndex < indexes.dayIndex
|
|
175
|
-
? dateComponents[0]
|
|
176
|
-
: dateComponents[1];
|
|
177
|
-
day =
|
|
178
|
-
month === dateComponents[1]
|
|
179
|
-
? dateComponents[0]
|
|
180
|
-
: dateComponents[1];
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
// mm/yy
|
|
184
|
-
month =
|
|
185
|
-
indexes.monthIndex < indexes.yearIndex
|
|
186
|
-
? dateComponents[0]
|
|
187
|
-
: dateComponents[1];
|
|
188
|
-
year =
|
|
189
|
-
month === dateComponents[1]
|
|
190
|
-
? dateComponents[0]
|
|
191
|
-
: dateComponents[1];
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
break;
|
|
195
|
-
case 1:
|
|
196
|
-
year = date;
|
|
197
|
-
break;
|
|
198
|
-
default:
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (month) {
|
|
202
|
-
// Check if month is valid.
|
|
203
|
-
month = this.getMonthNumber(month);
|
|
204
|
-
if (month === undefined) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
// Check if day is valid.
|
|
208
|
-
if (day) {
|
|
209
|
-
day = parseInt(day, 10);
|
|
210
|
-
const fuzzyMoment = this.getMomentFromFuzzyDate({
|
|
211
|
-
month: month,
|
|
212
|
-
day: day,
|
|
213
|
-
year: year,
|
|
214
|
-
});
|
|
215
|
-
if (isNaN(day) || !fuzzyMoment.isValid()) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (year) {
|
|
221
|
-
year =
|
|
222
|
-
year.toString().length === 2
|
|
223
|
-
? moment.parseTwoDigitYear(year)
|
|
224
|
-
: parseInt(year.toString(), 10);
|
|
225
|
-
if (isNaN(year) || year.toString().length !== 4) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
month: month,
|
|
231
|
-
day: day,
|
|
232
|
-
year: year,
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
getFuzzyDateRange(startFuzzyDate, endFuzzyDate) {
|
|
236
|
-
let start;
|
|
237
|
-
let end;
|
|
238
|
-
let days;
|
|
239
|
-
let months;
|
|
240
|
-
let years;
|
|
241
|
-
let valid = false;
|
|
242
|
-
if (startFuzzyDate &&
|
|
243
|
-
startFuzzyDate.year &&
|
|
244
|
-
endFuzzyDate &&
|
|
245
|
-
endFuzzyDate.year) {
|
|
246
|
-
start = this.getMomentFromFuzzyDate(startFuzzyDate);
|
|
247
|
-
end = this.getMomentFromFuzzyDate(endFuzzyDate);
|
|
248
|
-
years = end.diff(start, 'years');
|
|
249
|
-
months = end.diff(start, 'months');
|
|
250
|
-
days = end.diff(start, 'days');
|
|
251
|
-
valid = end.diff(start) >= 0;
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
years: years,
|
|
255
|
-
months: months,
|
|
256
|
-
days: days,
|
|
257
|
-
valid: valid,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
getCurrentFuzzyDate() {
|
|
261
|
-
const currentDate = moment();
|
|
262
|
-
return {
|
|
263
|
-
day: currentDate.date(),
|
|
264
|
-
month: currentDate.month() + 1,
|
|
265
|
-
year: currentDate.year(),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
getMostRecentLeapYear() {
|
|
269
|
-
let leapYear = new Date().getFullYear();
|
|
270
|
-
while (!this.isLeapYear(leapYear)) {
|
|
271
|
-
leapYear -= 1;
|
|
272
|
-
}
|
|
273
|
-
return leapYear;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Returns the first separator found in the provided date format string.
|
|
277
|
-
* Accepted separators: ['/', '.', '-', ' '].
|
|
278
|
-
* @param dateFormat
|
|
279
|
-
*/
|
|
280
|
-
getDateSeparator(dateFormat) {
|
|
281
|
-
let returnValue;
|
|
282
|
-
const separators = ['/', '.', '-', ' '];
|
|
283
|
-
separators.forEach((separator) => {
|
|
284
|
-
if (!returnValue && dateFormat.indexOf(separator) > 0) {
|
|
285
|
-
returnValue = separator;
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
return returnValue;
|
|
289
|
-
}
|
|
290
|
-
get4DigitYearFromDateString(date) {
|
|
291
|
-
let year;
|
|
292
|
-
const separator = this.getDateSeparator(date);
|
|
293
|
-
// Find the number value in the string that is 4 digits long.
|
|
294
|
-
date.split(separator).forEach((dateComponent) => {
|
|
295
|
-
if (!year && parseInt(dateComponent, 10).toString().length === 4) {
|
|
296
|
-
year = dateComponent;
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
if (year && !isNaN(Number(year))) {
|
|
300
|
-
return parseInt(year, 10);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
isLeapYear(year) {
|
|
304
|
-
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
305
|
-
}
|
|
306
|
-
getMonthNumber(month) {
|
|
307
|
-
let returnValue;
|
|
308
|
-
const monthAsNumber = parseInt(month, 10);
|
|
309
|
-
// If the month component is a string ("Janaury"), we check to see if it is a valid month
|
|
310
|
-
if (isNaN(monthAsNumber)) {
|
|
311
|
-
if (!moment(month, 'MMMM').isValid()) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
returnValue = parseInt(moment().month(month).format('M'), 10);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
returnValue = monthAsNumber;
|
|
318
|
-
}
|
|
319
|
-
// Ensure that the month is between 1 and 12
|
|
320
|
-
if (!(1 <= returnValue && returnValue <= 12)) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
return returnValue;
|
|
324
|
-
}
|
|
325
|
-
getDefaultYear(fuzzyDate) {
|
|
326
|
-
// Check if we need to return a leap year or the current year.
|
|
327
|
-
if (fuzzyDate.month === 2 && fuzzyDate.day === 29) {
|
|
328
|
-
return this.getMostRecentLeapYear();
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
return new Date().getFullYear();
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
getDateComponents(date) {
|
|
335
|
-
const separator = this.getDateSeparator(date);
|
|
336
|
-
return date.split(separator);
|
|
337
|
-
}
|
|
338
|
-
// Returns the order of year, month, and day from the provided date format.
|
|
339
|
-
getDateFormatIndexes(dateFormat) {
|
|
340
|
-
dateFormat = dateFormat.toLowerCase();
|
|
341
|
-
return {
|
|
342
|
-
yearIndex: dateFormat.indexOf('y'),
|
|
343
|
-
monthIndex: dateFormat.indexOf('m'),
|
|
344
|
-
dayIndex: dateFormat.indexOf('d'),
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
// Returns the index of each of the date components in the provided string (month, day, year).
|
|
348
|
-
getDateValueIndexes(date, dateFormat) {
|
|
349
|
-
const dateFormatIndexes = this.getDateFormatIndexes(dateFormat);
|
|
350
|
-
const dateComponentIndexes = [];
|
|
351
|
-
if (dateFormatIndexes.yearIndex > -1) {
|
|
352
|
-
dateComponentIndexes.push(dateFormatIndexes.yearIndex);
|
|
353
|
-
}
|
|
354
|
-
if (dateFormatIndexes.monthIndex > -1) {
|
|
355
|
-
dateComponentIndexes.push(dateFormatIndexes.monthIndex);
|
|
356
|
-
}
|
|
357
|
-
if (dateFormatIndexes.dayIndex > -1) {
|
|
358
|
-
dateComponentIndexes.push(dateFormatIndexes.dayIndex);
|
|
359
|
-
}
|
|
360
|
-
dateComponentIndexes.sort(function (a, b) {
|
|
361
|
-
return a - b;
|
|
362
|
-
});
|
|
363
|
-
return {
|
|
364
|
-
yearIndex: dateComponentIndexes.indexOf(dateFormatIndexes.yearIndex),
|
|
365
|
-
monthIndex: dateComponentIndexes.indexOf(dateFormatIndexes.monthIndex),
|
|
366
|
-
dayIndex: dateComponentIndexes.indexOf(dateFormatIndexes.dayIndex),
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Validates the provided SkyFuzzyDate object. Valid fuzzy dates are as follows:
|
|
371
|
-
* month, day, year
|
|
372
|
-
* month, year
|
|
373
|
-
* month, day
|
|
374
|
-
* year only
|
|
375
|
-
*/
|
|
376
|
-
isFuzzyDateValid(fuzzyDate) {
|
|
377
|
-
if (!fuzzyDate) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
// If none of the dates part are specified, return false.
|
|
381
|
-
if (!fuzzyDate.day && !fuzzyDate.month && !fuzzyDate.year) {
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
// If only month is specified, return false.
|
|
385
|
-
if (!fuzzyDate.day && fuzzyDate.month && !fuzzyDate.year) {
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
// If only day is specified, return false.
|
|
389
|
-
if (fuzzyDate.day && !fuzzyDate.month && !fuzzyDate.year) {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
return true;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
SkyFuzzyDateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyFuzzyDateService, deps: [{ token: i1.SkyAppLocaleProvider }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
396
|
-
SkyFuzzyDateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyFuzzyDateService, providedIn: 'root' });
|
|
397
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyFuzzyDateService, decorators: [{
|
|
398
|
-
type: Injectable,
|
|
399
|
-
args: [{
|
|
400
|
-
providedIn: 'root',
|
|
401
|
-
}]
|
|
402
|
-
}], ctorParameters: function () { return [{ type: i1.SkyAppLocaleProvider }]; } });
|
|
403
|
-
//# sourceMappingURL=fuzzy-date.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fuzzy-date.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/datetime/src/lib/modules/datepicker/fuzzy-date.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;;AAuB3C;;GAEG;AAIH,MAAM,OAAO,mBAAmB;IAK9B,YAAoB,cAAoC;QAApC,mBAAc,GAAd,cAAc,CAAsB;QAFhD,kBAAa,GAAG,IAAI,OAAO,EAAQ,CAAC;QAG1C,IAAI,CAAC,cAAc;aAChB,aAAa,EAAE;aACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aACnC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;Y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AAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,SAAS,EAAE,oBAAoB,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC;YACpE,UAAU,EAAE,oBAAoB,CAAC,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC;YACtE,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC;SACnE,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACK,gBAAgB,CAAC,SAAuB;QAC9C,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,KAAK,CAAC;SACd;QAED,yDAAyD;QACzD,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACzD,OAAO,KAAK,CAAC;SACd;QAED,4CAA4C;QAC5C,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACxD,OAAO,KAAK,CAAC;SACd;QAED,0CAA0C;QAC1C,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACxD,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAAC;IACd,CAAC;;iHAldU,mBAAmB;qHAAnB,mBAAmB,cAFlB,MAAM;4FAEP,mBAAmB;kBAH/B,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import { Injectable, OnDestroy } from '@angular/core';\nimport { SkyAppLocaleProvider } from '@skyux/i18n';\n\nimport moment from 'moment';\nimport { Subject } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\nimport { SkyFuzzyDate } from './fuzzy-date';\n\n/**\n * @internal\n */\ninterface SkyDateIndexes {\n yearIndex: number;\n monthIndex: number;\n dayIndex: number;\n}\n\n/**\n * @internal\n */\ninterface SkyFuzzyDateRange {\n years: string;\n months: string;\n days: string;\n valid: boolean;\n}\n\n/**\n * @internal\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyFuzzyDateService implements OnDestroy {\n private currentLocale: string;\n\n private ngUnsubscribe = new Subject<void>();\n\n constructor(private localeProvider: SkyAppLocaleProvider) {\n this.localeProvider\n .getLocaleInfo()\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((localeInfo) => {\n this.currentLocale = localeInfo.locale;\n });\n }\n\n /* istanbul ignore next */\n public ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n\n /**\n * Returns the browser's current locale string.\n */\n public getCurrentLocale(): string {\n return this.currentLocale;\n }\n\n /**\n * Returns the short format of the provided locale.\n * If not provided, the locale will be taken from the browser's default locale.\n */\n public getLocaleShortFormat(locale?: string): string {\n return moment.localeData(locale || this.currentLocale).longDateFormat('L');\n }\n\n /**\n * Formats a fuzzy date by using the provided format and locale strings.\n * If not provided, the locale will be taken from the browser's default locale.\n */\n public format(\n fuzzyDate: SkyFuzzyDate,\n format: string,\n locale?: string\n ): string {\n if (!this.isFuzzyDateValid(fuzzyDate)) {\n return '';\n }\n\n if (!format) {\n return '';\n }\n\n const separator = this.getDateSeparator(format);\n const dateParts: string[] = [];\n const formatTokens: string[] = format.split(separator);\n locale = locale || this.currentLocale;\n const fuzzyDateMoment =\n this.getMomentFromFuzzyDate(fuzzyDate).locale(locale);\n\n for (let index = 0; index < formatTokens.length; index++) {\n const token = formatTokens[index];\n\n /* istanbul ignore else */\n if (token) {\n // tslint:disable-next-line: switch-default\n switch (token.substr(0, 1).toLowerCase()) {\n case 'y':\n if (fuzzyDate.year) {\n dateParts.push(fuzzyDateMoment.format(token));\n }\n break;\n case 'm':\n if (fuzzyDate.month) {\n dateParts.push(fuzzyDateMoment.format(token));\n }\n break;\n case 'd':\n if (fuzzyDate.day) {\n dateParts.push(fuzzyDateMoment.format(token));\n }\n break;\n }\n }\n }\n\n return dateParts.join(separator);\n }\n\n /**\n * If not provided, years will default to current year; months will default to January;\n * days will default to 1st of the month.\n */\n public getMomentFromFuzzyDate(fuzzyDate: SkyFuzzyDate): any {\n if (!fuzzyDate) {\n return;\n }\n\n const year = fuzzyDate.year || this.getDefaultYear(fuzzyDate);\n const month = fuzzyDate.month > 0 ? fuzzyDate.month - 1 : 0;\n const day = fuzzyDate.day || 1;\n\n return moment([year, month, day]);\n }\n\n /**\n * Gets a string instance of a fuzzy date.\n * @deprecated Deprecated in favor of the `format` function.\n */\n public getStringFromFuzzyDate(\n fuzzyDate: SkyFuzzyDate,\n dateFormat: string\n ): string {\n if (!fuzzyDate || !dateFormat) {\n return;\n }\n\n const separator = this.getDateSeparator(dateFormat);\n const dateFormatIndexes = this.getDateFormatIndexes(dateFormat);\n let dateString = '';\n\n // Get the components of the date in the order expected of the local format.\n const dateComponents = [\n { value: fuzzyDate.year || 0, index: dateFormatIndexes.yearIndex },\n { value: fuzzyDate.month || 0, index: dateFormatIndexes.monthIndex },\n { value: fuzzyDate.day || 0, index: dateFormatIndexes.dayIndex },\n ];\n dateComponents.sort((a: any, b: any) => a.index - b.index);\n\n dateComponents.forEach((component) => {\n if (component.value > 0 && component.index > -1) {\n if (dateString) {\n dateString += separator;\n }\n dateString += component.value.toString();\n }\n });\n\n return dateString.trim();\n }\n\n public getFuzzyDateFromSelectedDate(\n selectedDate: Date,\n dateFormat: string\n ): SkyFuzzyDate {\n if (!selectedDate || !dateFormat) {\n return;\n }\n\n const fuzzyDate: SkyFuzzyDate = {};\n const dateFormatIndexes = this.getDateFormatIndexes(dateFormat);\n\n if (dateFormatIndexes.yearIndex > -1) {\n fuzzyDate.year = selectedDate.getFullYear();\n }\n\n if (dateFormatIndexes.dayIndex > -1) {\n fuzzyDate.day = selectedDate.getDate();\n }\n\n if (dateFormatIndexes.monthIndex > -1) {\n fuzzyDate.month = selectedDate.getMonth() + 1; // getMonth() is 0-indexed.\n }\n\n return fuzzyDate;\n }\n\n public getFuzzyDateFromString(\n date: string,\n dateFormat: string\n ): SkyFuzzyDate {\n if (!date || !dateFormat) {\n return;\n }\n\n let day: any;\n let month: any;\n let year: any;\n\n const dateComponents = this.getDateComponents(date);\n const indexes = this.getDateValueIndexes(date, dateFormat);\n\n // Look at the date string's component count:\n // 3 indicates a full date\n // 2 indicates a month-year or month-day date\n // 1 indicates a year\n // Other indicates a problem\n switch (dateComponents.length) {\n case 3:\n year = dateComponents[indexes.yearIndex];\n month = dateComponents[indexes.monthIndex];\n day = dateComponents[indexes.dayIndex];\n break;\n case 2:\n // First, check for a 4-digit year. If year exists, then we assume the other component\n // is the month. Otherwise, we can assume the input is mm/dd or mm/yy (2-digit year).\n year = this.get4DigitYearFromDateString(date);\n if (year) {\n month =\n dateComponents[0] === year.toString()\n ? dateComponents[1]\n : dateComponents[0];\n } else {\n if (indexes.dayIndex > -1) {\n // mm/dd\n month =\n indexes.monthIndex < indexes.dayIndex\n ? dateComponents[0]\n : dateComponents[1];\n day =\n month === dateComponents[1]\n ? dateComponents[0]\n : dateComponents[1];\n } else {\n // mm/yy\n month =\n indexes.monthIndex < indexes.yearIndex\n ? dateComponents[0]\n : dateComponents[1];\n year =\n month === dateComponents[1]\n ? dateComponents[0]\n : dateComponents[1];\n }\n }\n break;\n case 1:\n year = date;\n break;\n default:\n return;\n }\n\n if (month) {\n // Check if month is valid.\n month = this.getMonthNumber(month);\n if (month === undefined) {\n return;\n }\n\n // Check if day is valid.\n if (day) {\n day = parseInt(day, 10);\n const fuzzyMoment = this.getMomentFromFuzzyDate({\n month: month,\n day: day,\n year: year,\n });\n if (isNaN(day) || !fuzzyMoment.isValid()) {\n return;\n }\n }\n }\n\n if (year) {\n year =\n year.toString().length === 2\n ? moment.parseTwoDigitYear(year)\n : parseInt(year.toString(), 10);\n if (isNaN(year) || year.toString().length !== 4) {\n return;\n }\n }\n\n return {\n month: month,\n day: day,\n year: year,\n };\n }\n\n public getFuzzyDateRange(\n startFuzzyDate: SkyFuzzyDate,\n endFuzzyDate: SkyFuzzyDate\n ): SkyFuzzyDateRange {\n let start;\n let end;\n let days;\n let months;\n let years;\n let valid = false;\n\n if (\n startFuzzyDate &&\n startFuzzyDate.year &&\n endFuzzyDate &&\n endFuzzyDate.year\n ) {\n start = this.getMomentFromFuzzyDate(startFuzzyDate);\n end = this.getMomentFromFuzzyDate(endFuzzyDate);\n\n years = end.diff(start, 'years');\n months = end.diff(start, 'months');\n days = end.diff(start, 'days');\n valid = end.diff(start) >= 0;\n }\n\n return {\n years: years,\n months: months,\n days: days,\n valid: valid,\n };\n }\n\n public getCurrentFuzzyDate(): SkyFuzzyDate {\n const currentDate = moment();\n\n return {\n day: currentDate.date(),\n month: currentDate.month() + 1, // month() is 0-indexed.\n year: currentDate.year(),\n };\n }\n\n private getMostRecentLeapYear(): number {\n let leapYear = new Date().getFullYear();\n\n while (!this.isLeapYear(leapYear)) {\n leapYear -= 1;\n }\n\n return leapYear;\n }\n\n /**\n * Returns the first separator found in the provided date format string.\n * Accepted separators: ['/', '.', '-', ' '].\n * @param dateFormat\n */\n private getDateSeparator(dateFormat: string): string {\n let returnValue: string;\n const separators = ['/', '.', '-', ' '];\n\n separators.forEach((separator) => {\n if (!returnValue && dateFormat.indexOf(separator) > 0) {\n returnValue = separator;\n }\n });\n\n return returnValue;\n }\n\n private get4DigitYearFromDateString(date: string): number {\n let year: string;\n const separator = this.getDateSeparator(date);\n\n // Find the number value in the string that is 4 digits long.\n date.split(separator).forEach((dateComponent) => {\n if (!year && parseInt(dateComponent, 10).toString().length === 4) {\n year = dateComponent;\n }\n });\n\n if (year && !isNaN(Number(year))) {\n return parseInt(year, 10);\n }\n }\n\n private isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n }\n\n private getMonthNumber(month: string): number {\n let returnValue: number;\n const monthAsNumber = parseInt(month, 10);\n\n // If the month component is a string (\"Janaury\"), we check to see if it is a valid month\n if (isNaN(monthAsNumber)) {\n if (!moment(month, 'MMMM').isValid()) {\n return;\n }\n returnValue = parseInt(moment().month(month).format('M'), 10);\n } else {\n returnValue = monthAsNumber;\n }\n\n // Ensure that the month is between 1 and 12\n if (!(1 <= returnValue && returnValue <= 12)) {\n return;\n }\n\n return returnValue;\n }\n\n private getDefaultYear(fuzzyDate: SkyFuzzyDate): number {\n // Check if we need to return a leap year or the current year.\n if (fuzzyDate.month === 2 && fuzzyDate.day === 29) {\n return this.getMostRecentLeapYear();\n } else {\n return new Date().getFullYear();\n }\n }\n\n private getDateComponents(date: string): string[] {\n const separator = this.getDateSeparator(date);\n return date.split(separator);\n }\n\n // Returns the order of year, month, and day from the provided date format.\n private getDateFormatIndexes(dateFormat: string): SkyDateIndexes {\n dateFormat = dateFormat.toLowerCase();\n return {\n yearIndex: dateFormat.indexOf('y'),\n monthIndex: dateFormat.indexOf('m'),\n dayIndex: dateFormat.indexOf('d'),\n };\n }\n\n // Returns the index of each of the date components in the provided string (month, day, year).\n private getDateValueIndexes(\n date: string,\n dateFormat: string\n ): SkyDateIndexes {\n const dateFormatIndexes = this.getDateFormatIndexes(dateFormat);\n const dateComponentIndexes = [];\n if (dateFormatIndexes.yearIndex > -1) {\n dateComponentIndexes.push(dateFormatIndexes.yearIndex);\n }\n\n if (dateFormatIndexes.monthIndex > -1) {\n dateComponentIndexes.push(dateFormatIndexes.monthIndex);\n }\n\n if (dateFormatIndexes.dayIndex > -1) {\n dateComponentIndexes.push(dateFormatIndexes.dayIndex);\n }\n\n dateComponentIndexes.sort(function (a, b) {\n return a - b;\n });\n\n return {\n yearIndex: dateComponentIndexes.indexOf(dateFormatIndexes.yearIndex),\n monthIndex: dateComponentIndexes.indexOf(dateFormatIndexes.monthIndex),\n dayIndex: dateComponentIndexes.indexOf(dateFormatIndexes.dayIndex),\n };\n }\n\n /**\n * Validates the provided SkyFuzzyDate object. Valid fuzzy dates are as follows:\n * month, day, year\n * month, year\n * month, day\n * year only\n */\n private isFuzzyDateValid(fuzzyDate: SkyFuzzyDate): boolean {\n if (!fuzzyDate) {\n return false;\n }\n\n // If none of the dates part are specified, return false.\n if (!fuzzyDate.day && !fuzzyDate.month && !fuzzyDate.year) {\n return false;\n }\n\n // If only month is specified, return false.\n if (!fuzzyDate.day && fuzzyDate.month && !fuzzyDate.year) {\n return false;\n }\n\n // If only day is specified, return false.\n if (fuzzyDate.day && !fuzzyDate.month && !fuzzyDate.year) {\n return false;\n }\n\n return true;\n }\n}\n"]}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Component } from '@angular/core';
|
|
2
|
-
import { SkyDatepickerCalendarInnerComponent } from './datepicker-calendar-inner.component';
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
import * as i1 from "./datepicker-calendar-inner.component";
|
|
5
|
-
import * as i2 from "@skyux/indicators";
|
|
6
|
-
import * as i3 from "@angular/common";
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export class SkyMonthPickerComponent {
|
|
11
|
-
constructor(datepicker) {
|
|
12
|
-
this.rows = [];
|
|
13
|
-
this.datepicker = datepicker;
|
|
14
|
-
}
|
|
15
|
-
ngOnInit() {
|
|
16
|
-
this.datepicker.stepMonth = {
|
|
17
|
-
years: 1,
|
|
18
|
-
};
|
|
19
|
-
this.datepicker.setRefreshViewHandler(() => {
|
|
20
|
-
this.refreshMonthView();
|
|
21
|
-
}, 'month');
|
|
22
|
-
this.datepicker.setCompareHandler(this.compareMonth, 'month');
|
|
23
|
-
this.datepicker.refreshView();
|
|
24
|
-
this.datepicker.setKeydownHandler((key, event) => {
|
|
25
|
-
this.keydownMonths(key, event);
|
|
26
|
-
}, 'month');
|
|
27
|
-
}
|
|
28
|
-
compareMonth(date1, date2) {
|
|
29
|
-
const d1 = new Date(date1.getFullYear(), date1.getMonth());
|
|
30
|
-
const d2 = new Date(date2.getFullYear(), date2.getMonth());
|
|
31
|
-
return d1.getTime() - d2.getTime();
|
|
32
|
-
}
|
|
33
|
-
refreshMonthView() {
|
|
34
|
-
const months = new Array(12);
|
|
35
|
-
const year = this.datepicker.activeDate.getFullYear();
|
|
36
|
-
let date;
|
|
37
|
-
for (let i = 0; i < 12; i++) {
|
|
38
|
-
date = new Date(year, i, 1);
|
|
39
|
-
date = this.datepicker.fixTimeZone(date);
|
|
40
|
-
months[i] = this.datepicker.createDateObject(date, this.datepicker.formatMonth, false, this.datepicker.datepickerId + '-' + i);
|
|
41
|
-
}
|
|
42
|
-
this.title = this.datepicker.dateFilter(this.datepicker.activeDate, this.datepicker.formatMonthTitle);
|
|
43
|
-
this.rows = this.datepicker.createCalendarRows(months, this.datepicker.monthColLimit);
|
|
44
|
-
}
|
|
45
|
-
keydownMonths(key, event) {
|
|
46
|
-
let date = this.datepicker.activeDate.getMonth();
|
|
47
|
-
/* istanbul ignore else */
|
|
48
|
-
/* sanity check */
|
|
49
|
-
if (key === 'left') {
|
|
50
|
-
date = date - 1;
|
|
51
|
-
}
|
|
52
|
-
else if (key === 'up') {
|
|
53
|
-
date = date - this.datepicker.monthColLimit;
|
|
54
|
-
}
|
|
55
|
-
else if (key === 'right') {
|
|
56
|
-
date = date + 1;
|
|
57
|
-
}
|
|
58
|
-
else if (key === 'down') {
|
|
59
|
-
date = date + this.datepicker.monthColLimit;
|
|
60
|
-
}
|
|
61
|
-
else if (key === 'pageup' || key === 'pagedown') {
|
|
62
|
-
const year = this.datepicker.activeDate.getFullYear() + (key === 'pageup' ? -1 : 1);
|
|
63
|
-
this.datepicker.activeDate.setFullYear(year);
|
|
64
|
-
}
|
|
65
|
-
else if (key === 'home') {
|
|
66
|
-
date = 0;
|
|
67
|
-
}
|
|
68
|
-
else if (key === 'end') {
|
|
69
|
-
date = 11;
|
|
70
|
-
}
|
|
71
|
-
this.datepicker.activeDate.setMonth(date);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
SkyMonthPickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyMonthPickerComponent, deps: [{ token: i1.SkyDatepickerCalendarInnerComponent }], target: i0.ɵɵFactoryTarget.Component });
|
|
75
|
-
SkyMonthPickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: SkyMonthPickerComponent, selector: "sky-monthpicker", ngImport: i0, template: "<table *ngIf=\"datepicker.datepickerMode === 'month'\" role=\"grid\">\n <thead>\n <tr>\n <th class=\"sky-datepicker-header-left\">\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n <th\n [attr.colspan]=\"\n datepicker.monthColLimit - 2 <= 0 ? 1 : datepicker.monthColLimit - 2\n \"\n >\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n type=\"button\"\n class=\"\n sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\n \"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === maxMode\"\n [ngClass]=\"{\n 'sky-btn-disabled': datepicker.datepickerMode === maxMode\n }\"\n tabindex=\"-1\"\n >\n <strong>{{ title }}</strong>\n </button>\n </th>\n <th class=\"sky-datepicker-header-right\">\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of rows\">\n <td\n *ngFor=\"let date of row\"\n class=\"text-center\"\n role=\"gridcell\"\n id=\"{{ date.uid }}\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{\n 'sky-datepicker-btn-selected': date.selected,\n 'sky-btn-disabled': date.disabled,\n 'sky-btn-active': datepicker.isActive(date)\n }\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date)\"\n tabindex=\"-1\"\n >\n <span [ngClass]=\"{ 'sky-datepicker-current': date.current }\">{{\n date.label\n }}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n", styles: [":host-context(.sky-theme-modern) :host:focus{outline:none}.sky-theme-modern :host:focus{outline:none}\n"], components: [{ type: i2.λ4, selector: "sky-icon", inputs: ["icon", "iconType", "size", "fixedWidth", "variant"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
|
|
76
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyMonthPickerComponent, decorators: [{
|
|
77
|
-
type: Component,
|
|
78
|
-
args: [{
|
|
79
|
-
selector: 'sky-monthpicker',
|
|
80
|
-
templateUrl: 'monthpicker.component.html',
|
|
81
|
-
styleUrls: ['./monthpicker.component.scss'],
|
|
82
|
-
}]
|
|
83
|
-
}], ctorParameters: function () { return [{ type: i1.SkyDatepickerCalendarInnerComponent }]; } });
|
|
84
|
-
//# sourceMappingURL=monthpicker.component.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"monthpicker.component.js","sourceRoot":"","sources":["../../../../../../../../libs/components/datetime/src/lib/modules/datepicker/monthpic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7C;aAAM,IAAI,GAAG,KAAK,OAAO,EAAE;YAC1B,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;SACjB;aAAM,IAAI,GAAG,KAAK,MAAM,EAAE;YACzB,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;SAC7C;aAAM,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,UAAU,EAAE;YACjD,MAAM,IAAI,GACR,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACzE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC9C;aAAM,IAAI,GAAG,KAAK,MAAM,EAAE;YACzB,IAAI,GAAG,CAAC,CAAC;SACV;aAAM,IAAI,GAAG,KAAK,KAAK,EAAE;YACxB,IAAI,GAAG,EAAE,CAAC;SACX;QACD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;;qHAtFU,uBAAuB;yGAAvB,uBAAuB,uDCbpC,gzFA0FA;4FD7Ea,uBAAuB;kBALnC,SAAS;mBAAC;oBACT,QAAQ,EAAE,iBAAiB;oBAC3B,WAAW,EAAE,4BAA4B;oBACzC,SAAS,EAAE,CAAC,8BAA8B,CAAC;iBAC5C","sourcesContent":["import { Component, OnInit } from '@angular/core';\n\nimport { SkyDatepickerCalendarInnerComponent } from './datepicker-calendar-inner.component';\nimport { SkyDatepickerDate } from './datepicker-date';\n\n/**\n * @internal\n */\n@Component({\n selector: 'sky-monthpicker',\n templateUrl: 'monthpicker.component.html',\n styleUrls: ['./monthpicker.component.scss'],\n})\nexport class SkyMonthPickerComponent implements OnInit {\n public datepicker: SkyDatepickerCalendarInnerComponent;\n\n public maxMode: string;\n\n public rows: Array<Array<SkyDatepickerDate>> = [];\n\n public title: string;\n\n public constructor(datepicker: SkyDatepickerCalendarInnerComponent) {\n this.datepicker = datepicker;\n }\n\n public ngOnInit(): void {\n this.datepicker.stepMonth = {\n years: 1,\n };\n\n this.datepicker.setRefreshViewHandler(() => {\n this.refreshMonthView();\n }, 'month');\n\n this.datepicker.setCompareHandler(this.compareMonth, 'month');\n\n this.datepicker.refreshView();\n\n this.datepicker.setKeydownHandler((key: string, event: KeyboardEvent) => {\n this.keydownMonths(key, event);\n }, 'month');\n }\n\n private compareMonth(date1: Date, date2: Date): number {\n const d1 = new Date(date1.getFullYear(), date1.getMonth());\n const d2 = new Date(date2.getFullYear(), date2.getMonth());\n return d1.getTime() - d2.getTime();\n }\n\n private refreshMonthView(): void {\n const months: Array<SkyDatepickerDate> = new Array(12);\n const year: number = this.datepicker.activeDate.getFullYear();\n let date: Date;\n\n for (let i = 0; i < 12; i++) {\n date = new Date(year, i, 1);\n date = this.datepicker.fixTimeZone(date);\n months[i] = this.datepicker.createDateObject(\n date,\n this.datepicker.formatMonth,\n false,\n this.datepicker.datepickerId + '-' + i\n );\n }\n\n this.title = this.datepicker.dateFilter(\n this.datepicker.activeDate,\n this.datepicker.formatMonthTitle\n );\n this.rows = this.datepicker.createCalendarRows(\n months,\n this.datepicker.monthColLimit\n );\n }\n\n private keydownMonths(key: string, event: KeyboardEvent) {\n let date = this.datepicker.activeDate.getMonth();\n\n /* istanbul ignore else */\n /* sanity check */\n if (key === 'left') {\n date = date - 1;\n } else if (key === 'up') {\n date = date - this.datepicker.monthColLimit;\n } else if (key === 'right') {\n date = date + 1;\n } else if (key === 'down') {\n date = date + this.datepicker.monthColLimit;\n } else if (key === 'pageup' || key === 'pagedown') {\n const year =\n this.datepicker.activeDate.getFullYear() + (key === 'pageup' ? -1 : 1);\n this.datepicker.activeDate.setFullYear(year);\n } else if (key === 'home') {\n date = 0;\n } else if (key === 'end') {\n date = 11;\n }\n this.datepicker.activeDate.setMonth(date);\n }\n}\n","<table *ngIf=\"datepicker.datepickerMode === 'month'\" role=\"grid\">\n <thead>\n <tr>\n <th class=\"sky-datepicker-header-left\">\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n <th\n [attr.colspan]=\"\n datepicker.monthColLimit - 2 <= 0 ? 1 : datepicker.monthColLimit - 2\n \"\n >\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n type=\"button\"\n class=\"\n sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\n \"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === maxMode\"\n [ngClass]=\"{\n 'sky-btn-disabled': datepicker.datepickerMode === maxMode\n }\"\n tabindex=\"-1\"\n >\n <strong>{{ title }}</strong>\n </button>\n </th>\n <th class=\"sky-datepicker-header-right\">\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of rows\">\n <td\n *ngFor=\"let date of row\"\n class=\"text-center\"\n role=\"gridcell\"\n id=\"{{ date.uid }}\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{\n 'sky-datepicker-btn-selected': date.selected,\n 'sky-btn-disabled': date.disabled,\n 'sky-btn-active': datepicker.isActive(date)\n }\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date)\"\n tabindex=\"-1\"\n >\n <span [ngClass]=\"{ 'sky-datepicker-current': date.current }\">{{\n date.label\n }}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n"]}
|