jsl-ui 9.28.3 → 9.28.4

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 (170) hide show
  1. package/lib/components/IntervalComponent.d.ts +17 -17
  2. package/lib/components/IntervalComponent.js +65 -65
  3. package/lib/components/auto-suggest/AutoSuggestComponent.d.ts +22 -22
  4. package/lib/components/auto-suggest/AutoSuggestComponent.js +47 -47
  5. package/lib/components/button/ButtonComponent.d.ts +18 -18
  6. package/lib/components/button/ButtonComponent.js +29 -29
  7. package/lib/components/checkbox/CheckBoxComponent.d.ts +28 -28
  8. package/lib/components/checkbox/CheckBoxComponent.js +81 -81
  9. package/lib/components/date/DateComponent.d.ts +32 -32
  10. package/lib/components/date/DateComponent.js +89 -89
  11. package/lib/components/date-range/DateRangeComponent.d.ts +35 -35
  12. package/lib/components/date-range/DateRangeComponent.js +121 -123
  13. package/lib/components/date-time/DateTimeComponent.d.ts +15 -15
  14. package/lib/components/date-time/DateTimeComponent.js +39 -39
  15. package/lib/components/dialog/DialogComponent.d.ts +67 -67
  16. package/lib/components/dialog/DialogComponent.js +192 -198
  17. package/lib/components/drop-down/DropDownComponent.d.ts +27 -27
  18. package/lib/components/drop-down/DropDownComponent.js +60 -60
  19. package/lib/components/expander/ExpanderComponent.d.ts +27 -27
  20. package/lib/components/expander/ExpanderComponent.js +87 -89
  21. package/lib/components/form-field/FormComponent.d.ts +12 -12
  22. package/lib/components/form-field/FormComponent.js +23 -23
  23. package/lib/components/form-field/FormFieldComponent.d.ts +39 -39
  24. package/lib/components/form-field/FormFieldComponent.js +138 -138
  25. package/lib/components/grid/GridComponent.d.ts +26 -26
  26. package/lib/components/grid/GridComponent.js +110 -110
  27. package/lib/components/input/InputComponent.d.ts +33 -33
  28. package/lib/components/input/InputComponent.js +126 -126
  29. package/lib/components/loading/LoadingComponent.d.ts +8 -8
  30. package/lib/components/loading/LoadingComponent.js +20 -20
  31. package/lib/components/navigation/NavigationComponent.d.ts +34 -34
  32. package/lib/components/navigation/NavigationComponent.js +47 -45
  33. package/lib/components/notification/Notification.d.ts +19 -19
  34. package/lib/components/notification/Notification.js +65 -65
  35. package/lib/components/number/NumberComponent.d.ts +26 -26
  36. package/lib/components/number/NumberComponent.js +80 -80
  37. package/lib/components/overlay/OverlayComponent.d.ts +27 -27
  38. package/lib/components/overlay/OverlayComponent.js +134 -137
  39. package/lib/components/progress/ProgressComponent.d.ts +18 -18
  40. package/lib/components/progress/ProgressComponent.js +40 -40
  41. package/lib/components/ribbon-menu/RibbonMenuComponent.d.ts +12 -12
  42. package/lib/components/ribbon-menu/RibbonMenuComponent.js +23 -23
  43. package/lib/components/select/SelectComponent.d.ts +79 -79
  44. package/lib/components/select/SelectComponent.js +352 -356
  45. package/lib/components/select/SelectDDAreaComponent.d.ts +32 -32
  46. package/lib/components/select/SelectDDAreaComponent.js +303 -303
  47. package/lib/components/slider/nouislider.d.ts +44 -44
  48. package/lib/components/slider/nouislider.js +2158 -2158
  49. package/lib/components/stack-panel/SplitterComponent.d.ts +21 -21
  50. package/lib/components/stack-panel/SplitterComponent.js +124 -124
  51. package/lib/components/stack-panel/StackPanelComponent.d.ts +20 -20
  52. package/lib/components/stack-panel/StackPanelComponent.js +50 -50
  53. package/lib/components/tabs/TabsComponent.d.ts +40 -40
  54. package/lib/components/tabs/TabsComponent.js +191 -200
  55. package/lib/components/time/TimeComponent.d.ts +29 -29
  56. package/lib/components/time/TimeComponent.js +102 -104
  57. package/lib/components/tree-view/TreeViewComponent.d.ts +23 -23
  58. package/lib/components/tree-view/TreeViewComponent.js +42 -43
  59. package/lib/components/virtual-render/VirtualRenderComponent.d.ts +30 -30
  60. package/lib/components/virtual-render/VirtualRenderComponent.js +90 -92
  61. package/lib/core/culture.d.ts +5 -5
  62. package/lib/core/culture.js +385 -385
  63. package/lib/core/date.d.ts +14 -14
  64. package/lib/core/date.js +346 -346
  65. package/lib/core/helper.d.ts +13 -13
  66. package/lib/core/helper.js +100 -100
  67. package/lib/core/jq.d.ts +37 -37
  68. package/lib/core/jq.js +362 -362
  69. package/lib/core/lang.d.ts +24 -24
  70. package/lib/core/lang.js +24 -24
  71. package/lib/core/numeric.d.ts +7 -7
  72. package/lib/core/numeric.js +139 -139
  73. package/lib/core/polyfills.js +22 -22
  74. package/lib/core.d.ts +6 -6
  75. package/lib/core.js +6 -6
  76. package/lib/grid/filterDialogs/dateRangeFilter.d.ts +7 -7
  77. package/lib/grid/filterDialogs/dateRangeFilter.js +106 -106
  78. package/lib/grid/filterDialogs/excelFilter.d.ts +9 -9
  79. package/lib/grid/filterDialogs/excelFilter.js +250 -250
  80. package/lib/grid/plugins/ext.overlay.d.ts +2 -2
  81. package/lib/grid/plugins/ext.overlay.js +295 -295
  82. package/lib/grid/plugins/slick.cellrangedecorator.d.ts +12 -12
  83. package/lib/grid/plugins/slick.cellrangedecorator.js +68 -68
  84. package/lib/grid/plugins/slick.cellrangeselector.d.ts +1 -1
  85. package/lib/grid/plugins/slick.cellrangeselector.js +144 -144
  86. package/lib/grid/plugins/slick.cellselectionmodel.d.ts +1 -1
  87. package/lib/grid/plugins/slick.cellselectionmodel.js +194 -194
  88. package/lib/grid/plugins/slick.headerbuttons.d.ts +55 -55
  89. package/lib/grid/plugins/slick.headerbuttons.js +156 -156
  90. package/lib/grid/plugins/slick.headermenu.d.ts +74 -74
  91. package/lib/grid/plugins/slick.headermenu.js +260 -260
  92. package/lib/grid/plugins/slick.rowmovemanager.d.ts +18 -18
  93. package/lib/grid/plugins/slick.rowmovemanager.js +249 -249
  94. package/lib/grid/plugins/slick.rowselectionmodel.d.ts +1 -1
  95. package/lib/grid/plugins/slick.rowselectionmodel.js +167 -167
  96. package/lib/grid/slick.core.d.ts +91 -91
  97. package/lib/grid/slick.core.js +574 -574
  98. package/lib/grid/slick.creator.d.ts +81 -81
  99. package/lib/grid/slick.creator.js +726 -726
  100. package/lib/grid/slick.dataview.d.ts +71 -71
  101. package/lib/grid/slick.dataview.js +1069 -1069
  102. package/lib/grid/slick.editors.core.d.ts +4 -4
  103. package/lib/grid/slick.editors.core.js +235 -235
  104. package/lib/grid/slick.editors.date.d.ts +2 -2
  105. package/lib/grid/slick.editors.date.js +125 -125
  106. package/lib/grid/slick.editors.lookup.d.ts +14 -14
  107. package/lib/grid/slick.editors.lookup.js +352 -352
  108. package/lib/grid/slick.editors.nav.d.ts +6 -6
  109. package/lib/grid/slick.editors.nav.js +22 -22
  110. package/lib/grid/slick.formatters.d.ts +17 -17
  111. package/lib/grid/slick.formatters.js +144 -144
  112. package/lib/grid/slick.grid.d.ts +285 -285
  113. package/lib/grid/slick.grid.js +5409 -5409
  114. package/lib/grid/slick.groupitemmetadataprovider.d.ts +39 -39
  115. package/lib/grid/slick.groupitemmetadataprovider.js +165 -165
  116. package/lib/grid/slick.tree.d.ts +33 -33
  117. package/lib/grid/slick.tree.js +208 -208
  118. package/lib/grid.css +705 -1
  119. package/lib/grid.d.ts +13 -13
  120. package/lib/grid.js +13 -13
  121. package/lib/index.css +2195 -8
  122. package/lib/index.css.map +1 -1
  123. package/lib/index.d.ts +55 -56
  124. package/lib/index.js +61 -61
  125. package/lib/index.js.map +1 -1
  126. package/lib/interaction/dataconverter.d.ts +4 -4
  127. package/lib/interaction/dataconverter.js +1 -0
  128. package/lib/interaction/eventhandler.d.ts +13 -13
  129. package/lib/interaction/eventhandler.js +39 -39
  130. package/lib/interaction/moveable.d.ts +39 -39
  131. package/lib/interaction/moveable.js +160 -160
  132. package/lib/interaction/resizable.d.ts +37 -37
  133. package/lib/interaction/resizable.js +109 -109
  134. package/lib/ui/auto.suggest.d.ts +18 -18
  135. package/lib/ui/auto.suggest.js +244 -244
  136. package/lib/ui/date.picker/date-picker-options.d.ts +11 -11
  137. package/lib/ui/date.picker/date-picker-options.js +76 -76
  138. package/lib/ui/date.picker/lib/date-manip.d.ts +74 -74
  139. package/lib/ui/date.picker/lib/date-manip.js +120 -120
  140. package/lib/ui/date.picker/lib/dom.d.ts +23 -23
  141. package/lib/ui/date.picker/lib/dom.js +28 -28
  142. package/lib/ui/date.picker/lib/emitter.d.ts +13 -13
  143. package/lib/ui/date.picker/lib/emitter.js +49 -49
  144. package/lib/ui/date.picker/lib/fns.d.ts +23 -23
  145. package/lib/ui/date.picker/lib/fns.js +39 -39
  146. package/lib/ui/date.picker/mode/base-mode.d.ts +26 -26
  147. package/lib/ui/date.picker/mode/base-mode.js +248 -248
  148. package/lib/ui/date.picker/mode/dropdown-mode.d.ts +28 -28
  149. package/lib/ui/date.picker/mode/dropdown-mode.js +50 -50
  150. package/lib/ui/date.picker/mode/index.d.ts +28 -28
  151. package/lib/ui/date.picker/mode/index.js +18 -18
  152. package/lib/ui/date.picker/mode/modal-mode.d.ts +25 -25
  153. package/lib/ui/date.picker/mode/modal-mode.js +17 -17
  154. package/lib/ui/date.picker/mode/permanent-mode.d.ts +29 -29
  155. package/lib/ui/date.picker/mode/permanent-mode.js +19 -19
  156. package/lib/ui/date.picker/views/day-picker.d.ts +40 -40
  157. package/lib/ui/date.picker/views/day-picker.js +155 -155
  158. package/lib/ui/date.picker/views/month-picker.d.ts +26 -26
  159. package/lib/ui/date.picker/views/month-picker.js +65 -65
  160. package/lib/ui/date.picker/views/year-picker.d.ts +20 -20
  161. package/lib/ui/date.picker/views/year-picker.js +66 -66
  162. package/lib/ui/date.picker.d.ts +66 -66
  163. package/lib/ui/date.picker.js +32 -32
  164. package/lib/ui/dialog.d.ts +22 -22
  165. package/lib/ui/dialog.js +98 -98
  166. package/lib/ui/drop.down.d.ts +52 -52
  167. package/lib/ui/drop.down.js +2112 -2112
  168. package/lib/ui/number.input.d.ts +13 -13
  169. package/lib/ui/number.input.js +56 -56
  170. package/package.json +1 -1
