@beinformed/ui 1.58.3 → 1.59.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.
- package/CHANGELOG.md +24 -0
- package/esm/constants/Constants.js +10 -0
- package/esm/constants/Constants.js.map +1 -1
- package/esm/constants/Settings.js +5 -1
- package/esm/constants/Settings.js.map +1 -1
- package/esm/models/attributes/DatetimeAttributeModel.js +39 -4
- package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
- package/esm/models/attributes/input-constraints/DatetimeFormatConstraint.js +31 -2
- package/esm/models/attributes/input-constraints/DatetimeFormatConstraint.js.map +1 -1
- package/esm/models/content/SectionModel.js +1 -1
- package/esm/models/content/SectionModel.js.map +1 -1
- package/esm/models/content/SubSectionModel.js +12 -4
- package/esm/models/content/SubSectionModel.js.map +1 -1
- package/esm/react-client/client.js +2 -1
- package/esm/react-client/client.js.map +1 -1
- package/esm/react-server/serverUtil.js +2 -1
- package/esm/react-server/serverUtil.js.map +1 -1
- package/esm/redux/actions/Preferences.js +15 -1
- package/esm/redux/actions/Preferences.js.map +1 -1
- package/esm/utils/datetime/DateTimeUtil.js +292 -94
- package/esm/utils/datetime/DateTimeUtil.js.map +1 -1
- package/lib/constants/Constants.js +11 -1
- package/lib/constants/Constants.js.flow +11 -0
- package/lib/constants/Constants.js.map +1 -1
- package/lib/constants/Settings.js +7 -2
- package/lib/constants/Settings.js.flow +6 -0
- package/lib/constants/Settings.js.map +1 -1
- package/lib/models/attributes/DatetimeAttributeModel.js +38 -3
- package/lib/models/attributes/DatetimeAttributeModel.js.flow +54 -4
- package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
- package/lib/models/attributes/__tests__/DatetimeAttributeModel.spec.js.flow +9 -0
- package/lib/models/attributes/__tests__/DatetimeAttributeModel_offset.spec.js.flow +306 -0
- package/lib/models/attributes/input-constraints/DatetimeFormatConstraint.js +31 -2
- package/lib/models/attributes/input-constraints/DatetimeFormatConstraint.js.flow +42 -3
- package/lib/models/attributes/input-constraints/DatetimeFormatConstraint.js.map +1 -1
- package/lib/models/content/SectionModel.js +1 -1
- package/lib/models/content/SectionModel.js.flow +2 -1
- package/lib/models/content/SectionModel.js.map +1 -1
- package/lib/models/content/SubSectionModel.js +12 -3
- package/lib/models/content/SubSectionModel.js.flow +20 -3
- package/lib/models/content/SubSectionModel.js.map +1 -1
- package/lib/models/content/__tests__/ContentModel.spec.js.flow +3 -3
- package/lib/react-client/client.js +1 -0
- package/lib/react-client/client.js.flow +2 -0
- package/lib/react-client/client.js.map +1 -1
- package/lib/react-server/__tests__/serverUtil.spec.js.flow +12 -0
- package/lib/react-server/serverUtil.js +1 -0
- package/lib/react-server/serverUtil.js.flow +2 -0
- package/lib/react-server/serverUtil.js.map +1 -1
- package/lib/redux/actions/Preferences.js +17 -2
- package/lib/redux/actions/Preferences.js.flow +22 -0
- package/lib/redux/actions/Preferences.js.map +1 -1
- package/lib/redux/reducers/__tests__/ModelCatalogReducer.spec.js.flow +23 -0
- package/lib/utils/datetime/DateTimeUtil.js +292 -93
- package/lib/utils/datetime/DateTimeUtil.js.flow +482 -172
- package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
- package/lib/utils/datetime/__tests__/DateTime.spec.js.flow +771 -483
- package/package.json +11 -9
- package/src/constants/Constants.js +11 -0
- package/src/constants/Settings.js +6 -0
- package/src/models/attributes/DatetimeAttributeModel.js +54 -4
- package/src/models/attributes/__tests__/DatetimeAttributeModel.spec.js +9 -0
- package/src/models/attributes/__tests__/DatetimeAttributeModel_offset.spec.js +306 -0
- package/src/models/attributes/input-constraints/DatetimeFormatConstraint.js +42 -3
- package/src/models/content/SectionModel.js +2 -1
- package/src/models/content/SubSectionModel.js +20 -3
- package/src/models/content/__tests__/ContentModel.spec.js +3 -3
- package/src/react-client/client.js +2 -0
- package/src/react-server/__tests__/serverUtil.spec.js +12 -0
- package/src/react-server/serverUtil.js +2 -0
- package/src/redux/actions/Preferences.js +22 -0
- package/src/redux/reducers/__tests__/ModelCatalogReducer.spec.js +23 -0
- package/src/utils/datetime/DateTimeUtil.js +482 -172
- package/src/utils/datetime/__tests__/DateTime.spec.js +771 -483
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
|
3
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
4
|
+
import _Math$trunc from "@babel/runtime-corejs3/core-js-stable/math/trunc";
|
|
5
|
+
import _padStartInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/pad-start";
|
|
6
|
+
import { format, isAfter, isBefore, isSameDay, isValid, parse, add, sub, set, startOfMonth, endOfMonth, startOfWeek, getHours, getMinutes, getDay, getWeek } from "date-fns";
|
|
7
|
+
import { enGB, nl } from "date-fns/locale";
|
|
8
|
+
import { tz } from "@date-fns/tz";
|
|
9
|
+
import soft from "timezone-soft";
|
|
10
|
+
import { DATETIME_OFFSET_FORMAT, DEFAULT_FIRST_WEEK_CONTAINS_DATE, DEFAULT_WEEK_STARTS_ON, getSetting, IS_GRAALJS, isIncludeTimeOffsetInDateTimes, ISO_DATE_FORMAT, ISO_DATETIME_FORMAT, ISO_TIME_FORMAT, ISO_TIMESTAMP_FORMAT } from "../../constants";
|
|
4
11
|
import { getCookie } from "../browser/Cookies";
|
|
5
|
-
import { getSetting } from "../../constants/Settings";
|
|
6
|
-
import { ISO_DATE_FORMAT, ISO_DATETIME_FORMAT, ISO_TIME_FORMAT, ISO_TIMESTAMP_FORMAT, DEFAULT_WEEK_STARTS_ON, DEFAULT_FIRST_WEEK_CONTAINS_DATE } from "../../constants";
|
|
7
|
-
|
|
8
12
|
/**
|
|
9
13
|
* @hideconstructor
|
|
10
14
|
*/
|
|
11
15
|
class BaseDateTimeUtil {
|
|
12
16
|
constructor(isoFormat) {
|
|
13
17
|
_defineProperty(this, "_isoFormat", void 0);
|
|
18
|
+
_defineProperty(this, "_timeZone", typeof Intl === "undefined" ? "Etc/UTC" : Intl.DateTimeFormat().resolvedOptions().timeZone || "Etc/UTC");
|
|
14
19
|
this._isoFormat = isoFormat;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/**
|
|
23
|
+
* Returns the options defined in settings
|
|
18
24
|
*/
|
|
19
|
-
getLocale() {
|
|
20
|
-
const locale = getCookie("locale") ?? "en";
|
|
21
|
-
if (locale === "nl") {
|
|
22
|
-
return nl;
|
|
23
|
-
}
|
|
24
|
-
return enGB;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// returns the options defined in settings
|
|
28
25
|
getOptions() {
|
|
29
26
|
// indicates on what day the week starts
|
|
30
27
|
const weekStartsOn = getSetting("CALENDAR_WEEK_STARTS_ON", DEFAULT_WEEK_STARTS_ON);
|
|
@@ -37,15 +34,45 @@ class BaseDateTimeUtil {
|
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
|
|
37
|
+
/**
|
|
38
|
+
*/
|
|
39
|
+
getIsoFormat() {
|
|
40
|
+
var _context;
|
|
41
|
+
if (isIncludeTimeOffsetInDateTimes() && _startsWithInstanceProperty(_context = this._isoFormat).call(_context, ISO_DATETIME_FORMAT)) {
|
|
42
|
+
return this._isoFormat + DATETIME_OFFSET_FORMAT;
|
|
43
|
+
}
|
|
44
|
+
return this._isoFormat;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*/
|
|
49
|
+
convertFormat(sourceFormat) {
|
|
50
|
+
return sourceFormat ? sourceFormat : this.getIsoFormat();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*/
|
|
55
|
+
getLocale() {
|
|
56
|
+
const locale = getCookie("locale") ?? "en";
|
|
57
|
+
if (locale === "nl") {
|
|
58
|
+
return nl;
|
|
59
|
+
}
|
|
60
|
+
return enGB;
|
|
61
|
+
}
|
|
62
|
+
|
|
40
63
|
/**
|
|
41
64
|
*/
|
|
42
65
|
toDate(date) {
|
|
43
|
-
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.
|
|
66
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
67
|
+
if (date instanceof Date) {
|
|
68
|
+
return date;
|
|
69
|
+
}
|
|
44
70
|
const {
|
|
45
71
|
weekStartsOn,
|
|
46
72
|
firstWeekContainsDate
|
|
47
73
|
} = this.getOptions();
|
|
48
74
|
return parse(date, inputFormat, new Date(), {
|
|
75
|
+
in: this.getDateFnsContext(),
|
|
49
76
|
weekStartsOn,
|
|
50
77
|
firstWeekContainsDate
|
|
51
78
|
});
|
|
@@ -53,13 +80,15 @@ class BaseDateTimeUtil {
|
|
|
53
80
|
|
|
54
81
|
/**
|
|
55
82
|
*/
|
|
56
|
-
toFormat(
|
|
83
|
+
toFormat(isoDate, targetFormat) {
|
|
84
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
57
85
|
const {
|
|
58
86
|
weekStartsOn
|
|
59
87
|
} = this.getOptions();
|
|
60
|
-
const parsedDate =
|
|
88
|
+
const parsedDate = this.toDate(isoDate, inputFormat);
|
|
61
89
|
if (isValid(parsedDate)) {
|
|
62
90
|
return format(parsedDate, targetFormat, {
|
|
91
|
+
in: this.getDateFnsContext(),
|
|
63
92
|
weekStartsOn,
|
|
64
93
|
locale: this.getLocale()
|
|
65
94
|
});
|
|
@@ -70,17 +99,8 @@ class BaseDateTimeUtil {
|
|
|
70
99
|
/**
|
|
71
100
|
*/
|
|
72
101
|
toISO(date) {
|
|
73
|
-
let sourceFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.
|
|
74
|
-
|
|
75
|
-
weekStartsOn
|
|
76
|
-
} = this.getOptions();
|
|
77
|
-
const parsedDate = typeof date === "string" ? this.toDate(date, sourceFormat) : date;
|
|
78
|
-
if (isValid(parsedDate)) {
|
|
79
|
-
return format(parsedDate, this._isoFormat, {
|
|
80
|
-
weekStartsOn
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return "Invalid Date";
|
|
102
|
+
let sourceFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
103
|
+
return this.toFormat(date, this.getIsoFormat(), sourceFormat);
|
|
84
104
|
}
|
|
85
105
|
|
|
86
106
|
/**
|
|
@@ -89,86 +109,79 @@ class BaseDateTimeUtil {
|
|
|
89
109
|
return this.toISO(new Date());
|
|
90
110
|
}
|
|
91
111
|
|
|
92
|
-
|
|
93
|
-
*/
|
|
94
|
-
convertFormat(sourceFormat) {
|
|
95
|
-
return sourceFormat ? sourceFormat : this._isoFormat;
|
|
96
|
-
}
|
|
112
|
+
//////////// VALIDATION
|
|
97
113
|
|
|
98
114
|
/**
|
|
99
|
-
* VALIDATION
|
|
100
115
|
*/
|
|
101
116
|
hasFormat(date, sourceFormat) {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
const isOutsideRange = isBefore(realDate, new Date(1000, 1, 1)) || isAfter(realDate, new Date(9999, 11, 31));
|
|
111
|
-
if (isOutsideRange) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
return formattedValue.replace(/0/gu, "").toUpperCase() === date.replace(/0/gu, "").toUpperCase();
|
|
117
|
+
const formattedValue = this.toFormat(date, sourceFormat, sourceFormat);
|
|
118
|
+
if (formattedValue === "Invalid Date") {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const isOutsideRange = isBefore(formattedValue, new Date(1000, 1, 1)) || isAfter(formattedValue, new Date(9999, 11, 31));
|
|
122
|
+
if (isOutsideRange) {
|
|
123
|
+
return false;
|
|
115
124
|
}
|
|
116
|
-
return
|
|
125
|
+
return formattedValue.replace(/0/gu, "").toUpperCase() === date.replace(/0/gu, "").toUpperCase();
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
/**
|
|
120
129
|
*/
|
|
121
130
|
isValid(date) {
|
|
122
|
-
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.
|
|
123
|
-
|
|
131
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
132
|
+
if (!date) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
136
|
+
return isValid(parsedDate);
|
|
124
137
|
}
|
|
125
138
|
|
|
126
139
|
/**
|
|
127
140
|
*/
|
|
128
141
|
isAfter(inputDate, afterISODate) {
|
|
129
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
142
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
130
143
|
return afterISODate != null && isAfter(this.toDate(inputDate, inputFormat), this.toDate(afterISODate));
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
/**
|
|
134
147
|
*/
|
|
135
148
|
isSameOrAfter(inputDate, afterISODate) {
|
|
136
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
149
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
137
150
|
return afterISODate != null && (this.isAfter(inputDate, afterISODate, inputFormat) || this.isSame(inputDate, afterISODate, inputFormat));
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
/**
|
|
141
154
|
*/
|
|
142
155
|
isBefore(inputDate, beforeISODate) {
|
|
143
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
156
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
144
157
|
return beforeISODate != null && isBefore(this.toDate(inputDate, inputFormat), this.toDate(beforeISODate));
|
|
145
158
|
}
|
|
146
159
|
|
|
147
160
|
/**
|
|
148
161
|
*/
|
|
149
162
|
isSameOrBefore(inputDate, beforeISODate) {
|
|
150
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
163
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
151
164
|
return beforeISODate != null && (this.isBefore(inputDate, beforeISODate, inputFormat) || this.isSame(inputDate, beforeISODate, inputFormat));
|
|
152
165
|
}
|
|
153
166
|
|
|
154
167
|
/**
|
|
155
168
|
*/
|
|
156
169
|
isSame(inputDate, compareDate) {
|
|
157
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
170
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
158
171
|
return compareDate != null && this.toDate(inputDate, inputFormat).getTime() === this.toDate(compareDate).getTime();
|
|
159
172
|
}
|
|
160
173
|
|
|
161
174
|
/**
|
|
162
175
|
*/
|
|
163
176
|
isSameDay(inputDate, compareDate) {
|
|
164
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
177
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
165
178
|
return compareDate != null && isSameDay(this.toDate(inputDate, inputFormat), this.toDate(compareDate, inputFormat));
|
|
166
179
|
}
|
|
167
180
|
|
|
168
181
|
/**
|
|
169
182
|
*/
|
|
170
183
|
isOther(inputDate, compareDate) {
|
|
171
|
-
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.
|
|
184
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
172
185
|
return !this.isSame(inputDate, compareDate, inputFormat);
|
|
173
186
|
}
|
|
174
187
|
|
|
@@ -182,191 +195,376 @@ class BaseDateTimeUtil {
|
|
|
182
195
|
}
|
|
183
196
|
|
|
184
197
|
/**
|
|
185
|
-
*
|
|
198
|
+
* Checks if a given local date and time is ambiguous in the specified timezone.
|
|
199
|
+
* Ambiguity happens during the end of daylight saving time (DST) transitions.
|
|
200
|
+
*/
|
|
201
|
+
isAmbiguous(inputDate) {
|
|
202
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
203
|
+
if (inputDate == null || typeof Intl === "undefined") {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
const dateTime = this.toDate(inputDate, inputFormat);
|
|
207
|
+
if (!isValid(dateTime)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
const t = [60, -60, 30, -30];
|
|
211
|
+
const a = _mapInstanceProperty(t).call(t, x => {
|
|
212
|
+
const newDate = add(dateTime, {
|
|
213
|
+
minutes: x
|
|
214
|
+
});
|
|
215
|
+
return format(newDate, "HH:mm");
|
|
216
|
+
});
|
|
217
|
+
const time = format(dateTime, "HH:mm");
|
|
218
|
+
return a.indexOf(time) > -1;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
//////////// CALCULATIONS
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
226
|
+
_calculate(date, calculationFn, property, value) {
|
|
227
|
+
let inputFormat = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.getIsoFormat();
|
|
228
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
229
|
+
return this.toISO(calculationFn(parsedDate, {
|
|
230
|
+
[property]: value
|
|
231
|
+
}, {
|
|
232
|
+
in: this.getDateFnsContext()
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
186
237
|
*/
|
|
187
238
|
addSeconds(date, amount) {
|
|
188
|
-
|
|
239
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
240
|
+
return this._calculate(date, add, "seconds", amount, inputFormat);
|
|
189
241
|
}
|
|
190
242
|
|
|
191
243
|
/**
|
|
192
244
|
*/
|
|
193
245
|
addMinutes(date, amount) {
|
|
194
|
-
|
|
246
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
247
|
+
return this._calculate(date, add, "minutes", amount, inputFormat);
|
|
195
248
|
}
|
|
196
249
|
|
|
197
250
|
/**
|
|
198
251
|
*/
|
|
199
252
|
addHours(date, amount) {
|
|
200
|
-
|
|
253
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
254
|
+
return this._calculate(date, add, "hours", amount, inputFormat);
|
|
201
255
|
}
|
|
202
256
|
|
|
203
257
|
/**
|
|
204
258
|
*/
|
|
205
259
|
addDays(date, amount) {
|
|
206
|
-
|
|
260
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
261
|
+
return this._calculate(date, add, "days", amount, inputFormat);
|
|
207
262
|
}
|
|
208
263
|
|
|
209
264
|
/**
|
|
210
265
|
*/
|
|
211
266
|
addWeeks(date, amount) {
|
|
212
|
-
|
|
267
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
268
|
+
return this._calculate(date, add, "weeks", amount, inputFormat);
|
|
213
269
|
}
|
|
214
270
|
|
|
215
271
|
/**
|
|
216
272
|
*/
|
|
217
273
|
addMonths(date, amount) {
|
|
218
|
-
|
|
274
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
275
|
+
return this._calculate(date, add, "months", amount, inputFormat);
|
|
219
276
|
}
|
|
220
277
|
|
|
221
278
|
/**
|
|
222
279
|
*/
|
|
223
280
|
addYears(date, amount) {
|
|
224
|
-
|
|
281
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
282
|
+
return this._calculate(date, add, "years", amount, inputFormat);
|
|
225
283
|
}
|
|
226
284
|
|
|
227
285
|
/**
|
|
228
286
|
*/
|
|
229
287
|
subtractSeconds(date, amount) {
|
|
230
|
-
|
|
288
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
289
|
+
return this._calculate(date, sub, "seconds", amount, inputFormat);
|
|
231
290
|
}
|
|
232
291
|
|
|
233
292
|
/**
|
|
234
293
|
*/
|
|
235
294
|
subtractMinutes(date, amount) {
|
|
236
|
-
|
|
295
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
296
|
+
return this._calculate(date, sub, "minutes", amount, inputFormat);
|
|
237
297
|
}
|
|
238
298
|
|
|
239
299
|
/**
|
|
240
300
|
*/
|
|
241
301
|
subtractHours(date, amount) {
|
|
242
|
-
|
|
302
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
303
|
+
return this._calculate(date, sub, "hours", amount, inputFormat);
|
|
243
304
|
}
|
|
244
305
|
|
|
245
306
|
/**
|
|
246
307
|
*/
|
|
247
308
|
subtractDays(date, amount) {
|
|
248
|
-
|
|
309
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
310
|
+
return this._calculate(date, sub, "days", amount, inputFormat);
|
|
249
311
|
}
|
|
250
312
|
|
|
251
313
|
/**
|
|
252
314
|
*/
|
|
253
315
|
subtractWeeks(date, amount) {
|
|
254
|
-
|
|
316
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
317
|
+
return this._calculate(date, sub, "weeks", amount, inputFormat);
|
|
255
318
|
}
|
|
256
319
|
|
|
257
320
|
/**
|
|
258
321
|
*/
|
|
259
322
|
subtractMonths(date, amount) {
|
|
260
|
-
|
|
323
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
324
|
+
return this._calculate(date, sub, "months", amount, inputFormat);
|
|
261
325
|
}
|
|
262
326
|
|
|
263
327
|
/**
|
|
264
328
|
*/
|
|
265
329
|
subtractYears(date, amount) {
|
|
266
|
-
|
|
330
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
331
|
+
return this._calculate(date, sub, "years", amount, inputFormat);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
//////////// GETTERS
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @private
|
|
338
|
+
*/
|
|
339
|
+
_get(date, method) {
|
|
340
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
341
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
342
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
343
|
+
return this.toISO(method(parsedDate, {
|
|
344
|
+
in: this.getDateFnsContext(),
|
|
345
|
+
...options
|
|
346
|
+
}));
|
|
267
347
|
}
|
|
268
348
|
|
|
269
349
|
/**
|
|
270
|
-
* GETTERS
|
|
271
350
|
*/
|
|
272
351
|
startOfMonth(date) {
|
|
273
|
-
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.
|
|
274
|
-
return this.
|
|
352
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
353
|
+
return this._get(date, startOfMonth, inputFormat);
|
|
275
354
|
}
|
|
276
355
|
|
|
277
356
|
/**
|
|
278
357
|
*/
|
|
279
358
|
endOfMonth(date) {
|
|
280
|
-
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.
|
|
281
|
-
return this.
|
|
359
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
360
|
+
return this._get(date, endOfMonth, inputFormat);
|
|
282
361
|
}
|
|
283
362
|
|
|
284
363
|
/**
|
|
285
364
|
*/
|
|
286
365
|
startOfWeek(date) {
|
|
287
|
-
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.
|
|
366
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
288
367
|
const {
|
|
289
368
|
weekStartsOn
|
|
290
369
|
} = this.getOptions();
|
|
291
|
-
return this.
|
|
370
|
+
return this._get(date, startOfWeek, inputFormat, {
|
|
292
371
|
weekStartsOn
|
|
293
|
-
})
|
|
372
|
+
});
|
|
294
373
|
}
|
|
295
374
|
|
|
296
375
|
/**
|
|
297
376
|
*/
|
|
298
377
|
getHours(date) {
|
|
299
|
-
|
|
300
|
-
|
|
378
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
379
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
380
|
+
return getHours(parsedDate, {
|
|
381
|
+
in: this.getDateFnsContext()
|
|
382
|
+
});
|
|
301
383
|
}
|
|
302
384
|
|
|
303
385
|
/**
|
|
304
386
|
*/
|
|
305
387
|
getMinutes(date) {
|
|
306
|
-
|
|
307
|
-
|
|
388
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
389
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
390
|
+
return getMinutes(parsedDate, {
|
|
391
|
+
in: this.getDateFnsContext()
|
|
392
|
+
});
|
|
308
393
|
}
|
|
309
394
|
|
|
310
395
|
/**
|
|
311
396
|
*/
|
|
312
397
|
getWeek(date) {
|
|
398
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
313
399
|
const {
|
|
314
400
|
weekStartsOn,
|
|
315
401
|
firstWeekContainsDate
|
|
316
402
|
} = this.getOptions();
|
|
317
|
-
|
|
403
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
404
|
+
return getWeek(parsedDate, {
|
|
405
|
+
in: this.getDateFnsContext(),
|
|
318
406
|
weekStartsOn,
|
|
319
407
|
firstWeekContainsDate
|
|
320
408
|
});
|
|
321
409
|
}
|
|
322
410
|
|
|
411
|
+
//////////// SETTERS
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @private
|
|
415
|
+
*/
|
|
416
|
+
_set(date, property, value) {
|
|
417
|
+
let inputFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : this.getIsoFormat();
|
|
418
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
419
|
+
return this.toISO(set(parsedDate, {
|
|
420
|
+
[property]: value
|
|
421
|
+
}
|
|
422
|
+
// {
|
|
423
|
+
// in: this.getDateFnsContext(),
|
|
424
|
+
// },
|
|
425
|
+
));
|
|
426
|
+
}
|
|
427
|
+
|
|
323
428
|
/**
|
|
324
|
-
* SETTERS
|
|
325
429
|
*/
|
|
326
430
|
setYear(date, year) {
|
|
327
|
-
|
|
431
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
432
|
+
return this._set(date, "year", year, inputFormat);
|
|
328
433
|
}
|
|
329
434
|
|
|
330
435
|
/**
|
|
331
436
|
*/
|
|
332
437
|
setMonth(date, month) {
|
|
333
|
-
|
|
438
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
439
|
+
return this._set(date, "month", month, inputFormat);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
*/
|
|
444
|
+
setDay(date, day) {
|
|
445
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
446
|
+
return this._set(date, "date", day, inputFormat);
|
|
334
447
|
}
|
|
335
448
|
|
|
336
449
|
/**
|
|
337
450
|
*/
|
|
338
451
|
setHour(date, hour) {
|
|
339
|
-
|
|
452
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
453
|
+
return this._set(date, "hours", hour, inputFormat);
|
|
340
454
|
}
|
|
341
455
|
|
|
342
456
|
/**
|
|
343
457
|
*/
|
|
344
458
|
setMinute(date, minute) {
|
|
345
|
-
|
|
459
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
460
|
+
return this._set(date, "minutes", minute, inputFormat);
|
|
346
461
|
}
|
|
347
462
|
|
|
348
463
|
/**
|
|
349
464
|
*/
|
|
350
465
|
setSecond(date, second) {
|
|
351
|
-
|
|
466
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
467
|
+
return this._set(date, "seconds", second, inputFormat);
|
|
352
468
|
}
|
|
353
469
|
|
|
354
470
|
/**
|
|
355
471
|
*/
|
|
356
|
-
setMilliseconds(date,
|
|
357
|
-
|
|
472
|
+
setMilliseconds(date, millisecond) {
|
|
473
|
+
let inputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getIsoFormat();
|
|
474
|
+
return this._set(date, "milliseconds", millisecond, inputFormat);
|
|
358
475
|
}
|
|
359
476
|
|
|
360
477
|
/**
|
|
361
478
|
*/
|
|
362
479
|
setTime(date, hours, minutes, seconds, milliseconds) {
|
|
363
|
-
|
|
480
|
+
let inputFormat = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : this.getIsoFormat();
|
|
481
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
482
|
+
return this.toISO(set(parsedDate, {
|
|
364
483
|
hours,
|
|
365
484
|
minutes,
|
|
366
485
|
seconds,
|
|
367
486
|
milliseconds
|
|
487
|
+
}, {
|
|
488
|
+
in: this.getDateFnsContext()
|
|
368
489
|
}));
|
|
369
490
|
}
|
|
491
|
+
|
|
492
|
+
//////////// Timezone related
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
*/
|
|
496
|
+
getTimeZone() {
|
|
497
|
+
return this._timeZone;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
*/
|
|
502
|
+
setTimeZone(timeZone) {
|
|
503
|
+
this._timeZone = timeZone;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
*/
|
|
508
|
+
getDateFnsContext() {
|
|
509
|
+
if (IS_GRAALJS) {
|
|
510
|
+
return null; // tz method does not work in graal (yet)
|
|
511
|
+
}
|
|
512
|
+
return tz(this.getTimeZone());
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
//////////// Offsets
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
*/
|
|
519
|
+
getOffset(date) {
|
|
520
|
+
let inputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getIsoFormat();
|
|
521
|
+
const parsedDate = this.toDate(date, inputFormat);
|
|
522
|
+
if (isValid(parsedDate)) {
|
|
523
|
+
const dateOffset = this.toFormat(parsedDate, DATETIME_OFFSET_FORMAT);
|
|
524
|
+
const offsets = this.getTimezoneOffsets();
|
|
525
|
+
if (typeof offsets.daylight !== "undefined" && offsets.daylight.value === dateOffset) {
|
|
526
|
+
return offsets.daylight;
|
|
527
|
+
} else if (typeof offsets.standard !== "undefined" && offsets.standard.value === dateOffset) {
|
|
528
|
+
return offsets.standard;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
*/
|
|
536
|
+
getTimezoneOffsets() {
|
|
537
|
+
const createOffsetObject = info => {
|
|
538
|
+
var _context2, _context3;
|
|
539
|
+
const sign = info.offset < 0 ? "-" : "+";
|
|
540
|
+
const absOffset = Math.abs(info.offset);
|
|
541
|
+
const hours = _Math$trunc(absOffset);
|
|
542
|
+
const minutes = Math.round(absOffset % 1 * 60);
|
|
543
|
+
const offsetString = `${sign}${_padStartInstanceProperty(_context2 = String(hours + (minutes === 60 ? 1 : 0))).call(_context2, 2, "0")}:${_padStartInstanceProperty(_context3 = String(minutes % 60)).call(_context3, 2, "0")}`;
|
|
544
|
+
return {
|
|
545
|
+
label: info.name,
|
|
546
|
+
abbr: info.abbr,
|
|
547
|
+
value: offsetString
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
const timezone = soft(this.getTimeZone());
|
|
551
|
+
if (timezone.length === 0) {
|
|
552
|
+
return {};
|
|
553
|
+
}
|
|
554
|
+
const {
|
|
555
|
+
daylight,
|
|
556
|
+
standard
|
|
557
|
+
} = timezone[0];
|
|
558
|
+
if (daylight) {
|
|
559
|
+
return {
|
|
560
|
+
daylight: createOffsetObject(daylight),
|
|
561
|
+
standard: createOffsetObject(standard)
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
standard: createOffsetObject(standard)
|
|
566
|
+
};
|
|
567
|
+
}
|
|
370
568
|
}
|
|
371
569
|
|
|
372
570
|
/**
|