@beinformed/ui 1.58.4 → 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.
Files changed (60) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/esm/constants/Constants.js +10 -0
  3. package/esm/constants/Constants.js.map +1 -1
  4. package/esm/constants/Settings.js +5 -1
  5. package/esm/constants/Settings.js.map +1 -1
  6. package/esm/models/attributes/DatetimeAttributeModel.js +39 -4
  7. package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
  8. package/esm/models/attributes/input-constraints/DatetimeFormatConstraint.js +31 -2
  9. package/esm/models/attributes/input-constraints/DatetimeFormatConstraint.js.map +1 -1
  10. package/esm/react-client/client.js +2 -1
  11. package/esm/react-client/client.js.map +1 -1
  12. package/esm/react-server/serverUtil.js +2 -1
  13. package/esm/react-server/serverUtil.js.map +1 -1
  14. package/esm/redux/actions/Preferences.js +15 -1
  15. package/esm/redux/actions/Preferences.js.map +1 -1
  16. package/esm/utils/datetime/DateTimeUtil.js +292 -94
  17. package/esm/utils/datetime/DateTimeUtil.js.map +1 -1
  18. package/lib/constants/Constants.js +11 -1
  19. package/lib/constants/Constants.js.flow +11 -0
  20. package/lib/constants/Constants.js.map +1 -1
  21. package/lib/constants/Settings.js +7 -2
  22. package/lib/constants/Settings.js.flow +6 -0
  23. package/lib/constants/Settings.js.map +1 -1
  24. package/lib/models/attributes/DatetimeAttributeModel.js +38 -3
  25. package/lib/models/attributes/DatetimeAttributeModel.js.flow +54 -4
  26. package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
  27. package/lib/models/attributes/__tests__/DatetimeAttributeModel.spec.js.flow +9 -0
  28. package/lib/models/attributes/__tests__/DatetimeAttributeModel_offset.spec.js.flow +306 -0
  29. package/lib/models/attributes/input-constraints/DatetimeFormatConstraint.js +31 -2
  30. package/lib/models/attributes/input-constraints/DatetimeFormatConstraint.js.flow +42 -3
  31. package/lib/models/attributes/input-constraints/DatetimeFormatConstraint.js.map +1 -1
  32. package/lib/react-client/client.js +1 -0
  33. package/lib/react-client/client.js.flow +2 -0
  34. package/lib/react-client/client.js.map +1 -1
  35. package/lib/react-server/__tests__/serverUtil.spec.js.flow +12 -0
  36. package/lib/react-server/serverUtil.js +1 -0
  37. package/lib/react-server/serverUtil.js.flow +2 -0
  38. package/lib/react-server/serverUtil.js.map +1 -1
  39. package/lib/redux/actions/Preferences.js +17 -2
  40. package/lib/redux/actions/Preferences.js.flow +22 -0
  41. package/lib/redux/actions/Preferences.js.map +1 -1
  42. package/lib/redux/reducers/__tests__/ModelCatalogReducer.spec.js.flow +23 -0
  43. package/lib/utils/datetime/DateTimeUtil.js +292 -93
  44. package/lib/utils/datetime/DateTimeUtil.js.flow +482 -172
  45. package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
  46. package/lib/utils/datetime/__tests__/DateTime.spec.js.flow +771 -483
  47. package/package.json +11 -9
  48. package/src/constants/Constants.js +11 -0
  49. package/src/constants/Settings.js +6 -0
  50. package/src/models/attributes/DatetimeAttributeModel.js +54 -4
  51. package/src/models/attributes/__tests__/DatetimeAttributeModel.spec.js +9 -0
  52. package/src/models/attributes/__tests__/DatetimeAttributeModel_offset.spec.js +306 -0
  53. package/src/models/attributes/input-constraints/DatetimeFormatConstraint.js +42 -3
  54. package/src/react-client/client.js +2 -0
  55. package/src/react-server/__tests__/serverUtil.spec.js +12 -0
  56. package/src/react-server/serverUtil.js +2 -0
  57. package/src/redux/actions/Preferences.js +22 -0
  58. package/src/redux/reducers/__tests__/ModelCatalogReducer.spec.js +23 -0
  59. package/src/utils/datetime/DateTimeUtil.js +482 -172
  60. package/src/utils/datetime/__tests__/DateTime.spec.js +771 -483
@@ -5,10 +5,12 @@ import {
5
5
  TimestampUtil,
6
6
  } from "../DateTimeUtil";
7
7
  import {
8
+ INCLUDE_TIME_OFFSET,
8
9
  ISO_DATE_FORMAT,
9
10
  ISO_DATETIME_FORMAT,
10
11
  ISO_TIME_FORMAT,
11
12
  ISO_TIMESTAMP_FORMAT,
13
+ DATETIME_OFFSET_FORMAT,
12
14
  } from "../../../constants";
13
15
 
14
16
  import { setSettings } from "../../../constants/Settings";
@@ -16,10 +18,10 @@ import { setSettings } from "../../../constants/Settings";
16
18
  const DUTCH_DATE_FORMAT = "dd-MM-yyyy";
17
19
  const DUTCH_DATETIME_FORMAT = "dd-MM-yyyy HH:mm";
18
20
 
19
- const DUTCH_DATE = "13-06-2017";
20
- const DUTCH_DATETIME = "13-06-2017 14:15";
21
+ const INPUT_13_06_2017 = "13-06-2017";
22
+ const INPUT_13_06_2017_14_15 = "13-06-2017 14:15";
21
23
 
22
- const ISO_DATE = "2017-06-13";
24
+ const ISO_2017_06_13 = "2017-06-13";
23
25
 
24
26
  const INVALID_DATE = "Invalid Date";
25
27
 
@@ -31,548 +33,834 @@ const ISO_1979_12_31 = "1979-12-31";
31
33
  const ISO_1980_01_15 = "1980-01-15";
32
34
 
33
35
  const ISO_1980_10_18T13_20_00 = "1980-10-18T13:20:00";
36
+ const ISO_1980_01_01T13_20_00 = "1980-01-01T13:20:00";
37
+
38
+ const ISO_1980_10_18T13_20_00_OFFSET = "1980-10-18T13:20:00+02:00"; // CEST
39
+ const ISO_1980_01_01T13_20_00_OFFSET = "1980-01-01T13:20:00+01:00"; // CET
40
+
34
41
  const ISO_1980_10_18T13_20_00_000 = "1980-10-18T13:20:00.000";
35
42
  const ISO_1980_10_18T13_19_00_000 = "1980-10-18T13:19:00.000";
36
43
  const ISO_1980_10_18T13_21_00_000 = "1980-10-18T13:21:00.000";
37
44
  const ISO_1980_01_01T13_20_00_000 = "1980-01-01T13:20:00.000";
38
45
 
