jsl-ui 9.28.2 → 9.28.3

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