package/lib/core/date.js CHANGED
@@ -1,346 +1,346 @@
1
- import culture from "./culture";
2
- /*
3
- * contains function to parse and format numeric values
4
- */
5
- //*** all following parts are extracted out of jquery-ui library (GPL/MIT license) ***/
6
- var _helper = {
7
- _defaults: { shortYearCutoff: "+10", dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] },
8
- _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
9
- _daylightSavingAdjust(date) {
10
- if (!date) {
11
- return null;
12
- }
13
- date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
14
- return date;
15
- },
16
- _getDaysInMonth(year, month) {
17
- return 32 - _helper._daylightSavingAdjust(new Date(year, month, 32)).getDate();
18
- }
19
- };
20
- export class date {
21
- /* Parse a string value into a date object.
22
- See formatDate below for the possible formats.
23
-
24
- @param format string - the expected format of the date
25
- @param value string - the date in the above format
26
- @param settings Object - attributes include:
27
- shortYearCutoff number - the cutoff year for determining the century (optional)
28
- dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
29
- dayNames string[7] - names of the days from Sunday (optional)
30
- monthNamesShort string[12] - abbreviated names of the months (optional)
31
- monthNames string[12] - names of the months (optional)
32
- @return Date - the extracted date value or null if value is blank */
33
- static parse(value, format, settings) {
34
- if (value === null) {
35
- return null;
36
- }
37
- if (value === undefined) {
38
- return undefined;
39
- }
40
- if (value == "") {
41
- return null;
42
- }
43
- format = format || culture.info.dateFormat;
44
- //value = (typeof value == 'object' ? value.toString() : value + '');
45
- let shortYearCutoff = (settings ? settings.shortYearCutoff : null) || _helper._defaults.shortYearCutoff;
46
- shortYearCutoff = (typeof shortYearCutoff != "string" ? shortYearCutoff :
47
- new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
48
- let dayNamesShort = (settings ? settings.dayNamesShort : null) || _helper._defaults.dayNamesShort;
49
- let dayNames = (settings ? settings.dayNames : null) || _helper._defaults.dayNames;
50
- let monthNamesShort = (settings ? settings.monthNamesShort : null) || _helper._defaults.monthNamesShort;
51
- let monthNames = (settings ? settings.monthNames : null) || _helper._defaults.monthNames;
52
- let year = -1;
53
- let month = -1;
54
- let day = -1;
55
- let doy = -1;
56
- let literal = false;
57
- // Check whether a format character is doubled
58
- let lookAhead = function (match) {
59
- let matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
60
- if (matches) {
61
- iFormat++;
62
- }
63
- return matches;
64
- };
65
- // Extract a number from the string value
66
- let getNumber = function (match) {
67
- let isDoubled = lookAhead(match);
68
- let size = (match == "@" ? 14 : (match == "!" ? 20 :
69
- (match == "y" && isDoubled ? 4 : (match == "o" ? 3 : 2))));
70
- let digits = new RegExp("^\\d{1," + size + "}");
71
- let num = value.substring(iValue).match(digits);
72
- if (!num) {
73
- throw "Missing number at position " + iValue;
74
- }
75
- iValue += num[0].length;
76
- return parseInt(num[0], 10);
77
- };
78
- // Extract a name from the string value and convert to an index
79
- let getName = function (match, shortNames, longNames) {
80
- let names = (lookAhead(match) ? longNames : shortNames);
81
- for (let i = 0; i < names.length; i++) {
82
- if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
83
- iValue += names[i].length;
84
- return i + 1;
85
- }
86
- }
87
- throw new Error("Unknown name at position " + iValue);
88
- };
89
- // Confirm that a literal character matches the string value
90
- let checkLiteral = function () {
91
- if (value.charAt(iValue) != format.charAt(iFormat)) {
92
- throw "Unexpected literal at position " + iValue;
93
- }
94
- iValue++;
95
- };
96
- let iValue = 0;
97
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
98
- if (literal) {
99
- if (format.charAt(iFormat) == "'" && !lookAhead("'")) {
100
- literal = false;
101
- }
102
- else {
103
- checkLiteral();
104
- }
105
- }
106
- else {
107
- switch (format.charAt(iFormat)) {
108
- case "d":
109
- day = getNumber("d");
110
- break;
111
- case "D":
112
- getName("D", dayNamesShort, dayNames);
113
- break;
114
- case "o":
115
- doy = getNumber("o");
116
- break;
117
- case "m":
118
- month = getNumber("m");
119
- break;
120
- case "M":
121
- month = getName("M", monthNamesShort, monthNames);
122
- break;
123
- case "y":
124
- year = getNumber("y");
125
- break;
126
- case "@":
127
- var date = new Date(getNumber("@"));
128
- year = date.getFullYear();
129
- month = date.getMonth() + 1;
130
- day = date.getDate();
131
- break;
132
- case "!":
133
- var date = new Date((getNumber("!") - _helper._ticksTo1970) / 10000);
134
- year = date.getFullYear();
135
- month = date.getMonth() + 1;
136
- day = date.getDate();
137
- break;
138
- case "'":
139
- if (lookAhead("'")) {
140
- checkLiteral();
141
- }
142
- else {
143
- literal = true;
144
- }
145
- break;
146
- default:
147
- checkLiteral();
148
- }
149
- }
150
- }
151
- if (year == -1) {
152
- year = new Date().getFullYear();
153
- }
154
- else if (year < 100) {
155
- year += new Date().getFullYear() - new Date().getFullYear() % 100 +
156
- (year <= shortYearCutoff ? 0 : -100);
157
- }
158
- if (doy > -1) {
159
- month = 1;
160
- day = doy;
161
- do {
162
- let dim = _helper._getDaysInMonth(year, month - 1);
163
- if (day <= dim) {
164
- break;
165
- }
166
- month++;
167
- day -= dim;
168
- } while (true);
169
- }
170
- let result = _helper._daylightSavingAdjust(new Date(year, month - 1, day));
171
- if (result.getFullYear() != year || result.getMonth() + 1 != month || result.getDate() != day) {
172
- throw new Error("Invalid date");
173
- } // E.g. 31/02/*
174
- return result;
175
- }
176
- /* Format a date object into a string value.
177
- The format can be combinations of the following:
178
- d - day of month (no leading zero)
179
- dd - day of month (two digit)
180
- o - day of year (no leading zeros)
181
- oo - day of year (three digit)
182
- D - day name short
183
- DD - day name long
184
- m - month of year (no leading zero)
185
- mm - month of year (two digit)
186
- M - month name short
187
- MM - month name long
188
- y - year (two digit)
189
- yy - year (four digit)
190
- @ - Unix timestamp (ms since 01/01/1970)
191
- ! - Windows ticks (100ns since 01/01/0001)
192
- '...' - literal text
193
- '' - single quote
194
-
195
- @param format string - the desired format of the date
196
- @param date Date - the date value to format
197
- @param settings Object - attributes include:
198
- dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
199
- dayNames string[7] - names of the days from Sunday (optional)
200
- monthNamesShort string[12] - abbreviated names of the months (optional)
201
- monthNames string[12] - names of the months (optional)
202
- @return string - the date in the above format */
203
- static format(date, format, settings) {
204
- if (!date || isNaN(date)) {
205
- return "";
206
- }
207
- format = format || culture.info.dateFormat;
208
- let dayNamesShort = (settings ? settings.dayNamesShort : null) || _helper._defaults.dayNamesShort;
209
- let dayNames = (settings ? settings.dayNames : null) || _helper._defaults.dayNames;
210
- let monthNamesShort = (settings ? settings.monthNamesShort : null) || _helper._defaults.monthNamesShort;
211
- let monthNames = (settings ? settings.monthNames : null) || _helper._defaults.monthNames;
212
- // Check whether a format character is doubled
213
- let lookAhead = function (match) {
214
- let matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
215
- if (matches) {
216
- iFormat++;
217
- }
218
- return matches;
219
- };
220
- // Format a number, with leading zero if necessary
221
- let formatNumber = function (match, value, len) {
222
- let num = "" + value;
223
- if (lookAhead(match)) {
224
- while (num.length < len) {
225
- num = "0" + num;
226
- }
227
- }
228
- return num;
229
- };
230
- // Format a name, short or long as requested
231
- let formatName = function (match, value, shortNames, longNames) {
232
- return (lookAhead(match) ? longNames[value] : shortNames[value]);
233
- };
234
- let output = "";
235
- let literal = false;
236
- if (date) {
237
- for (var iFormat = 0; iFormat < format.length; iFormat++) {
238
- if (literal) {
239
- if (format.charAt(iFormat) == "'" && !lookAhead("'")) {
240
- literal = false;
241
- }
242
- else {
243
- output += format.charAt(iFormat);
244
- }
245
- }
246
- else {
247
- switch (format.charAt(iFormat)) {
248
- case "d":
249
- output += formatNumber("d", date.getDate(), 2);
250
- break;
251
- case "D":
252
- output += formatName("D", date.getDay(), dayNamesShort, dayNames);
253
- break;
254
- case "o":
255
- output += formatNumber("o", (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000, 3);
256
- break;
257
- case "m":
258
- output += formatNumber("m", date.getMonth() + 1, 2);
259
- break;
260
- case "M":
261
- output += formatName("M", date.getMonth(), monthNamesShort, monthNames);
262
- break;
263
- case "y":
264
- output += (lookAhead("y") ? date.getFullYear() :
265
- (date.getFullYear() % 100 < 10 ? "0" : "") + date.getFullYear() % 100);
266
- break;
267
- case "@":
268
- output += date.getTime();
269
- break;
270
- case "!":
271
- output += date.getTime() * 10000 + _helper._ticksTo1970;
272
- break;
273
- case "'":
274
- if (lookAhead("'")) {
275
- output += "'";
276
- }
277
- else {
278
- literal = true;
279
- }
280
- break;
281
- default:
282
- output += format.charAt(iFormat);
283
- }
284
- }
285
- }
286
- }
287
- return output;
288
- }
289
- static formatTime(value, inputMode) {
290
- if (inputMode === "HourMinute") {
291
- return value ? (pad(value.getHours()) + ":" + pad(value.getMinutes())) : "";
292
- }
293
- else if (inputMode === "HourMinuteSecond") {
294
- return value ? (pad(value.getHours()) + ":" + pad(value.getMinutes()) + ":" + pad(value.getSeconds())) : "";
295
- }
296
- return "";
297
- }
298
- static now() {
299
- return new Date();
300
- }
301
- static addSeconds(d, seconds) {
302
- const future = new Date(d);
303
- future.setSeconds(d.getSeconds() + seconds);
304
- return future;
305
- }
306
- static addMinutes(d, minutes) {
307
- const future = new Date(d);
308
- future.setMinutes(d.getMinutes() + minutes);
309
- return future;
310
- }
311
- static addHours(d, hours) {
312
- const future = new Date(d);
313
- future.setHours(d.getHours() + hours);
314
- return future;
315
- }
316
- static addDays(d, days) {
317
- const future = new Date(d);
318
- future.setDate(d.getDate() + days);
319
- return future;
320
- }
321
- static getDaysBetween(startDate, endDate) {
322
- return Math.round((endDate - startDate) / (1000.0 * 3600.0 * 24.0));
323
- }
324
- static getMsBetween(startDate, endDate) {
325
- return endDate.getTime() - startDate.getTime();
326
- }
327
- static onlyDate(d) {
328
- if (d == null) {
329
- return d;
330
- }
331
- const result = new Date(d);
332
- result.setHours(0, 0, 0, 0);
333
- return result;
334
- }
335
- static equal(date1, date2) {
336
- return (date1 && date1.getTime()) === (date2 && date2.getTime());
337
- }
338
- }
339
- function pad(nr) {
340
- if (nr < 10) {
341
- return "0" + nr.toString();
342
- }
343
- else {
344
- return nr.toString();
345
- }
346
- }
1
+ import culture from "./culture";
2
+ /*
3
+ * contains function to parse and format numeric values
4
+ */
5
+ //*** all following parts are extracted out of jquery-ui library (GPL/MIT license) ***/
6
+ var _helper = {
7
+ _defaults: { shortYearCutoff: "+10", dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] },
8
+ _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
9
+ _daylightSavingAdjust(date) {
10
+ if (!date) {
11
+ return null;
12
+ }
13
+ date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
14
+ return date;
15
+ },
16
+ _getDaysInMonth(year, month) {
17
+ return 32 - _helper._daylightSavingAdjust(new Date(year, month, 32)).getDate();
18
+ }
19
+ };
20
+ export class date {
21
+ /* Parse a string value into a date object.
22
+ See formatDate below for the possible formats.
23
+
24
+ @param format string - the expected format of the date
25
+ @param value string - the date in the above format
26
+ @param settings Object - attributes include:
27
+ shortYearCutoff number - the cutoff year for determining the century (optional)
28
+ dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
29
+ dayNames string[7] - names of the days from Sunday (optional)
30
+ monthNamesShort string[12] - abbreviated names of the months (optional)
31
+ monthNames string[12] - names of the months (optional)
32
+ @return Date - the extracted date value or null if value is blank */
33
+ static parse(value, format, settings) {
34
+ if (value === null) {
35
+ return null;
36
+ }
37
+ if (value === undefined) {
38
+ return undefined;
39
+ }
40
+ if (value == "") {
41
+ return null;
42
+ }
43
+ format = format || culture.info.dateFormat;
44
+ //value = (typeof value == 'object' ? value.toString() : value + '');
45
+ let shortYearCutoff = (settings ? settings.shortYearCutoff : null) || _helper._defaults.shortYearCutoff;
46
+ shortYearCutoff = (typeof shortYearCutoff != "string" ? shortYearCutoff :
47
+ new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
48
+ let dayNamesShort = (settings ? settings.dayNamesShort : null) || _helper._defaults.dayNamesShort;
49
+ let dayNames = (settings ? settings.dayNames : null) || _helper._defaults.dayNames;
50
+ let monthNamesShort = (settings ? settings.monthNamesShort : null) || _helper._defaults.monthNamesShort;
51
+ let monthNames = (settings ? settings.monthNames : null) || _helper._defaults.monthNames;
52
+ let year = -1;
53
+ let month = -1;
54
+ let day = -1;
55
+ let doy = -1;
56
+ let literal = false;
57
+ // Check whether a format character is doubled
58
+ let lookAhead = function (match) {
59
+ let matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
60
+ if (matches) {
61
+ iFormat++;
62
+ }
63
+ return matches;
64
+ };
65
+ // Extract a number from the string value
66
+ let getNumber = function (match) {
67
+ let isDoubled = lookAhead(match);
68
+ let size = (match == "@" ? 14 : (match == "!" ? 20 :
69
+ (match == "y" && isDoubled ? 4 : (match == "o" ? 3 : 2))));
70
+ let digits = new RegExp("^\\d{1," + size + "}");
71
+ let num = value.substring(iValue).match(digits);
72
+ if (!num) {
73
+ throw "Missing number at position " + iValue;
74
+ }
75
+ iValue += num[0].length;
76
+ return parseInt(num[0], 10);
77
+ };
78
+ // Extract a name from the string value and convert to an index
79
+ let getName = function (match, shortNames, longNames) {
80
+ let names = (lookAhead(match) ? longNames : shortNames);
81
+ for (let i = 0; i < names.length; i++) {
82
+ if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
83
+ iValue += names[i].length;
84
+ return i + 1;
85
+ }
86
+ }
87
+ throw new Error("Unknown name at position " + iValue);
88
+ };
89
+ // Confirm that a literal character matches the string value
90
+ let checkLiteral = function () {
91
+ if (value.charAt(iValue) != format.charAt(iFormat)) {
92
+ throw "Unexpected literal at position " + iValue;
93
+ }
94
+ iValue++;
95
+ };
96
+ let iValue = 0;
97
+ for (var iFormat = 0; iFormat < format.length; iFormat++) {
98
+ if (literal) {
99
+ if (format.charAt(iFormat) == "'" && !lookAhead("'")) {
100
+ literal = false;
101
+ }
102
+ else {
103
+ checkLiteral();
104
+ }
105
+ }
106
+ else {
107
+ switch (format.charAt(iFormat)) {
108
+ case "d":
109
+ day = getNumber("d");
110
+ break;
111
+ case "D":
112
+ getName("D", dayNamesShort, dayNames);
113
+ break;
114
+ case "o":
115
+ doy = getNumber("o");
116
+ break;
117
+ case "m":
118
+ month = getNumber("m");
119
+ break;
120
+ case "M":
121
+ month = getName("M", monthNamesShort, monthNames);
122
+ break;
123
+ case "y":
124
+ year = getNumber("y");
125
+ break;
126
+ case "@":
127
+ var date = new Date(getNumber("@"));
128
+ year = date.getFullYear();
129
+ month = date.getMonth() + 1;
130
+ day = date.getDate();
131
+ break;
132
+ case "!":
133
+ var date = new Date((getNumber("!") - _helper._ticksTo1970) / 10000);
134
+ year = date.getFullYear();
135
+ month = date.getMonth() + 1;
136
+ day = date.getDate();
137
+ break;
138
+ case "'":
139
+ if (lookAhead("'")) {
140
+ checkLiteral();
141
+ }
142
+ else {
143
+ literal = true;
144
+ }
145
+ break;
146
+ default:
147
+ checkLiteral();
148
+ }
149
+ }
150
+ }
151
+ if (year == -1) {
152
+ year = new Date().getFullYear();
153
+ }
154
+ else if (year < 100) {
155
+ year += new Date().getFullYear() - new Date().getFullYear() % 100 +
156
+ (year <= shortYearCutoff ? 0 : -100);
157
+ }
158
+ if (doy > -1) {
159
+ month = 1;
160
+ day = doy;
161
+ do {
162
+ let dim = _helper._getDaysInMonth(year, month - 1);
163
+ if (day <= dim) {
164
+ break;
165
+ }
166
+ month++;
167
+ day -= dim;
168
+ } while (true);
169
+ }
170
+ let result = _helper._daylightSavingAdjust(new Date(year, month - 1, day));
171
+ if (result.getFullYear() != year || result.getMonth() + 1 != month || result.getDate() != day) {
172
+ throw new Error("Invalid date");
173
+ } // E.g. 31/02/*
174
+ return result;
175
+ }
176
+ /* Format a date object into a string value.
177
+ The format can be combinations of the following:
178
+ d - day of month (no leading zero)
179
+ dd - day of month (two digit)
180
+ o - day of year (no leading zeros)
181
+ oo - day of year (three digit)
182
+ D - day name short
183
+ DD - day name long
184
+ m - month of year (no leading zero)
185
+ mm - month of year (two digit)
186
+ M - month name short
187
+ MM - month name long
188
+ y - year (two digit)
189
+ yy - year (four digit)
190
+ @ - Unix timestamp (ms since 01/01/1970)
191
+ ! - Windows ticks (100ns since 01/01/0001)
192
+ '...' - literal text
193
+ '' - single quote
194
+
195
+ @param format string - the desired format of the date
196
+ @param date Date - the date value to format
197
+ @param settings Object - attributes include:
198
+ dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
199
+ dayNames string[7] - names of the days from Sunday (optional)
200
+ monthNamesShort string[12] - abbreviated names of the months (optional)
201
+ monthNames string[12] - names of the months (optional)
202
+ @return string - the date in the above format */
203
+ static format(date, format, settings) {
204
+ if (!date || isNaN(date)) {
205
+ return "";
206
+ }
207
+ format = format || culture.info.dateFormat;
208
+ let dayNamesShort = (settings ? settings.dayNamesShort : null) || _helper._defaults.dayNamesShort;
209
+ let dayNames = (settings ? settings.dayNames : null) || _helper._defaults.dayNames;
210
+ let monthNamesShort = (settings ? settings.monthNamesShort : null) || _helper._defaults.monthNamesShort;
211
+ let monthNames = (settings ? settings.monthNames : null) || _helper._defaults.monthNames;
212
+ // Check whether a format character is doubled
213
+ let lookAhead = function (match) {
214
+ let matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
215
+ if (matches) {
216
+ iFormat++;
217
+ }
218
+ return matches;
219
+ };
220
+ // Format a number, with leading zero if necessary
221
+ let formatNumber = function (match, value, len) {
222
+ let num = "" + value;
223
+ if (lookAhead(match)) {
224
+ while (num.length < len) {
225
+ num = "0" + num;
226
+ }
227
+ }
228
+ return num;
229
+ };
230
+ // Format a name, short or long as requested
231
+ let formatName = function (match, value, shortNames, longNames) {
232
+ return (lookAhead(match) ? longNames[value] : shortNames[value]);
233
+ };
234
+ let output = "";
235
+ let literal = false;
236
+ if (date) {
237
+ for (var iFormat = 0; iFormat < format.length; iFormat++) {
238
+ if (literal) {
239
+ if (format.charAt(iFormat) == "'" && !lookAhead("'")) {
240
+ literal = false;
241
+ }
242
+ else {
243
+ output += format.charAt(iFormat);
244
+ }
245
+ }
246
+ else {
247
+ switch (format.charAt(iFormat)) {
248
+ case "d":
249
+ output += formatNumber("d", date.getDate(), 2);
250
+ break;
251
+ case "D":
252
+ output += formatName("D", date.getDay(), dayNamesShort, dayNames);
253
+ break;
254
+ case "o":
255
+ output += formatNumber("o", (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000, 3);
256
+ break;
257
+ case "m":
258
+ output += formatNumber("m", date.getMonth() + 1, 2);
259
+ break;
260
+ case "M":
261
+ output += formatName("M", date.getMonth(), monthNamesShort, monthNames);
262
+ break;
263
+ case "y":
264
+ output += (lookAhead("y") ? date.getFullYear() :
265
+ (date.getFullYear() % 100 < 10 ? "0" : "") + date.getFullYear() % 100);
266
+ break;
267
+ case "@":
268
+ output += date.getTime();
269
+ break;
270
+ case "!":
271
+ output += date.getTime() * 10000 + _helper._ticksTo1970;
272
+ break;
273
+ case "'":
274
+ if (lookAhead("'")) {
275
+ output += "'";
276
+ }
277
+ else {
278
+ literal = true;
279
+ }
280
+ break;
281
+ default:
282
+ output += format.charAt(iFormat);
283
+ }
284
+ }
285
+ }
286
+ }
287
+ return output;
288
+ }
289
+ static formatTime(value, inputMode) {
290
+ if (inputMode === "HourMinute") {
291
+ return value ? (pad(value.getHours()) + ":" + pad(value.getMinutes())) : "";
292
+ }
293
+ else if (inputMode === "HourMinuteSecond") {
294
+ return value ? (pad(value.getHours()) + ":" + pad(value.getMinutes()) + ":" + pad(value.getSeconds())) : "";
295
+ }
296
+ return "";
297
+ }
298
+ static now() {
299
+ return new Date();
300
+ }
301
+ static addSeconds(d, seconds) {
302
+ const future = new Date(d);
303
+ future.setSeconds(d.getSeconds() + seconds);
304
+ return future;
305
+ }
306
+ static addMinutes(d, minutes) {
307
+ const future = new Date(d);
308
+ future.setMinutes(d.getMinutes() + minutes);
309
+ return future;
310
+ }
311
+ static addHours(d, hours) {
312
+ const future = new Date(d);
313
+ future.setHours(d.getHours() + hours);
314
+ return future;
315
+ }
316
+ static addDays(d, days) {
317
+ const future = new Date(d);
318
+ future.setDate(d.getDate() + days);
319
+ return future;
320
+ }
321
+ static getDaysBetween(startDate, endDate) {
322
+ return Math.round((endDate - startDate) / (1000.0 * 3600.0 * 24.0));
323
+ }
324
+ static getMsBetween(startDate, endDate) {
325
+ return endDate.getTime() - startDate.getTime();
326
+ }
327
+ static onlyDate(d) {
328
+ if (d == null) {
329
+ return d;
330
+ }
331
+ const result = new Date(d);
332
+ result.setHours(0, 0, 0, 0);
333
+ return result;
334
+ }
335
+ static equal(date1, date2) {
336
+ return (date1 && date1.getTime()) === (date2 && date2.getTime());
337
+ }
338
+ }
339
+ function pad(nr) {
340
+ if (nr < 10) {
341
+ return "0" + nr.toString();
342
+ }
343
+ else {
344
+ return nr.toString();
345
+ }
346
+ }