39
- describe("dateTimeUtil", () => {
40
- it("should convert java date time format to moment date time format", () => {
41
- expect(DateUtil.convertFormat()).toBe(ISO_DATE_FORMAT);
42
- expect(DateTimeUtil.convertFormat()).toBe(ISO_DATETIME_FORMAT);
43
- expect(TimeUtil.convertFormat()).toBe(ISO_TIME_FORMAT);
44
- expect(TimestampUtil.convertFormat()).toBe(ISO_TIMESTAMP_FORMAT);
45
-
46
- expect(DateUtil.convertFormat("yyyy-MM-dd")).toBe("yyyy-MM-dd");
47
- expect(DateTimeUtil.convertFormat("yyyy-MM-dd HH:mm:ss")).toBe(
48
- "yyyy-MM-dd HH:mm:ss",
49
- );
50
- expect(TimeUtil.convertFormat("HH:mm:ss")).toBe("HH:mm:ss");
51
- expect(TimestampUtil.convertFormat("yyyy-MM-dd HH:mm:ss.SSS")).toBe(
52
- "yyyy-MM-dd HH:mm:ss.SSS",
53
- );
54
- });
46
+ describe("asserts for date/time utilities", () => {
47
+ beforeEach(() => {
48
+ DateUtil.setTimeZone("Europe/Amsterdam");
49
+ DateTimeUtil.setTimeZone("Europe/Amsterdam");
50
+ TimeUtil.setTimeZone("Europe/Amsterdam");
51
+ TimestampUtil.setTimeZone("Europe/Amsterdam");
55
52
 
56
- it("should render iso date to specified format", () => {
57
- expect(DateUtil.toFormat(ISO_DATE, DUTCH_DATE_FORMAT)).toBe(DUTCH_DATE);
58
- expect(DateUtil.toFormat(ISO_DATE, "MM-dd-yyyy")).toBe("06-13-2017");
53
+ setSettings({ [INCLUDE_TIME_OFFSET]: false });
59
54
  });
60
55
 
61
- it("should render specified format to iso date", () => {
62
- expect(DateUtil.toISO(DUTCH_DATE, DUTCH_DATE_FORMAT)).toBe(ISO_DATE);
63
- expect(DateUtil.toISO("06-13-2017", "MM-dd-yyyy")).toBe(ISO_DATE);
64
- });
56
+ describe("test DateUtil", () => {
57
+ it("should convert java date time format to date-fns date time format", () => {
58
+ expect(DateUtil.convertFormat()).toBe(ISO_DATE_FORMAT);
59
+ expect(DateUtil.convertFormat("yyyy-MM-dd")).toBe("yyyy-MM-dd");
60
+ });
65
61
 
66
- it("should render iso datetime to specified format", () => {
67
- expect(
68
- DateTimeUtil.toFormat("2017-06-13T14:15:12", DUTCH_DATETIME_FORMAT),
69
- ).toBe(DUTCH_DATETIME);
70
- expect(DateTimeUtil.toFormat("2017-06-13T14:15:12", "h:mm")).toBe("2:15");
71
- expect(
72
- DateTimeUtil.toFormat("2017-06-13T23:15:12", DUTCH_DATE_FORMAT),
73
- ).toBe(DUTCH_DATE);
74
- });
62
+ it("should render iso date to specified format", () => {
63
+ expect(DateUtil.toFormat(ISO_2017_06_13, DUTCH_DATE_FORMAT)).toBe(
64
+ INPUT_13_06_2017,
65
+ );
66
+ expect(DateUtil.toFormat(ISO_2017_06_13, "MM-dd-yyyy")).toBe(
67
+ "06-13-2017",
68
+ );
69
+ });
75
70
 
76
- it("should render specified format to iso datetime", () => {
77
- expect(DateTimeUtil.toISO(DUTCH_DATETIME, DUTCH_DATETIME_FORMAT)).toBe(
78
- "2017-06-13T14:15:00",
79
- );
80
- expect(DateTimeUtil.toISO("13-06-2017 2:15", "dd-MM-yyyy h:mm")).toBe(
81
- "2017-06-13T02:15:00",
82
- );
83
- expect(DateTimeUtil.toISO(DUTCH_DATE, DUTCH_DATE_FORMAT)).toBe(
84
- "2017-06-13T00:00:00",
85
- );
86
- });
71
+ it("should render specified format to iso date", () => {
72
+ expect(DateUtil.toISO(INPUT_13_06_2017, DUTCH_DATE_FORMAT)).toBe(
73
+ ISO_2017_06_13,
74
+ );
75
+ expect(DateUtil.toISO("06-13-2017", "MM-dd-yyyy")).toBe(ISO_2017_06_13);
76
+ });
87
77
 
88
- it("should render iso time to specified format", () => {
89
- expect(TimeUtil.toFormat("14:15:12", "HH:mm")).toBe("14:15");
90
- expect(TimeUtil.toFormat("14:15:12", "h:mm")).toBe("2:15");
91
- expect(TimeUtil.toFormat("23:15:12", "h:mm")).toBe("11:15");
92
- });
78
+ it("should return invalid date when date entered is not a date", () => {
79
+ expect(DateUtil.toISO("bla", DUTCH_DATE_FORMAT)).toBe(INVALID_DATE);
80
+ });
93
81
 
94
- it("should render specified format to iso time", () => {
95
- expect(TimeUtil.toISO("14:15", "HH:mm")).toBe("14:15:00");
96
- expect(TimeUtil.toISO("2:15 AM", "h:mm aa")).toBe("02:15:00");
97
- expect(TimeUtil.toISO("02:15 PM", "hh:mm aa")).toBe("14:15:00");
98
- expect(TimeUtil.toISO("11:15 AM", "h:mm aa")).toBe("11:15:00");
99
- });
82
+ describe("asserts", () => {
83
+ it("hasFormat", () => {
84
+ expect(DateUtil.hasFormat("18-10-1980", DUTCH_DATE_FORMAT)).toBe(true);
85
+ expect(DateUtil.hasFormat("18-1-1980", DUTCH_DATE_FORMAT)).toBe(true);
86
+ expect(DateUtil.hasFormat("18-1980", DUTCH_DATE_FORMAT)).toBe(false);
87
+ });
100
88
 
101
- it("should render iso timestamp to specified format", () => {
102
- expect(
103
- TimestampUtil.toFormat("2017-06-13T14:15:12.000", DUTCH_DATETIME_FORMAT),
104
- ).toBe(DUTCH_DATETIME);
105
- expect(TimestampUtil.toFormat("2017-06-13T14:15:12.000", "h:mm")).toBe(
106
- "2:15",
107
- );
108
- expect(
109
- TimestampUtil.toFormat("2017-06-13T23:15:12.000", DUTCH_DATE_FORMAT),
110
- ).toBe(DUTCH_DATE);
111
- });
89
+ it("isValid", () => {
90
+ expect(DateUtil.isValid("18-10-1980", DUTCH_DATE_FORMAT)).toBe(true);
91
+ expect(DateUtil.isValid("bla", DUTCH_DATE_FORMAT)).toBe(false);
92
+ });
112
93
 
113
- it("should render specified format to iso timestamp", () => {
114
- expect(TimestampUtil.toISO(DUTCH_DATETIME, DUTCH_DATETIME_FORMAT)).toBe(
115
- "2017-06-13T14:15:00.000",
116
- );
117
- expect(TimestampUtil.toISO("13-06-2017 2:15", "dd-MM-yyyy h:mm")).toBe(
118
- "2017-06-13T02:15:00.000",
119
- );
120
- expect(TimestampUtil.toISO(DUTCH_DATE, DUTCH_DATE_FORMAT)).toBe(
121
- "2017-06-13T00:00:00.000",
122
- );
123
- });
94
+ it("isAfter", () => {
95
+ expect(DateUtil.isAfter(ISO_1980_10_18, ISO_1980_10_17)).toBe(true);
96
+ expect(DateUtil.isAfter(ISO_1980_10_18, ISO_1980_10_18)).toBe(false);
97
+ expect(DateUtil.isAfter(ISO_1980_10_18, ISO_1980_10_19)).toBe(false);
98
+ });
124
99
 
125
- it("should return invalid date when date entered is not a date", () => {
126
- expect(DateUtil.toISO("bla", DUTCH_DATE_FORMAT)).toBe(INVALID_DATE);
127
- expect(DateTimeUtil.toISO("bla", DUTCH_DATETIME_FORMAT)).toBe(INVALID_DATE);
128
- expect(TimeUtil.toISO("bla", "HH:mm")).toBe(INVALID_DATE);
129
- expect(TimestampUtil.toISO("bla", DUTCH_DATETIME_FORMAT)).toBe(
130
- INVALID_DATE,
131
- );
132
- });
100
+ it("isSameOrAfter", () => {
101
+ expect(DateUtil.isSameOrAfter(ISO_1980_10_18, ISO_1980_10_17)).toBe(
102
+ true,
103
+ );
104
+ expect(DateUtil.isSameOrAfter(ISO_1980_10_18, ISO_1980_10_18)).toBe(
105
+ true,
106
+ );
107
+ expect(DateUtil.isSameOrAfter(ISO_1980_10_18, ISO_1980_10_19)).toBe(
108
+ false,
109
+ );
110
+ });
133
111
 
134
- it("hasFormat", () => {
135
- expect(DateUtil.hasFormat("18-10-1980", DUTCH_DATE_FORMAT)).toBe(true);
136
- expect(DateUtil.hasFormat("18-1-1980", DUTCH_DATE_FORMAT)).toBe(true);
137
- expect(DateUtil.hasFormat("18-1980", DUTCH_DATE_FORMAT)).toBe(false);
138
- });
112
+ it("isBefore", () => {
113
+ expect(DateUtil.isBefore(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
114
+ expect(DateUtil.isBefore(ISO_1980_10_18, ISO_1980_10_18)).toBe(false);
115
+ expect(DateUtil.isBefore(ISO_1980_10_18, ISO_1980_10_19)).toBe(true);
116
+ });
139
117
 
140
- it("isValid", () => {
141
- expect(DateUtil.isValid("18-10-1980", DUTCH_DATE_FORMAT)).toBe(true);
142
- expect(
143
- DateTimeUtil.isValid("18-10-1980 13:20", DUTCH_DATETIME_FORMAT),
144
- ).toBe(true);
145
- expect(TimeUtil.isValid("13:20", "HH:mm")).toBe(true);
146
- expect(
147
- TimestampUtil.isValid("18-10-1980 13:20", DUTCH_DATETIME_FORMAT),
148
- ).toBe(true);
149
-
150
- expect(DateUtil.isValid("bla", DUTCH_DATE_FORMAT)).toBe(false);
151
- expect(DateTimeUtil.isValid("bla", DUTCH_DATETIME_FORMAT)).toBe(false);
152
- expect(TimeUtil.isValid("bla", "HH:mm")).toBe(false);
153
- expect(TimestampUtil.isValid("bla", DUTCH_DATETIME_FORMAT)).toBe(false);
154
- });
118
+ it("isSameOrBefore", () => {
119
+ expect(DateUtil.isSameOrBefore(ISO_1980_10_18, ISO_1980_10_17)).toBe(
120
+ false,
121
+ );
122
+ expect(DateUtil.isSameOrBefore(ISO_1980_10_18, ISO_1980_10_18)).toBe(
123
+ true,
124
+ );
125
+ expect(DateUtil.isSameOrBefore(ISO_1980_10_18, ISO_1980_10_19)).toBe(
126
+ true,
127
+ );
128
+ });
155
129
 
156
- it("isAfter", () => {
157
- expect(DateUtil.isAfter(ISO_1980_10_18, ISO_1980_10_17)).toBe(true);
158
- expect(
159
- DateTimeUtil.isAfter(ISO_1980_10_18T13_20_00, "1980-10-18T13:19:00"),
160
- ).toBe(true);
161
- expect(TimeUtil.isAfter("13:20:00", "13:19:00")).toBe(true);
162
- expect(
163
- TimestampUtil.isAfter(
164
- ISO_1980_10_18T13_20_00_000,
165
- ISO_1980_10_18T13_19_00_000,
166
- ),
167
- ).toBe(true);
168
-
169
- expect(DateUtil.isAfter(ISO_1980_10_18, ISO_1980_10_18)).toBe(false);
170
- expect(
171
- DateTimeUtil.isAfter(ISO_1980_10_18T13_20_00, ISO_1980_10_18T13_20_00),
172
- ).toBe(false);
173
- expect(TimeUtil.isAfter("13:20:00", "13:20:00")).toBe(false);
174
- expect(
175
- TimestampUtil.isAfter(
176
- ISO_1980_10_18T13_20_00_000,
177
- ISO_1980_10_18T13_20_00_000,
178
- ),
179
- ).toBe(false);
180
-
181
- expect(DateUtil.isAfter(ISO_1980_10_18, ISO_1980_10_19)).toBe(false);
182
- expect(
183
- DateTimeUtil.isAfter(ISO_1980_10_18T13_20_00, "1980-10-18T13:21:00"),
184
- ).toBe(false);
185
- expect(TimeUtil.isAfter("13:20:00", "13:21:00")).toBe(false);
186
- expect(
187
- TimestampUtil.isAfter(
188
- ISO_1980_10_18T13_20_00_000,
189
- ISO_1980_10_18T13_21_00_000,
190
- ),
191
- ).toBe(false);
192
- });
130
+ it("isSame", () => {
131
+ expect(DateUtil.isSame(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
132
+ expect(DateUtil.isSame(ISO_1980_10_18, ISO_1980_10_18)).toBe(true);
133
+ expect(DateUtil.isSame(ISO_1980_10_18, ISO_1980_10_19)).toBe(false);
134
+ });
193
135
 
194
- it("isSameOrAfter", () => {
195
- expect(DateUtil.isSameOrAfter(ISO_1980_10_18, ISO_1980_10_17)).toBe(true);
196
- expect(
197
- DateTimeUtil.isSameOrAfter(
198
- ISO_1980_10_18T13_20_00,
199
- "1980-10-18T13:19:00",
200
- ),
201
- ).toBe(true);
202
- expect(TimeUtil.isSameOrAfter("13:20:00", "13:19:00")).toBe(true);
203
- expect(
204
- TimestampUtil.isSameOrAfter(
205
- ISO_1980_10_18T13_20_00_000,
206
- ISO_1980_10_18T13_19_00_000,
207
- ),
208
- ).toBe(true);
209
-
210
- expect(DateUtil.isSameOrAfter(ISO_1980_10_18, ISO_1980_10_18)).toBe(true);
211
- expect(
212
- DateTimeUtil.isSameOrAfter(
213
- ISO_1980_10_18T13_20_00,
214
- ISO_1980_10_18T13_20_00,
215
- ),
216
- ).toBe(true);
217
- expect(TimeUtil.isSameOrAfter("13:20:00", "13:20:00")).toBe(true);
218
- expect(
219
- TimestampUtil.isSameOrAfter(
220
- ISO_1980_10_18T13_20_00_000,
221
- ISO_1980_10_18T13_20_00_000,
222
- ),
223
- ).toBe(true);
224
-
225
- expect(DateUtil.isSameOrAfter(ISO_1980_10_18, ISO_1980_10_19)).toBe(false);
226
- expect(TimeUtil.isSameOrAfter("13:20:00", "13:21:00")).toBe(false);
227
- expect(
228
- TimestampUtil.isSameOrAfter(
229
- ISO_1980_10_18T13_20_00_000,
230
- ISO_1980_10_18T13_21_00_000,
231
- ),
232
- ).toBe(false);
233
- });
136
+ it("isSameDay", () => {
137
+ expect(DateUtil.isSameDay(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
138
+ expect(DateUtil.isSameDay(ISO_1980_10_18, ISO_1980_10_18)).toBe(true);
139
+ });
234
140
 
235
- it("isBefore", () => {
236
- expect(DateUtil.isBefore(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
237
- expect(TimeUtil.isBefore("13:20:00", "13:19:00")).toBe(false);
238
- expect(
239
- TimestampUtil.isBefore(
240
- ISO_1980_10_18T13_20_00_000,
241
- ISO_1980_10_18T13_19_00_000,
242
- ),
243
- ).toBe(false);
244
-
245
- expect(DateUtil.isBefore(ISO_1980_10_18, ISO_1980_10_18)).toBe(false);
246
- expect(TimeUtil.isBefore("13:20:00", "13:20:00")).toBe(false);
247
- expect(
248
- TimestampUtil.isBefore(
249
- ISO_1980_10_18T13_20_00_000,
250
- ISO_1980_10_18T13_20_00_000,
251
- ),
252
- ).toBe(false);
253
-
254
- expect(DateUtil.isBefore(ISO_1980_10_18, ISO_1980_10_19)).toBe(true);
255
- expect(TimeUtil.isBefore("13:20:00", "13:21:00")).toBe(true);
256
- expect(
257
- TimestampUtil.isBefore(
258
- ISO_1980_10_18T13_20_00_000,
259
- ISO_1980_10_18T13_21_00_000,
260
- ),
261
- ).toBe(true);
262
- });
141
+ it("isOther", () => {
142
+ expect(DateUtil.isOther(ISO_1980_10_18, ISO_1980_10_17)).toBe(true);
143
+ expect(DateUtil.isOther(ISO_1980_10_18, ISO_1980_10_18)).toBe(false);
144
+ expect(DateUtil.isOther(ISO_1980_10_18, ISO_1980_10_19)).toBe(true);
145
+ });
263
146
 
264
- it("isSameOrBefore", () => {
265
- expect(DateUtil.isSameOrBefore(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
266
- expect(TimeUtil.isSameOrBefore("13:20:00", "13:19:00")).toBe(false);
267
- expect(
268
- TimestampUtil.isSameOrBefore(
269
- ISO_1980_10_18T13_20_00_000,
270
- ISO_1980_10_18T13_19_00_000,
271
- ),
272
- ).toBe(false);
273
-
274
- expect(DateUtil.isSameOrBefore(ISO_1980_10_18, ISO_1980_10_18)).toBe(true);
275
- expect(TimeUtil.isSameOrBefore("13:20:00", "13:20:00")).toBe(true);
276
- expect(
277
- TimestampUtil.isSameOrBefore(
278
- ISO_1980_10_18T13_20_00_000,
279
- ISO_1980_10_18T13_20_00_000,
280
- ),
281
- ).toBe(true);
282
-
283
- expect(DateUtil.isSameOrBefore(ISO_1980_10_18, ISO_1980_10_19)).toBe(true);
284
- expect(TimeUtil.isSameOrBefore("13:20:00", "13:21:00")).toBe(true);
285
- expect(
286
- TimestampUtil.isSameOrBefore(
287
- ISO_1980_10_18T13_20_00_000,
288
- ISO_1980_10_18T13_21_00_000,
289
- ),
290
- ).toBe(true);
291
- });
147
+ it("isWeekend", () => {
148
+ expect(DateUtil.isWeekend("2018-12-14")).toBe(false);
149
+ expect(DateUtil.isWeekend("2018-12-15")).toBe(true);
150
+ expect(DateUtil.isWeekend("2018-12-16")).toBe(true);
151
+ expect(DateUtil.isWeekend("2018-12-17")).toBe(false);
152
+ expect(DateUtil.isWeekend("2018-12-18")).toBe(false);
153
+ expect(DateUtil.isWeekend("2018-12-19")).toBe(false);
154
+ expect(DateUtil.isWeekend("2018-12-20")).toBe(false);
155
+ });
156
+ });
292
157
 
293
- it("isSame", () => {
294
- expect(DateUtil.isSame(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
295
- expect(TimeUtil.isSame("13:20:00", "13:19:00")).toBe(false);
296
- expect(
297
- TimestampUtil.isSame(
298
- ISO_1980_10_18T13_20_00_000,
299
- ISO_1980_10_18T13_19_00_000,
300
- ),
301
- ).toBe(false);
302
-
303
- expect(DateUtil.isSame(ISO_1980_10_18, ISO_1980_10_18)).toBe(true);
304
- expect(TimeUtil.isSame("13:20:00", "13:20:00")).toBe(true);
305
- expect(
306
- TimestampUtil.isSame(
307
- ISO_1980_10_18T13_20_00_000,
308
- ISO_1980_10_18T13_20_00_000,
309
- ),
310
- ).toBe(true);
311
-
312
- expect(DateUtil.isSame(ISO_1980_10_18, ISO_1980_10_19)).toBe(false);
313
- expect(TimeUtil.isSame("13:20:00", "13:21:00")).toBe(false);
314
- expect(
315
- TimestampUtil.isSame(
316
- ISO_1980_10_18T13_20_00_000,
317
- ISO_1980_10_18T13_21_00_000,
318
- ),
319
- ).toBe(false);
320
- });
158
+ test("Calculations", () => {
159
+ expect(DateUtil.addSeconds(ISO_1980_01_01, 1)).toBe(ISO_1980_01_01);
160
+ expect(DateUtil.addMinutes(ISO_1980_01_01, 1)).toBe(ISO_1980_01_01);
161
+ expect(DateUtil.addHours(ISO_1980_01_01, 1)).toBe(ISO_1980_01_01);
162
+ expect(DateUtil.addDays(ISO_1980_01_01, 1)).toBe("1980-01-02");
163
+ expect(DateUtil.addWeeks(ISO_1980_01_01, 1)).toBe("1980-01-08");
164
+ expect(DateUtil.addMonths(ISO_1980_01_01, 1)).toBe("1980-02-01");
165
+ expect(DateUtil.addYears(ISO_1980_01_01, 1)).toBe("1981-01-01");
166
+ expect(DateUtil.subtractSeconds(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
167
+ expect(DateUtil.subtractMinutes(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
168
+ expect(DateUtil.subtractHours(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
169
+ expect(DateUtil.subtractDays(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
170
+ expect(DateUtil.subtractWeeks(ISO_1980_01_01, 1)).toBe("1979-12-25");
171
+ expect(DateUtil.subtractMonths(ISO_1980_01_01, 1)).toBe("1979-12-01");
172
+ expect(DateUtil.subtractYears(ISO_1980_01_01, 1)).toBe("1979-01-01");
173
+ });
321
174
 
322
- it("isSameDay", () => {
323
- expect(DateUtil.isSameDay(ISO_1980_10_18, ISO_1980_10_17)).toBe(false);
324
- expect(DateUtil.isSameDay(ISO_1980_10_18, ISO_1980_10_18)).toBe(true);
325
- expect(
326
- TimestampUtil.isSameDay(
327
- ISO_1980_10_18T13_20_00_000,
328
- "1980-10-19T13:19:00.000",
329
- ),
330
- ).toBe(false);
331
- expect(
332
- TimestampUtil.isSameDay(
333
- ISO_1980_10_18T13_20_00_000,
334
- ISO_1980_10_18T13_19_00_000,
335
- ),
336
- ).toBe(true);
337
- });
175
+ describe("test the start of the week", () => {
176
+ describe("with week start on sunday", () => {
177
+ beforeEach(() => {
178
+ // week starts on day 0 (sunday)
179
+ setSettings({ CALENDAR_WEEK_STARTS_ON: 0 });
180
+ });
181
+ it("startOfWeek", () => {
182
+ expect(DateUtil.startOfWeek("2021-03-01")).toBe("2021-02-28");
183
+ });
184
+ });
338
185
 
339
- it("isOther", () => {
340
- expect(DateUtil.isOther(ISO_1980_10_18, ISO_1980_10_17)).toBe(true);
341
- expect(TimeUtil.isOther("13:20:00", "13:19:00")).toBe(true);
342
- expect(
343
- TimestampUtil.isOther(
344
- ISO_1980_10_18T13_20_00_000,
345
- ISO_1980_10_18T13_19_00_000,
346
- ),
347
- ).toBe(true);
348
-
349
- expect(DateUtil.isOther(ISO_1980_10_18, ISO_1980_10_18)).toBe(false);
350
- expect(TimeUtil.isOther("13:20:00", "13:20:00")).toBe(false);
351
- expect(
352
- TimestampUtil.isOther(
353
- ISO_1980_10_18T13_20_00_000,
354
- ISO_1980_10_18T13_20_00_000,
355
- ),
356
- ).toBe(false);
357
-
358
- expect(DateUtil.isOther(ISO_1980_10_18, ISO_1980_10_19)).toBe(true);
359
- expect(TimeUtil.isOther("13:20:00", "13:21:00")).toBe(true);
360
- expect(
361
- TimestampUtil.isOther(
362
- ISO_1980_10_18T13_20_00_000,
363
- ISO_1980_10_18T13_21_00_000,
364
- ),
365
- ).toBe(true);
366
- });
186
+ describe("with week start on monday", () => {
187
+ beforeEach(() => {
188
+ // week starts on day 1 (monday)
189
+ setSettings({ CALENDAR_WEEK_STARTS_ON: 1 });
190
+ });
367
191
 
368
- it("isWeekend", () => {
369
- expect(DateUtil.isWeekend("2018-12-14")).toBe(false);
370
- expect(DateUtil.isWeekend("2018-12-15")).toBe(true);
371
- expect(DateUtil.isWeekend("2018-12-16")).toBe(true);
372
- expect(DateUtil.isWeekend("2018-12-17")).toBe(false);
373
- expect(DateUtil.isWeekend("2018-12-18")).toBe(false);
374
- expect(DateUtil.isWeekend("2018-12-19")).toBe(false);
375
- expect(DateUtil.isWeekend("2018-12-20")).toBe(false);
376
- });
192
+ it("startOfWeek", () => {
193
+ expect(DateUtil.startOfWeek("2021-03-01")).toBe("2021-03-01");
194
+ });
195
+ });
377
196
 
378
- it("addSeconds", () => {
379
- expect(DateUtil.addSeconds(ISO_1980_01_01, 1)).toBe(ISO_1980_01_01);
380
- expect(TimeUtil.addSeconds("13:20:00", 1)).toBe("13:20:01");
381
- expect(TimestampUtil.addSeconds(ISO_1980_01_01T13_20_00_000, 1)).toBe(
382
- "1980-01-01T13:20:01.000",
383
- );
384
- });
197
+ describe("with week start on saturday", () => {
198
+ beforeEach(() => {
199
+ setSettings({ CALENDAR_WEEK_STARTS_ON: 6 });
200
+ });
201
+ it("startOfWeek", () => {
202
+ expect(DateUtil.startOfWeek("2021-03-01")).toBe("2021-02-27");
203
+ });
204
+ });
205
+ });
385
206
 
386
- it("addMinutes", () => {
387
- expect(DateUtil.addMinutes(ISO_1980_01_01, 1)).toBe(ISO_1980_01_01);
388
- expect(TimeUtil.addMinutes("13:20:00", 1)).toBe("13:21:00");
389
- expect(TimestampUtil.addMinutes(ISO_1980_01_01T13_20_00_000, 1)).toBe(
390
- "1980-01-01T13:21:00.000",
391
- );
392
- });
207
+ test("Individual getters and setters", () => {
208
+ expect(DateUtil.startOfMonth(ISO_1980_01_15)).toBe(ISO_1980_01_01);
393
209
 
394
- it("addHours", () => {
395
- expect(DateUtil.addHours(ISO_1980_01_01, 1)).toBe(ISO_1980_01_01);
396
- expect(TimeUtil.addHours("13:20:00", 1)).toBe("14:20:00");
397
- expect(TimestampUtil.addHours(ISO_1980_01_01T13_20_00_000, 1)).toBe(
398
- "1980-01-01T14:20:00.000",
399
- );
210
+ expect(DateUtil.getWeek(ISO_1980_01_15)).toBe(3);
211
+ expect(DateUtil.setSecond(ISO_1980_01_01, 22)).toBe(ISO_1980_01_01);
212
+ expect(DateUtil.setMinute(ISO_1980_01_01, 22)).toBe(ISO_1980_01_01);
213
+ expect(DateUtil.setHour(ISO_1980_01_01, 22)).toBe(ISO_1980_01_01);
214
+ expect(DateUtil.setMonth(ISO_1980_01_01, 6)).toBe("1980-07-01");
215
+ expect(DateUtil.setYear(ISO_1980_01_01, 1986)).toBe("1986-01-01");
216
+ });
400
217
  });
401
218
 
402
- it("addDays", () => {
403
- expect(DateUtil.addDays(ISO_1980_01_01, 1)).toBe("1980-01-02");
404
- expect(TimeUtil.addDays("13:20:00", 1)).toBe("13:20:00");
405
- expect(TimestampUtil.addDays(ISO_1980_01_01T13_20_00_000, 1)).toBe(
406
- "1980-01-02T13:20:00.000",
407
- );
408
- });
219
+ describe("test TimeUtil", () => {
220
+ it("should convert java date time format to date-fns date time format", () => {
221
+ expect(TimeUtil.convertFormat()).toBe(ISO_TIME_FORMAT);
222
+ expect(TimeUtil.convertFormat("HH:mm:ss")).toBe("HH:mm:ss");
223
+ });
409
224
 
410
- it("addWeeks", () => {
411
- expect(DateUtil.addWeeks(ISO_1980_01_01, 1)).toBe("1980-01-08");
412
- expect(TimeUtil.addWeeks("13:20:00", 1)).toBe("13:20:00");
413
- expect(TimestampUtil.addWeeks(ISO_1980_01_01T13_20_00_000, 1)).toBe(
414
- "1980-01-08T13:20:00.000",
415
- );
416
- });
225
+ it("should render iso time to specified format", () => {
226
+ expect(TimeUtil.toFormat("14:15:12", "HH:mm")).toBe("14:15");
227
+ expect(TimeUtil.toFormat("14:15:12", "h:mm")).toBe("2:15");
228
+ expect(TimeUtil.toFormat("23:15:12", "h:mm")).toBe("11:15");
229
+ });
417
230
 
418
- it("addMonths", () => {
419
- expect(DateUtil.addMonths(ISO_1980_01_01, 1)).toBe("1980-02-01");
420
- expect(TimeUtil.addMonths("13:20:00", 1)).toBe("13:20:00");
421
- expect(TimestampUtil.addMonths(ISO_1980_01_01T13_20_00_000, 1)).toBe(
422
- "1980-02-01T13:20:00.000",
423
- );
424
- });
231
+ it("should render specified format to iso time", () => {
232
+ expect(TimeUtil.toISO("14:15", "HH:mm")).toBe("14:15:00");
233
+ expect(TimeUtil.toISO("2:15 AM", "h:mm aa")).toBe("02:15:00");
234
+ expect(TimeUtil.toISO("02:15 PM", "hh:mm aa")).toBe("14:15:00");
235
+ expect(TimeUtil.toISO("11:15 AM", "h:mm aa")).toBe("11:15:00");
236
+ });
425
237
 
426
- it("addYears", () => {
427
- expect(DateUtil.addYears(ISO_1980_01_01, 1)).toBe("1981-01-01");
428
- expect(TimeUtil.addYears("13:20:00", 1)).toBe("13:20:00");
429
- expect(TimestampUtil.addYears(ISO_1980_01_01T13_20_00_000, 1)).toBe(
430
- "1981-01-01T13:20:00.000",
431
- );
432
- });
238
+ it("should return invalid date when date entered is not a date", () => {
239
+ expect(TimeUtil.toISO("bla", "HH:mm")).toBe(INVALID_DATE);
240
+ });
433
241
 
434
- it("subtractSeconds", () => {
435
- expect(DateUtil.subtractSeconds(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
436
- expect(TimeUtil.subtractSeconds("13:20:00", 1)).toBe("13:19:59");
437
- expect(TimestampUtil.subtractSeconds(ISO_1980_01_01T13_20_00_000, 1)).toBe(
438
- "1980-01-01T13:19:59.000",
439
- );
440
- });
242
+ describe("asserts", () => {
243
+ it("isValid", () => {
244
+ expect(TimeUtil.isValid("13:20", "HH:mm")).toBe(true);
245
+ expect(TimeUtil.isValid("bla", "HH:mm")).toBe(false);
246
+ });
441
247
 
442
- it("subtractMinutes", () => {
443
- expect(DateUtil.subtractMinutes(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
444
- expect(TimeUtil.subtractMinutes("13:20:00", 1)).toBe("13:19:00");
445
- expect(TimestampUtil.subtractMinutes(ISO_1980_01_01T13_20_00_000, 1)).toBe(
446
- "1980-01-01T13:19:00.000",
447
- );
448
- });
248
+ it("isAfter", () => {
249
+ expect(TimeUtil.isAfter("13:20:00", "13:19:00")).toBe(true);
250
+ expect(TimeUtil.isAfter("13:20:00", "13:20:00")).toBe(false);
251
+ expect(TimeUtil.isAfter("13:20:00", "13:21:00")).toBe(false);
252
+ });
449
253
 
450
- it("subtractHours", () => {
451
- expect(DateUtil.subtractHours(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
452
- expect(TimeUtil.subtractHours("13:20:00", 1)).toBe("12:20:00");
453
- expect(TimestampUtil.subtractHours(ISO_1980_01_01T13_20_00_000, 1)).toBe(
454
- "1980-01-01T12:20:00.000",
455
- );
456
- });
254
+ it("isSameOrAfter", () => {
255
+ expect(TimeUtil.isSameOrAfter("13:20:00", "13:19:00")).toBe(true);
256
+ expect(TimeUtil.isSameOrAfter("13:20:00", "13:20:00")).toBe(true);
257
+ expect(TimeUtil.isSameOrAfter("13:20:00", "13:21:00")).toBe(false);
258
+ });
457
259
 
458
- it("subtractDays", () => {
459
- expect(DateUtil.subtractDays(ISO_1980_01_01, 1)).toBe(ISO_1979_12_31);
460
- expect(TimeUtil.subtractDays("13:20:00", 1)).toBe("13:20:00");
461
- expect(TimestampUtil.subtractDays(ISO_1980_01_01T13_20_00_000, 1)).toBe(
462
- "1979-12-31T13:20:00.000",
463
- );
464
- });
260
+ it("isBefore", () => {
261
+ expect(TimeUtil.isBefore("13:20:00", "13:19:00")).toBe(false);
262
+ expect(TimeUtil.isBefore("13:20:00", "13:20:00")).toBe(false);
263
+ expect(TimeUtil.isBefore("13:20:00", "13:21:00")).toBe(true);
264
+ });
465
265
 
466
- it("subtractWeeks", () => {
467
- expect(DateUtil.subtractWeeks(ISO_1980_01_01, 1)).toBe("1979-12-25");
468
- expect(TimeUtil.subtractWeeks("13:20:00", 1)).toBe("13:20:00");
469
- expect(TimestampUtil.subtractWeeks(ISO_1980_01_01T13_20_00_000, 1)).toBe(
470
- "1979-12-25T13:20:00.000",
471
- );
472
- });
266
+ it("isSameOrBefore", () => {
267
+ expect(TimeUtil.isSameOrBefore("13:20:00", "13:19:00")).toBe(false);
268
+ expect(TimeUtil.isSameOrBefore("13:20:00", "13:20:00")).toBe(true);
269
+ expect(TimeUtil.isSameOrBefore("13:20:00", "13:21:00")).toBe(true);
270
+ });
473
271
 
474
- it("subtractMonths", () => {
475
- expect(DateUtil.subtractMonths(ISO_1980_01_01, 1)).toBe("1979-12-01");
476
- expect(TimeUtil.subtractMonths("13:20:00", 1)).toBe("13:20:00");
477
- expect(TimestampUtil.subtractMonths(ISO_1980_01_01T13_20_00_000, 1)).toBe(
478
- "1979-12-01T13:20:00.000",
479
- );
480
- });
272
+ it("isSame", () => {
273
+ expect(TimeUtil.isSame("13:20:00", "13:19:00")).toBe(false);
274
+ expect(TimeUtil.isSame("13:20:00", "13:20:00")).toBe(true);
275
+ expect(TimeUtil.isSame("13:20:00", "13:21:00")).toBe(false);
276
+ });
481
277
 
482
- it("subtractYears", () => {
483
- expect(DateUtil.subtractYears(ISO_1980_01_01, 1)).toBe("1979-01-01");
484
- expect(TimeUtil.subtractYears("13:20:00", 1)).toBe("13:20:00");
485
- expect(TimestampUtil.subtractYears(ISO_1980_01_01T13_20_00_000, 1)).toBe(
486
- "1979-01-01T13:20:00.000",
487
- );
488
- });
278
+ it("isOther", () => {
279
+ expect(TimeUtil.isOther("13:20:00", "13:19:00")).toBe(true);
280
+ expect(TimeUtil.isOther("13:20:00", "13:20:00")).toBe(false);
281
+ expect(TimeUtil.isOther("13:20:00", "13:21:00")).toBe(true);
282
+ });
283
+ });
284
+
285
+ test("Calculations", () => {
286
+ expect(TimeUtil.addSeconds("13:20:00", 1)).toBe("13:20:01");
287
+ expect(TimeUtil.addMinutes("13:20:00", 1)).toBe("13:21:00");
288
+ expect(TimeUtil.addHours("13:20:00", 1)).toBe("14:20:00");
289
+ expect(TimeUtil.addDays("13:20:00", 1)).toBe("13:20:00");
290
+ expect(TimeUtil.addWeeks("13:20:00", 1)).toBe("13:20:00");
291
+ expect(TimeUtil.addMonths("13:20:00", 1)).toBe("13:20:00");
292
+ expect(TimeUtil.addYears("13:20:00", 1)).toBe("13:20:00");
293
+ expect(TimeUtil.subtractSeconds("13:20:00", 1)).toBe("13:19:59");
294
+ expect(TimeUtil.subtractMinutes("13:20:00", 1)).toBe("13:19:00");
295
+ expect(TimeUtil.subtractHours("13:20:00", 1)).toBe("12:20:00");
296
+ expect(TimeUtil.subtractDays("13:20:00", 1)).toBe("13:20:00");
297
+ expect(TimeUtil.subtractWeeks("13:20:00", 1)).toBe("13:20:00");
298
+ expect(TimeUtil.subtractMonths("13:20:00", 1)).toBe("13:20:00");
299
+ expect(TimeUtil.subtractYears("13:20:00", 1)).toBe("13:20:00");
300
+ });
489
301
 
490
- it("startOfMonth", () => {
491
- expect(DateUtil.startOfMonth(ISO_1980_01_15)).toBe(ISO_1980_01_01);
302
+ test("Individual getters and setters", () => {
303
+ expect(TimeUtil.getHours("13:20:00")).toBe(13);
304
+ expect(TimeUtil.getMinutes("13:20:00")).toBe(20);
305
+ expect(TimeUtil.setSecond("13:20:00", 22)).toBe("13:20:22");
306
+ expect(TimeUtil.setMinute("13:20:00", 22)).toBe("13:22:00");
307
+ expect(TimeUtil.setHour("13:20:00", 22)).toBe("22:20:00");
308
+ expect(TimeUtil.setMonth("13:20:00", 6)).toBe("13:20:00");
309
+ expect(TimeUtil.setYear("13:20:00", 1986)).toBe("13:20:00");
310
+ });
492
311
  });
493
312
 
494
- describe("test the start of the week", () => {
495
- describe("with week start on sunday", () => {
496
- beforeEach(() => {
497
- // week starts on day 0 (sunday)
498
- setSettings({ CALENDAR_WEEK_STARTS_ON: 0 });
313
+ describe(`test DateTimeUtil`, () => {
314
+ describe(`test DateTimeUtil - offset off`, () => {
315
+ it("should convert java date time format to date-fns date time format", () => {
316
+ expect(DateTimeUtil.convertFormat()).toBe(ISO_DATETIME_FORMAT);
317
+ expect(DateTimeUtil.convertFormat("yyyy-MM-dd HH:mm:ss")).toBe(
318
+ "yyyy-MM-dd HH:mm:ss",
319
+ );
499
320
  });
500
- it("startOfWeek", () => {
501
- expect(DateUtil.startOfWeek("2021-03-01")).toBe("2021-02-28");
321
+
322
+ it("should render iso datetime to specified format", () => {
323
+ expect(
324
+ DateTimeUtil.toFormat("2017-06-13T14:15:12", DUTCH_DATETIME_FORMAT),
325
+ ).toBe(INPUT_13_06_2017_14_15);
326
+ expect(DateTimeUtil.toFormat("2017-06-13T14:15:12", "h:mm")).toBe(
327
+ "2:15",
328
+ );
329
+ expect(
330
+ DateTimeUtil.toFormat("2017-06-13T23:15:12", DUTCH_DATE_FORMAT),
331
+ ).toBe(INPUT_13_06_2017);
502
332
  });
503
- });
504
333
 
505
- describe("with week start on monday", () => {
506
- beforeEach(() => {
507
- // week starts on day 1 (monday)
508
- setSettings({ CALENDAR_WEEK_STARTS_ON: 1 });
334
+ it("should render specified format to iso datetime", () => {
335
+ expect(
336
+ DateTimeUtil.toISO(INPUT_13_06_2017_14_15, DUTCH_DATETIME_FORMAT),
337
+ ).toBe("2017-06-13T14:15:00");
338
+ expect(DateTimeUtil.toISO("13-06-2017 2:15", "dd-MM-yyyy h:mm")).toBe(
339
+ "2017-06-13T02:15:00",
340
+ );
341
+ expect(DateTimeUtil.toISO(INPUT_13_06_2017, DUTCH_DATE_FORMAT)).toBe(
342
+ "2017-06-13T00:00:00",
343
+ );
344
+ });
345
+
346
+ it("should return invalid date when date entered is not a date", () => {
347
+ expect(DateTimeUtil.toISO("bla", DUTCH_DATETIME_FORMAT)).toBe(
348
+ INVALID_DATE,
349
+ );
350
+ });
351
+
352
+ describe("asserts", () => {
353
+ it("isValid", () => {
354
+ expect(
355
+ DateTimeUtil.isValid("18-10-1980 13:20", DUTCH_DATETIME_FORMAT),
356
+ ).toBe(true);
357
+ expect(DateTimeUtil.isValid("bla", DUTCH_DATETIME_FORMAT)).toBe(
358
+ false,
359
+ );
360
+ });
361
+
362
+ it("isAfter", () => {
363
+ expect(
364
+ DateTimeUtil.isAfter(
365
+ ISO_1980_10_18T13_20_00,
366
+ "1980-10-18T13:19:00",
367
+ ),
368
+ ).toBe(true);
369
+ expect(
370
+ DateTimeUtil.isAfter(
371
+ ISO_1980_10_18T13_20_00,
372
+ ISO_1980_10_18T13_20_00,
373
+ ),
374
+ ).toBe(false);
375
+ expect(
376
+ DateTimeUtil.isAfter(
377
+ ISO_1980_10_18T13_20_00,
378
+ "1980-10-18T13:21:00",
379
+ ),
380
+ ).toBe(false);
381
+ });
382
+
383
+ it("isAmbiguous", () => {
384
+ expect(DateTimeUtil.isAmbiguous(null, DUTCH_DATETIME_FORMAT)).toBe(
385
+ false,
386
+ );
387
+
388
+ expect(DateTimeUtil.isAmbiguous("", DUTCH_DATETIME_FORMAT)).toBe(
389
+ false,
390
+ );
391
+
392
+ expect(
393
+ DateTimeUtil.isAmbiguous("18-10-1980 13:20", DUTCH_DATETIME_FORMAT),
394
+ ).toBe(false);
395
+
396
+ expect(
397
+ DateTimeUtil.isAmbiguous("27-10-2024 02:30", DUTCH_DATETIME_FORMAT),
398
+ ).toBe(true);
399
+
400
+ expect(
401
+ DateTimeUtil.isAmbiguous(new Date(2024, 9, 27, 2, 30, 0)),
402
+ ).toBe(true);
403
+
404
+ const d = DateTimeUtil.toDate(
405
+ "27-10-2024T02:30+01:00",
406
+ "dd-MM-yyyy'T'HH:mmxxx",
407
+ );
408
+ expect(DateTimeUtil.isAmbiguous(d)).toBe(true);
409
+ });
509
410
  });
510
411
 
511
- it("startOfWeek", () => {
512
- expect(DateUtil.startOfWeek("2021-03-01")).toBe("2021-03-01");
412
+ test("Calculations", () => {
413
+ expect(DateTimeUtil.addSeconds(ISO_1980_01_01T13_20_00, 1)).toBe(
414
+ "1980-01-01T13:20:01",
415
+ );
416
+ expect(DateTimeUtil.addMinutes(ISO_1980_01_01T13_20_00, 1)).toBe(
417
+ "1980-01-01T13:21:00",
418
+ );
419
+ expect(DateTimeUtil.addHours(ISO_1980_01_01T13_20_00, 1)).toBe(
420
+ "1980-01-01T14:20:00",
421
+ );
422
+ expect(DateTimeUtil.addDays(ISO_1980_01_01T13_20_00, 1)).toBe(
423
+ "1980-01-02T13:20:00",
424
+ );
425
+ expect(DateTimeUtil.addWeeks(ISO_1980_01_01T13_20_00, 1)).toBe(
426
+ "1980-01-08T13:20:00",
427
+ );
428
+ expect(DateTimeUtil.addMonths(ISO_1980_01_01T13_20_00, 1)).toBe(
429
+ "1980-02-01T13:20:00",
430
+ );
431
+ expect(DateTimeUtil.addYears(ISO_1980_01_01T13_20_00, 1)).toBe(
432
+ "1981-01-01T13:20:00",
433
+ );
434
+ expect(DateTimeUtil.subtractSeconds(ISO_1980_01_01T13_20_00, 1)).toBe(
435
+ "1980-01-01T13:19:59",
436
+ );
437
+ expect(DateTimeUtil.subtractMinutes(ISO_1980_01_01T13_20_00, 1)).toBe(
438
+ "1980-01-01T13:19:00",
439
+ );
440
+ expect(DateTimeUtil.subtractHours(ISO_1980_01_01T13_20_00, 1)).toBe(
441
+ "1980-01-01T12:20:00",
442
+ );
443
+ expect(DateTimeUtil.subtractDays(ISO_1980_01_01T13_20_00, 1)).toBe(
444
+ "1979-12-31T13:20:00",
445
+ );
446
+ expect(DateTimeUtil.subtractWeeks(ISO_1980_01_01T13_20_00, 1)).toBe(
447
+ "1979-12-25T13:20:00",
448
+ );
449
+ expect(DateTimeUtil.subtractMonths(ISO_1980_01_01T13_20_00, 1)).toBe(
450
+ "1979-12-01T13:20:00",
451
+ );
452
+ expect(DateTimeUtil.subtractYears(ISO_1980_01_01T13_20_00, 1)).toBe(
453
+ "1979-01-01T13:20:00",
454
+ );
513
455
  });
514
456
  });
515
457
 
516
- describe("with week start on saturday", () => {
458
+ describe(`test DateTimeUtil - offset on`, () => {
517
459
  beforeEach(() => {
518
- setSettings({ CALENDAR_WEEK_STARTS_ON: 6 });
460
+ setSettings({ [INCLUDE_TIME_OFFSET]: true });
461
+ DateTimeUtil.setTimeZone("Europe/Amsterdam");
519
462
  });
520
- it("startOfWeek", () => {
521
- expect(DateUtil.startOfWeek("2021-03-01")).toBe("2021-02-27");
463
+
464
+ it("Retrieves available offsets for the timezone", () => {
465
+ expect(DateTimeUtil.getTimezoneOffsets()).toEqual({
466
+ daylight: {
467
+ abbr: "CEST",
468
+ label: "Central European Summer Time",
469
+ value: "+02:00",
470
+ },
471
+ standard: {
472
+ abbr: "CET",
473
+ label: "Central European Standard Time",
474
+ value: "+01:00",
475
+ },
476
+ });
477
+ });
478
+
479
+ it("Retrieves offset information", () => {
480
+ expect(DateTimeUtil.getOffset("2024-01-01T10:10:10+00:00")).toEqual({
481
+ abbr: "CET",
482
+ label: "Central European Standard Time",
483
+ value: "+01:00",
484
+ });
485
+
486
+ expect(DateTimeUtil.getOffset("")).toEqual(null);
487
+ });
488
+
489
+ it("should convert java date time format to date-fns date time format", () => {
490
+ expect(DateTimeUtil.convertFormat()).toBe(
491
+ ISO_DATETIME_FORMAT + DATETIME_OFFSET_FORMAT,
492
+ );
493
+ expect(DateTimeUtil.convertFormat("yyyy-MM-dd HH:mm:ss")).toBe(
494
+ "yyyy-MM-dd HH:mm:ss",
495
+ );
496
+ });
497
+
498
+ it("should render iso datetime to specified format", () => {
499
+ expect(
500
+ DateTimeUtil.toFormat(
501
+ "2017-06-13T14:15:12+02:00",
502
+ DUTCH_DATETIME_FORMAT,
503
+ ),
504
+ ).toBe(INPUT_13_06_2017_14_15);
505
+ expect(DateTimeUtil.toFormat("2017-06-13T14:15:12+02:00", "h:mm")).toBe(
506
+ "2:15",
507
+ );
508
+ expect(
509
+ DateTimeUtil.toFormat("2017-06-13T19:15:12+02:00", DUTCH_DATE_FORMAT),
510
+ ).toBe(INPUT_13_06_2017);
511
+ });
512
+
513
+ it("should render specified format to iso datetime", () => {
514
+ expect(
515
+ DateTimeUtil.toISO(INPUT_13_06_2017_14_15, DUTCH_DATETIME_FORMAT),
516
+ ).toBe("2017-06-13T14:15:00+02:00");
517
+ expect(DateTimeUtil.toISO("13-06-2017 2:15", "dd-MM-yyyy h:mm")).toBe(
518
+ "2017-06-13T02:15:00+02:00",
519
+ );
520
+ expect(DateTimeUtil.toISO(INPUT_13_06_2017, DUTCH_DATE_FORMAT)).toBe(
521
+ "2017-06-13T00:00:00+02:00",
522
+ );
523
+ });
524
+
525
+ it("should return invalid date when date entered is not a date", () => {
526
+ expect(DateTimeUtil.toISO("bla", DUTCH_DATETIME_FORMAT)).toBe(
527
+ INVALID_DATE,
528
+ );
529
+ });
530
+
531
+ describe("asserts", () => {
532
+ it("isValid", () => {
533
+ expect(
534
+ DateTimeUtil.isValid("18-10-1980 13:20", DUTCH_DATETIME_FORMAT),
535
+ ).toBe(true);
536
+ expect(DateTimeUtil.isValid("bla", DUTCH_DATETIME_FORMAT)).toBe(
537
+ false,
538
+ );
539
+ });
540
+
541
+ it("isAfter", () => {
542
+ expect(
543
+ DateTimeUtil.isAfter(
544
+ ISO_1980_10_18T13_20_00_OFFSET,
545
+ "1980-10-18T13:19:00+02:00",
546
+ ),
547
+ ).toBe(true);
548
+ expect(
549
+ DateTimeUtil.isAfter(
550
+ ISO_1980_10_18T13_20_00_OFFSET,
551
+ ISO_1980_10_18T13_20_00_OFFSET,
552
+ ),
553
+ ).toBe(false);
554
+ expect(
555
+ DateTimeUtil.isAfter(
556
+ ISO_1980_10_18T13_20_00_OFFSET,
557
+ "1980-10-18T13:21:00+02:00",
558
+ ),
559
+ ).toBe(false);
560
+ });
561
+ });
562
+
563
+ test("Calculations", () => {
564
+ expect(DateTimeUtil.addSeconds(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
565
+ "1980-01-01T13:20:01+01:00",
566
+ );
567
+ expect(DateTimeUtil.addMinutes(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
568
+ "1980-01-01T13:21:00+01:00",
569
+ );
570
+ expect(DateTimeUtil.addHours(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
571
+ "1980-01-01T14:20:00+01:00",
572
+ );
573
+ expect(DateTimeUtil.addDays(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
574
+ "1980-01-02T13:20:00+01:00",
575
+ );
576
+ expect(DateTimeUtil.addWeeks(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
577
+ "1980-01-08T13:20:00+01:00",
578
+ );
579
+ expect(DateTimeUtil.addMonths(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
580
+ "1980-02-01T13:20:00+01:00",
581
+ );
582
+ expect(DateTimeUtil.addYears(ISO_1980_01_01T13_20_00_OFFSET, 1)).toBe(
583
+ "1981-01-01T13:20:00+01:00",
584
+ );
585
+ expect(
586
+ DateTimeUtil.subtractSeconds(ISO_1980_01_01T13_20_00_OFFSET, 1),
587
+ ).toBe("1980-01-01T13:19:59+01:00");
588
+ expect(
589
+ DateTimeUtil.subtractMinutes(ISO_1980_01_01T13_20_00_OFFSET, 1),
590
+ ).toBe("1980-01-01T13:19:00+01:00");
591
+ expect(
592
+ DateTimeUtil.subtractHours(ISO_1980_01_01T13_20_00_OFFSET, 1),
593
+ ).toBe("1980-01-01T12:20:00+01:00");
594
+ expect(
595
+ DateTimeUtil.subtractDays(ISO_1980_01_01T13_20_00_OFFSET, 1),
596
+ ).toBe("1979-12-31T13:20:00+01:00");
597
+ expect(
598
+ DateTimeUtil.subtractWeeks(ISO_1980_01_01T13_20_00_OFFSET, 1),
599
+ ).toBe("1979-12-25T13:20:00+01:00");
600
+ expect(
601
+ DateTimeUtil.subtractMonths(ISO_1980_01_01T13_20_00_OFFSET, 1),
602
+ ).toBe("1979-12-01T13:20:00+01:00");
603
+ expect(
604
+ DateTimeUtil.subtractYears(ISO_1980_01_01T13_20_00_OFFSET, 1),
605
+ ).toBe("1979-01-01T13:20:00+01:00");
522
606
  });
523
607
  });
524
608
  });
525
- it("getWeek", () => {
526
- expect(DateUtil.getWeek(ISO_1980_01_15)).toBe(3);
527
- });
528
609
 
529
- it("getHours", () => {
530
- expect(TimeUtil.getHours("13:20:00")).toBe(13);
531
- expect(TimestampUtil.getHours(ISO_1980_01_01T13_20_00_000)).toBe(13);
532
- });
610
+ describe("test TimeStampUtil", () => {
611
+ it("should convert java date time format to date-fns date time format", () => {
612
+ expect(TimestampUtil.convertFormat()).toBe(ISO_TIMESTAMP_FORMAT);
613
+ expect(TimestampUtil.convertFormat("yyyy-MM-dd HH:mm:ss.SSS")).toBe(
614
+ "yyyy-MM-dd HH:mm:ss.SSS",
615
+ );
616
+ });
533
617
 
534
- it("getMinutes", () => {
535
- expect(TimeUtil.getMinutes("13:20:00")).toBe(20);
536
- expect(TimestampUtil.getMinutes(ISO_1980_01_01T13_20_00_000)).toBe(20);
537
- });
618
+ it("should render iso timestamp to specified format", () => {
619
+ expect(
620
+ TimestampUtil.toFormat(
621
+ "2017-06-13T14:15:12.000",
622
+ DUTCH_DATETIME_FORMAT,
623
+ ),
624
+ ).toBe(INPUT_13_06_2017_14_15);
625
+ expect(TimestampUtil.toFormat("2017-06-13T14:15:12.000", "h:mm")).toBe(
626
+ "2:15",
627
+ );
628
+ expect(
629
+ TimestampUtil.toFormat("2017-06-13T23:15:12.000", DUTCH_DATE_FORMAT),
630
+ ).toBe(INPUT_13_06_2017);
631
+ });
538
632
 
539
- it("setSecond", () => {
540
- expect(DateUtil.setSecond(ISO_1980_01_01, 22)).toBe(ISO_1980_01_01);
541
- expect(TimeUtil.setSecond("13:20:00", 22)).toBe("13:20:22");
542
- expect(TimestampUtil.setSecond(ISO_1980_01_01T13_20_00_000, 22)).toBe(
543
- "1980-01-01T13:20:22.000",
544
- );
545
- });
633
+ it("should render specified format to iso timestamp", () => {
634
+ expect(
635
+ TimestampUtil.toISO(INPUT_13_06_2017_14_15, DUTCH_DATETIME_FORMAT),
636
+ ).toBe("2017-06-13T14:15:00.000");
637
+ expect(TimestampUtil.toISO("13-06-2017 2:15", "dd-MM-yyyy h:mm")).toBe(
638
+ "2017-06-13T02:15:00.000",
639
+ );
640
+ expect(TimestampUtil.toISO(INPUT_13_06_2017, DUTCH_DATE_FORMAT)).toBe(
641
+ "2017-06-13T00:00:00.000",
642
+ );
643
+ });
546
644
 
547
- it("setMinute", () => {
548
- expect(DateUtil.setMinute(ISO_1980_01_01, 22)).toBe(ISO_1980_01_01);
549
- expect(TimeUtil.setMinute("13:20:00", 22)).toBe("13:22:00");
550
- expect(TimestampUtil.setMinute(ISO_1980_01_01T13_20_00_000, 22)).toBe(
551
- "1980-01-01T13:22:00.000",
552
- );
553
- });
645
+ it("should return invalid date when date entered is not a date", () => {
646
+ expect(TimestampUtil.toISO("bla", DUTCH_DATETIME_FORMAT)).toBe(
647
+ INVALID_DATE,
648
+ );
649
+ });
554
650
 
555
- it("setHour", () => {
556
- expect(DateUtil.setHour(ISO_1980_01_01, 22)).toBe(ISO_1980_01_01);
557
- expect(TimeUtil.setHour("13:20:00", 22)).toBe("22:20:00");
558
- expect(TimestampUtil.setHour(ISO_1980_01_01T13_20_00_000, 22)).toBe(
559
- "1980-01-01T22:20:00.000",
560
- );
561
- });
651
+ describe("asserts", () => {
652
+ it("isValid", () => {
653
+ expect(
654
+ TimestampUtil.isValid("18-10-1980 13:20", DUTCH_DATETIME_FORMAT),
655
+ ).toBe(true);
656
+ expect(TimestampUtil.isValid("bla", DUTCH_DATETIME_FORMAT)).toBe(false);
657
+ });
562
658
 
563
- it("setMonth", () => {
564
- expect(DateUtil.setMonth(ISO_1980_01_01, 6)).toBe("1980-07-01");
565
- expect(TimeUtil.setMonth("13:20:00", 6)).toBe("13:20:00");
566
- expect(TimestampUtil.setMonth(ISO_1980_01_01T13_20_00_000, 6)).toBe(
567
- "1980-07-01T13:20:00.000",
568
- );
569
- });
659
+ it("isAfter", () => {
660
+ expect(
661
+ TimestampUtil.isAfter(
662
+ ISO_1980_10_18T13_20_00_000,
663
+ ISO_1980_10_18T13_19_00_000,
664
+ ),
665
+ ).toBe(true);
666
+ expect(
667
+ TimestampUtil.isAfter(
668
+ ISO_1980_10_18T13_20_00_000,
669
+ ISO_1980_10_18T13_20_00_000,
670
+ ),
671
+ ).toBe(false);
672
+ expect(
673
+ TimestampUtil.isAfter(
674
+ ISO_1980_10_18T13_20_00_000,
675
+ ISO_1980_10_18T13_21_00_000,
676
+ ),
677
+ ).toBe(false);
678
+ });
679
+
680
+ it("isSameOrAfter", () => {
681
+ expect(
682
+ TimestampUtil.isSameOrAfter(
683
+ ISO_1980_10_18T13_20_00_000,
684
+ ISO_1980_10_18T13_19_00_000,
685
+ ),
686
+ ).toBe(true);
687
+ expect(
688
+ TimestampUtil.isSameOrAfter(
689
+ ISO_1980_10_18T13_20_00_000,
690
+ ISO_1980_10_18T13_20_00_000,
691
+ ),
692
+ ).toBe(true);
693
+ expect(
694
+ TimestampUtil.isSameOrAfter(
695
+ ISO_1980_10_18T13_20_00_000,
696
+ ISO_1980_10_18T13_21_00_000,
697
+ ),
698
+ ).toBe(false);
699
+ });
700
+
701
+ it("isBefore", () => {
702
+ expect(
703
+ TimestampUtil.isBefore(
704
+ ISO_1980_10_18T13_20_00_000,
705
+ ISO_1980_10_18T13_19_00_000,
706
+ ),
707
+ ).toBe(false);
708
+ expect(
709
+ TimestampUtil.isBefore(
710
+ ISO_1980_10_18T13_20_00_000,
711
+ ISO_1980_10_18T13_20_00_000,
712
+ ),
713
+ ).toBe(false);
714
+ expect(
715
+ TimestampUtil.isBefore(
716
+ ISO_1980_10_18T13_20_00_000,
717
+ ISO_1980_10_18T13_21_00_000,
718
+ ),
719
+ ).toBe(true);
720
+ });
721
+
722
+ it("isSameOrBefore", () => {
723
+ expect(
724
+ TimestampUtil.isSameOrBefore(
725
+ ISO_1980_10_18T13_20_00_000,
726
+ ISO_1980_10_18T13_19_00_000,
727
+ ),
728
+ ).toBe(false);
729
+ expect(
730
+ TimestampUtil.isSameOrBefore(
731
+ ISO_1980_10_18T13_20_00_000,
732
+ ISO_1980_10_18T13_20_00_000,
733
+ ),
734
+ ).toBe(true);
735
+ expect(
736
+ TimestampUtil.isSameOrBefore(
737
+ ISO_1980_10_18T13_20_00_000,
738
+ ISO_1980_10_18T13_21_00_000,
739
+ ),
740
+ ).toBe(true);
741
+ });
742
+
743
+ it("isSame", () => {
744
+ expect(
745
+ TimestampUtil.isSame(
746
+ ISO_1980_10_18T13_20_00_000,
747
+ ISO_1980_10_18T13_19_00_000,
748
+ ),
749
+ ).toBe(false);
750
+ expect(
751
+ TimestampUtil.isSame(
752
+ ISO_1980_10_18T13_20_00_000,
753
+ ISO_1980_10_18T13_20_00_000,
754
+ ),
755
+ ).toBe(true);
756
+ expect(
757
+ TimestampUtil.isSame(
758
+ ISO_1980_10_18T13_20_00_000,
759
+ ISO_1980_10_18T13_21_00_000,
760
+ ),
761
+ ).toBe(false);
762
+ });
570
763
 
571
- it("setYear", () => {
572
- expect(DateUtil.setYear(ISO_1980_01_01, 1986)).toBe("1986-01-01");
573
- expect(TimeUtil.setYear("13:20:00", 1986)).toBe("13:20:00");
574
- expect(TimestampUtil.setYear(ISO_1980_01_01T13_20_00_000, 1986)).toBe(
575
- "1986-01-01T13:20:00.000",
576
- );
764
+ it("isSameDay", () => {
765
+ expect(
766
+ TimestampUtil.isSameDay(
767
+ ISO_1980_10_18T13_20_00_000,
768
+ "1980-10-19T13:19:00.000",
769
+ ),
770
+ ).toBe(false);
771
+ expect(
772
+ TimestampUtil.isSameDay(
773
+ ISO_1980_10_18T13_20_00_000,
774
+ ISO_1980_10_18T13_19_00_000,
775
+ ),
776
+ ).toBe(true);
777
+ });
778
+
779
+ it("isOther", () => {
780
+ expect(
781
+ TimestampUtil.isOther(
782
+ ISO_1980_10_18T13_20_00_000,
783
+ ISO_1980_10_18T13_19_00_000,
784
+ ),
785
+ ).toBe(true);
786
+ expect(
787
+ TimestampUtil.isOther(
788
+ ISO_1980_10_18T13_20_00_000,
789
+ ISO_1980_10_18T13_20_00_000,
790
+ ),
791
+ ).toBe(false);
792
+ expect(
793
+ TimestampUtil.isOther(
794
+ ISO_1980_10_18T13_20_00_000,
795
+ ISO_1980_10_18T13_21_00_000,
796
+ ),
797
+ ).toBe(true);
798
+ });
799
+ });
800
+
801
+ test("Calculations", () => {
802
+ expect(TimestampUtil.addSeconds(ISO_1980_01_01T13_20_00_000, 1)).toBe(
803
+ "1980-01-01T13:20:01.000",
804
+ );
805
+ expect(TimestampUtil.addMinutes(ISO_1980_01_01T13_20_00_000, 1)).toBe(
806
+ "1980-01-01T13:21:00.000",
807
+ );
808
+ expect(TimestampUtil.addHours(ISO_1980_01_01T13_20_00_000, 1)).toBe(
809
+ "1980-01-01T14:20:00.000",
810
+ );
811
+ expect(TimestampUtil.addDays(ISO_1980_01_01T13_20_00_000, 1)).toBe(
812
+ "1980-01-02T13:20:00.000",
813
+ );
814
+ expect(TimestampUtil.addWeeks(ISO_1980_01_01T13_20_00_000, 1)).toBe(
815
+ "1980-01-08T13:20:00.000",
816
+ );
817
+ expect(TimestampUtil.addMonths(ISO_1980_01_01T13_20_00_000, 1)).toBe(
818
+ "1980-02-01T13:20:00.000",
819
+ );
820
+ expect(TimestampUtil.addYears(ISO_1980_01_01T13_20_00_000, 1)).toBe(
821
+ "1981-01-01T13:20:00.000",
822
+ );
823
+ expect(
824
+ TimestampUtil.subtractSeconds(ISO_1980_01_01T13_20_00_000, 1),
825
+ ).toBe("1980-01-01T13:19:59.000");
826
+ expect(
827
+ TimestampUtil.subtractMinutes(ISO_1980_01_01T13_20_00_000, 1),
828
+ ).toBe("1980-01-01T13:19:00.000");
829
+ expect(TimestampUtil.subtractHours(ISO_1980_01_01T13_20_00_000, 1)).toBe(
830
+ "1980-01-01T12:20:00.000",
831
+ );
832
+ expect(TimestampUtil.subtractDays(ISO_1980_01_01T13_20_00_000, 1)).toBe(
833
+ "1979-12-31T13:20:00.000",
834
+ );
835
+ expect(TimestampUtil.subtractWeeks(ISO_1980_01_01T13_20_00_000, 1)).toBe(
836
+ "1979-12-25T13:20:00.000",
837
+ );
838
+ expect(TimestampUtil.subtractMonths(ISO_1980_01_01T13_20_00_000, 1)).toBe(
839
+ "1979-12-01T13:20:00.000",
840
+ );
841
+ expect(TimestampUtil.subtractYears(ISO_1980_01_01T13_20_00_000, 1)).toBe(
842
+ "1979-01-01T13:20:00.000",
843
+ );
844
+ });
845
+
846
+ test("Individual getters and setters", () => {
847
+ expect(TimestampUtil.getHours(ISO_1980_01_01T13_20_00_000)).toBe(13);
848
+ expect(TimestampUtil.getMinutes(ISO_1980_01_01T13_20_00_000)).toBe(20);
849
+ expect(TimestampUtil.setSecond(ISO_1980_01_01T13_20_00_000, 22)).toBe(
850
+ "1980-01-01T13:20:22.000",
851
+ );
852
+ expect(TimestampUtil.setMinute(ISO_1980_01_01T13_20_00_000, 22)).toBe(
853
+ "1980-01-01T13:22:00.000",
854
+ );
855
+ expect(TimestampUtil.setHour(ISO_1980_01_01T13_20_00_000, 22)).toBe(
856
+ "1980-01-01T22:20:00.000",
857
+ );
858
+ expect(TimestampUtil.setMonth(ISO_1980_01_01T13_20_00_000, 6)).toBe(
859
+ "1980-07-01T13:20:00.000",
860
+ );
861
+ expect(TimestampUtil.setYear(ISO_1980_01_01T13_20_00_000, 1986)).toBe(
862
+ "1986-01-01T13:20:00.000",
863
+ );
864
+ });
577
865
  });
578
866
  });