eoss 0.1.0-alpha.39 → 0.1.0-alpha.40

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 (233) hide show
  1. package/lib/0.js +1 -1
  2. package/lib/1.js +1 -1
  3. package/lib/10.js +1 -1
  4. package/lib/11.js +1 -1
  5. package/lib/12.js +1 -1
  6. package/lib/13.js +1 -1
  7. package/lib/14.js +1 -1
  8. package/lib/15.js +1 -1
  9. package/lib/16.js +1 -1
  10. package/lib/17.js +1 -1
  11. package/lib/18.js +1 -1
  12. package/lib/19.js +1 -1
  13. package/lib/20.js +1 -1
  14. package/lib/21.js +1 -1
  15. package/lib/22.js +1 -1
  16. package/lib/23.js +1 -1
  17. package/lib/24.js +1 -1
  18. package/lib/25.js +1 -1
  19. package/lib/26.js +1 -1
  20. package/lib/27.js +1 -1
  21. package/lib/28.js +1 -1
  22. package/lib/29.js +1 -1
  23. package/lib/3.js +1 -1
  24. package/lib/30.js +1 -1
  25. package/lib/31.js +1 -1
  26. package/lib/32.js +1 -1
  27. package/lib/33.js +1 -1
  28. package/lib/34.js +1 -1
  29. package/lib/35.js +1 -1
  30. package/lib/36.js +1 -1
  31. package/lib/37.js +1 -1
  32. package/lib/38.js +1 -1
  33. package/lib/39.js +1 -1
  34. package/lib/4.js +1 -1
  35. package/lib/40.js +1 -1
  36. package/lib/41.js +1 -1
  37. package/lib/42.js +1 -1
  38. package/lib/43.js +1 -1
  39. package/lib/44.js +1 -1
  40. package/lib/45.js +1 -1
  41. package/lib/46.js +1 -1
  42. package/lib/47.js +1 -1
  43. package/lib/48.js +1 -1
  44. package/lib/49.js +1 -1
  45. package/lib/5.js +1 -1
  46. package/lib/50.js +1 -1
  47. package/lib/51.js +1 -1
  48. package/lib/52.js +1 -1
  49. package/lib/53.js +1 -1
  50. package/lib/54.js +1 -1
  51. package/lib/55.js +1 -1
  52. package/lib/56.js +1 -1
  53. package/lib/57.js +1 -1
  54. package/lib/58.js +1 -1
  55. package/lib/59.js +1 -1
  56. package/lib/6.js +1 -1
  57. package/lib/60.js +1 -1
  58. package/lib/61.js +1 -1
  59. package/lib/62.js +1 -1
  60. package/lib/63.js +1 -1
  61. package/lib/64.js +1 -1
  62. package/lib/65.js +1 -1
  63. package/lib/66.js +1 -1
  64. package/lib/67.js +1 -1
  65. package/lib/68.js +1 -1
  66. package/lib/69.js +1 -1
  67. package/lib/7.js +1 -1
  68. package/lib/70.js +1 -1
  69. package/lib/71.js +1 -1
  70. package/lib/72.js +1 -1
  71. package/lib/73.js +1 -1
  72. package/lib/74.js +1 -1
  73. package/lib/75.js +1 -1
  74. package/lib/76.js +1 -1
  75. package/lib/77.js +1 -1
  76. package/lib/78.js +1 -1
  77. package/lib/79.js +1 -1
  78. package/lib/8.js +1 -1
  79. package/lib/80.js +1 -1
  80. package/lib/81.js +1 -1
  81. package/lib/9.js +1 -1
  82. package/lib/account-login.js +837 -862
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +4 -4
  86. package/lib/autocomplete.js +1813 -1988
  87. package/lib/avatar.js +2 -2
  88. package/lib/backtop.js +2 -2
  89. package/lib/badge.js +2 -2
  90. package/lib/breadcrumb-item.js +4 -4
  91. package/lib/breadcrumb.js +4 -4
  92. package/lib/button-group.js +4 -4
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +837 -862
  95. package/lib/calendar.js +839 -864
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +846 -871
  98. package/lib/carousel.js +839 -864
  99. package/lib/cascader-panel.js +852 -877
  100. package/lib/cascader.js +2048 -2223
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +859 -884
  103. package/lib/checkbox.js +4 -4
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +1040 -1065
  106. package/lib/collapse.js +1040 -1065
  107. package/lib/color-picker.js +972 -1122
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +12 -12
  110. package/lib/data-table.js +843 -868
  111. package/lib/date-picker.js +10520 -10695
  112. package/lib/descriptions-item.js +4 -4
  113. package/lib/descriptions.js +4 -4
  114. package/lib/dialog.js +837 -862
  115. package/lib/divider.js +2 -2
  116. package/lib/drawer.js +2 -2
  117. package/lib/dropdown-item.js +4 -4
  118. package/lib/dropdown-menu.js +974 -1124
  119. package/lib/dropdown.js +841 -866
  120. package/lib/email-login.js +837 -862
  121. package/lib/empty.js +2 -2
  122. package/lib/eoss.common.js +4023 -2668
  123. package/lib/flip.js +2 -2
  124. package/lib/flow-group.js +853 -878
  125. package/lib/flow.js +868 -893
  126. package/lib/flows.js +854 -879
  127. package/lib/footer.js +2 -2
  128. package/lib/form-item.js +860 -885
  129. package/lib/form.js +933 -950
  130. package/lib/guide.js +2 -2
  131. package/lib/header.js +2 -2
  132. package/lib/icon.js +837 -862
  133. package/lib/icons.js +2 -2
  134. package/lib/image-viewer.js +837 -862
  135. package/lib/image.js +4 -4
  136. package/lib/index.js +1 -1
  137. package/lib/infinite-scroll.js +2 -2
  138. package/lib/input-number.js +6 -6
  139. package/lib/input.js +839 -864
  140. package/lib/link.js +2 -2
  141. package/lib/loading.js +2 -2
  142. package/lib/login.js +867 -891
  143. package/lib/lowcode-view.js +1843 -1185
  144. package/lib/lowcode.js +3050 -1569
  145. package/lib/main.js +970 -988
  146. package/lib/marquee.js +837 -862
  147. package/lib/menu-item-group.js +15 -15
  148. package/lib/menu-item.js +6 -6
  149. package/lib/menu.js +2227 -2368
  150. package/lib/message-box.js +843 -868
  151. package/lib/message.js +839 -864
  152. package/lib/notification.js +861 -886
  153. package/lib/option-group.js +4 -4
  154. package/lib/option.js +839 -864
  155. package/lib/page-header.js +2 -2
  156. package/lib/pagination.js +839 -864
  157. package/lib/phone-login.js +847 -866
  158. package/lib/popconfirm.js +4 -4
  159. package/lib/popover.js +1831 -2006
  160. package/lib/process-config.js +839 -864
  161. package/lib/process-module.js +846 -871
  162. package/lib/process-rule.js +905 -930
  163. package/lib/progress.js +2 -2
  164. package/lib/qr-code.js +4 -4
  165. package/lib/qrcode-login.js +839 -864
  166. package/lib/radio-button.js +4 -4
  167. package/lib/radio-group.js +850 -875
  168. package/lib/radio.js +4 -4
  169. package/lib/rate.js +837 -862
  170. package/lib/retrial-auth.js +837 -862
  171. package/lib/row.js +2 -2
  172. package/lib/scrollbar.js +839 -864
  173. package/lib/select.js +2139 -2314
  174. package/lib/selector-panel.js +940 -965
  175. package/lib/selector.js +852 -877
  176. package/lib/slider.js +4 -4
  177. package/lib/step.js +32 -32
  178. package/lib/steps.js +874 -899
  179. package/lib/submenu.js +1269 -1385
  180. package/lib/switch.js +839 -864
  181. package/lib/tab-pane.js +4 -4
  182. package/lib/table-column.js +840 -865
  183. package/lib/table.js +1825 -2000
  184. package/lib/tabs.js +846 -871
  185. package/lib/tag.js +2 -2
  186. package/lib/theme-chalk/fonts/iconfont.ttf +0 -0
  187. package/lib/theme-chalk/fonts/iconfont.woff +0 -0
  188. package/lib/theme-chalk/index.css +1 -1
  189. package/lib/theme-chalk/lowcode.css +1 -1
  190. package/lib/time-picker.js +6471 -6646
  191. package/lib/time-select.js +5039 -5214
  192. package/lib/timeline-item.js +2 -2
  193. package/lib/timeline.js +2 -2
  194. package/lib/tips.js +837 -862
  195. package/lib/toolbar.js +4 -4
  196. package/lib/tooltip.js +1813 -1988
  197. package/lib/transfer.js +837 -862
  198. package/lib/tree-group.js +853 -878
  199. package/lib/tree.js +1026 -1051
  200. package/lib/update-history.js +4 -4
  201. package/lib/upload.js +859 -884
  202. package/lib/wujie.js +841 -866
  203. package/package.json +1 -1
  204. package/packages/flow-group/src/main.vue +2 -2
  205. package/packages/form/src/form-item-render.vue +1 -0
  206. package/packages/form/src/form-item.vue +12 -6
  207. package/packages/form/src/form.vue +5 -5
  208. package/packages/login/src/login.vue +1 -0
  209. package/packages/lowcode/src/attribute/function.vue +28 -9
  210. package/packages/lowcode/src/attribute/props.vue +202 -0
  211. package/packages/lowcode/src/attribute/styles.vue +79 -5
  212. package/packages/lowcode/src/attribute.vue +61 -4
  213. package/packages/lowcode/src/canvas.vue +159 -2
  214. package/packages/lowcode/src/form-render.vue +305 -0
  215. package/packages/lowcode/src/lowcode.vue +33 -13
  216. package/packages/lowcode/src/modules.vue +53 -37
  217. package/packages/lowcode/src/render.vue +80 -25
  218. package/packages/lowcode/src/util/components.js +100 -0
  219. package/packages/lowcode/src/util/props-util.js +67 -0
  220. package/packages/lowcode/src/util/source-generator.js +69 -9
  221. package/packages/lowcode/src/util/source-parser.js +64 -10
  222. package/packages/lowcode-view/src/render.vue +48 -18
  223. package/packages/main/src/components/userinfo.vue +0 -1
  224. package/packages/menu/src/menu-item-group.vue +1 -1
  225. package/packages/menu/src/mixins.js +8 -4
  226. package/packages/menu/src/submenu.vue +35 -5
  227. package/packages/phone-login/src/phone-login.vue +5 -2
  228. package/packages/theme-chalk/dist/fonts/iconfont.ttf +0 -0
  229. package/packages/theme-chalk/dist/fonts/iconfont.woff +0 -0
  230. package/packages/theme-chalk/src/fonts/iconfont.ttf +0 -0
  231. package/packages/theme-chalk/src/fonts/iconfont.woff +0 -0
  232. package/packages/theme-chalk/src/lowcode.scss +21 -2
  233. package/src/index.js +336 -336
package/lib/dropdown.js CHANGED
@@ -82,7 +82,7 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 235);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 242);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3568,7 +3568,7 @@ module.exports = require("vue");
3568
3568
 
3569
3569
  /***/ }),
3570
3570
 
3571
- /***/ 235:
3571
+ /***/ 242:
3572
3572
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3573
3573
 
3574
3574
  "use strict";
@@ -3692,11 +3692,11 @@ var button_ = __webpack_require__(13);
3692
3692
  var button_default = /*#__PURE__*/__webpack_require__.n(button_);
3693
3693
 
3694
3694
  // EXTERNAL MODULE: external "eoss/lib/button-group"
3695
- var button_group_ = __webpack_require__(53);
3695
+ var button_group_ = __webpack_require__(54);
3696
3696
  var button_group_default = /*#__PURE__*/__webpack_require__.n(button_group_);
3697
3697
 
3698
3698
  // EXTERNAL MODULE: external "eoss/lib/dropdown-menu"
3699
- var dropdown_menu_ = __webpack_require__(62);
3699
+ var dropdown_menu_ = __webpack_require__(63);
3700
3700
  var dropdown_menu_default = /*#__PURE__*/__webpack_require__.n(dropdown_menu_);
3701
3701
 
3702
3702
  // EXTERNAL MODULE: ./src/utils/util.js
@@ -5031,14 +5031,14 @@ function insertAfter(newEl, targetEl) {
5031
5031
 
5032
5032
  /***/ }),
5033
5033
 
5034
- /***/ 53:
5034
+ /***/ 54:
5035
5035
  /***/ (function(module, exports) {
5036
5036
 
5037
5037
  module.exports = require("eoss/lib/button-group");
5038
5038
 
5039
5039
  /***/ }),
5040
5040
 
5041
- /***/ 62:
5041
+ /***/ 63:
5042
5042
  /***/ (function(module, exports) {
5043
5043
 
5044
5044
  module.exports = require("eoss/lib/dropdown-menu");
@@ -5095,759 +5095,736 @@ module.exports = require("eoss/lib/dropdown-menu");
5095
5095
  /* unused harmony export getSecond */
5096
5096
  /* unused harmony export getWeekday */
5097
5097
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5098
- /* Modified from https://github.com/taylorhakes/fecha
5099
- *
5100
- * The MIT License (MIT)
5101
- *
5102
- * Copyright (c) 2015 Taylor Hakes
5103
- *
5104
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5105
- * of this software and associated documentation files (the "Software"), to deal
5106
- * in the Software without restriction, including without limitation the rights
5107
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5108
- * copies of the Software, and to permit persons to whom the Software is
5109
- * furnished to do so, subject to the following conditions:
5110
- *
5111
- * The above copyright notice and this permission notice shall be included in all
5112
- * copies or substantial portions of the Software.
5113
- *
5114
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5115
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5116
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5117
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5118
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5119
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5120
- * SOFTWARE.
5121
- */
5122
-
5123
- /*eslint-disable*/
5124
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5125
-
5126
-
5098
+
5099
+
5127
5100
  /**
5128
5101
  * Parse or format dates
5129
5102
  * @class fecha
5130
- */
5131
- const fecha = {};
5132
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5133
- const twoDigits = '\\d\\d?';
5134
- const threeDigits = '\\d{3}';
5135
- const fourDigits = '\\d{4}';
5136
- const word = '[^\\s]+';
5137
- const literal = /\[([^]*?)\]/gm;
5138
- const noop = function () {};
5139
-
5140
- function regexEscape(str) {
5141
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5142
- }
5143
-
5144
- function shorten(arr, sLen) {
5145
- const newArr = [];
5146
- for (let i = 0, len = arr.length; i < len; i++) {
5147
- newArr.push(arr[i].substr(0, sLen));
5148
- }
5149
- return newArr;
5150
- }
5151
-
5152
- function monthUpdate() {
5153
- return function (d, v) {
5154
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5155
- if (~index) {
5156
- d.month = index;
5157
- }
5158
- };
5159
- }
5160
-
5161
- function pad(val, len) {
5162
- val = String(val);
5163
- len = len || 2;
5164
- while (val.length < len) {
5165
- val = '0' + val;
5166
- }
5167
- return val;
5168
- }
5169
-
5170
- // 直接使用中文日期名称常量
5171
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5172
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5173
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5174
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5175
- const amPm = ['上午', '下午'];
5176
- const DoFn = function DoFn(D) {
5177
- return D + '日';
5178
- };
5179
-
5180
- const formatFlags = {
5181
- D: function(dateObj) {
5182
- return dateObj.getDay();
5183
- },
5184
- DD: function(dateObj) {
5185
- return pad(dateObj.getDay());
5186
- },
5187
- Do: function(dateObj) {
5188
- return DoFn(dateObj.getDate());
5189
- },
5190
- d: function(dateObj) {
5191
- return dateObj.getDate();
5192
- },
5193
- dd: function(dateObj) {
5194
- return pad(dateObj.getDate());
5195
- },
5196
- ddd: function(dateObj) {
5197
- return dayNamesShort[dateObj.getDay()];
5198
- },
5199
- dddd: function(dateObj) {
5200
- return dayNames[dateObj.getDay()];
5201
- },
5202
- M: function(dateObj) {
5203
- return dateObj.getMonth() + 1;
5204
- },
5205
- MM: function(dateObj) {
5206
- return pad(dateObj.getMonth() + 1);
5207
- },
5208
- MMM: function(dateObj) {
5209
- return monthNamesShort[dateObj.getMonth()];
5210
- },
5211
- MMMM: function(dateObj) {
5212
- return monthNames[dateObj.getMonth()];
5213
- },
5214
- yy: function(dateObj) {
5215
- return pad(String(dateObj.getFullYear()), 4).substr(2);
5216
- },
5217
- yyyy: function(dateObj) {
5218
- return pad(dateObj.getFullYear(), 4);
5219
- },
5220
- h: function(dateObj) {
5221
- return dateObj.getHours() % 12 || 12;
5222
- },
5223
- hh: function(dateObj) {
5224
- return pad(dateObj.getHours() % 12 || 12);
5225
- },
5226
- H: function(dateObj) {
5227
- return dateObj.getHours();
5228
- },
5229
- HH: function(dateObj) {
5230
- return pad(dateObj.getHours());
5231
- },
5232
- m: function(dateObj) {
5233
- return dateObj.getMinutes();
5234
- },
5235
- mm: function(dateObj) {
5236
- return pad(dateObj.getMinutes());
5237
- },
5238
- s: function(dateObj) {
5239
- return dateObj.getSeconds();
5240
- },
5241
- ss: function(dateObj) {
5242
- return pad(dateObj.getSeconds());
5243
- },
5244
- S: function(dateObj) {
5245
- return Math.round(dateObj.getMilliseconds() / 100);
5246
- },
5247
- SS: function(dateObj) {
5248
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5249
- },
5250
- SSS: function(dateObj) {
5251
- return pad(dateObj.getMilliseconds(), 3);
5252
- },
5253
- a: function(dateObj) {
5254
- return dateObj.getHours() < 12 ? '上午' : '下午';
5255
- },
5256
- A: function(dateObj) {
5257
- return dateObj.getHours() < 12 ? '上午' : '下午';
5258
- },
5259
- ZZ: function(dateObj) {
5260
- const o = dateObj.getTimezoneOffset();
5261
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5262
- }
5263
- };
5264
-
5265
- const parseFlags = {
5266
- d: [twoDigits, function (d, v) {
5267
- d.day = v;
5268
- }],
5269
- Do: [twoDigits + word, function (d, v) {
5270
- d.day = parseInt(v, 10);
5271
- }],
5272
- M: [twoDigits, function (d, v) {
5273
- d.month = v - 1;
5274
- }],
5275
- yy: [twoDigits, function (d, v) {
5276
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
5277
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5278
- }],
5279
- h: [twoDigits, function (d, v) {
5280
- d.hour = v;
5281
- }],
5282
- m: [twoDigits, function (d, v) {
5283
- d.minute = v;
5284
- }],
5285
- s: [twoDigits, function (d, v) {
5286
- d.second = v;
5287
- }],
5288
- yyyy: [fourDigits, function (d, v) {
5289
- d.year = v;
5290
- }],
5291
- S: ['\\d', function (d, v) {
5292
- d.millisecond = v * 100;
5293
- }],
5294
- SS: ['\\d{2}', function (d, v) {
5295
- d.millisecond = v * 10;
5296
- }],
5297
- SSS: [threeDigits, function (d, v) {
5298
- d.millisecond = v;
5299
- }],
5300
- D: [twoDigits, noop],
5301
- ddd: [word, noop],
5302
- MMM: [word, monthUpdate('monthNamesShort')],
5303
- MMMM: [word, monthUpdate('monthNames')],
5304
- a: [word, function (d, v) {
5305
- const val = v.toLowerCase();
5306
- if (val === '上午') {
5307
- d.isPm = false;
5308
- } else if (val === '下午') {
5309
- d.isPm = true;
5310
- }
5311
- }],
5312
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5313
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
5314
-
5315
- if (parts) {
5316
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5317
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5318
- }
5319
- }]
5320
- };
5321
- parseFlags.dd = parseFlags.d;
5322
- parseFlags.dddd = parseFlags.ddd;
5323
- parseFlags.DD = parseFlags.D;
5324
- parseFlags.mm = parseFlags.m;
5325
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5326
- parseFlags.MM = parseFlags.M;
5327
- parseFlags.ss = parseFlags.s;
5328
- parseFlags.A = parseFlags.a;
5329
-
5330
-
5331
- // Some common format strings
5332
- fecha.masks = {
5333
- default: 'ddd MMM dd yyyy HH:mm:ss',
5334
- shortDate: 'M/D/yy',
5335
- mediumDate: 'MMM d, yyyy',
5336
- longDate: 'MMMM d, yyyy',
5337
- fullDate: 'dddd, MMMM d, yyyy',
5338
- shortTime: 'HH:mm',
5339
- mediumTime: 'HH:mm:ss',
5340
- longTime: 'HH:mm:ss.SSS'
5341
- };
5342
-
5103
+ */
5104
+ var fecha = {};
5105
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5106
+ var twoDigits = '\\d\\d?';
5107
+ var threeDigits = '\\d{3}';
5108
+ var fourDigits = '\\d{4}';
5109
+ var word = '[^\\s]+';
5110
+ var literal = /\[([^]*?)\]/gm;
5111
+ var noop = function noop() {};
5112
+
5113
+ function regexEscape(str) {
5114
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5115
+ }
5116
+
5117
+ function shorten(arr, sLen) {
5118
+ var newArr = [];
5119
+ for (var i = 0, len = arr.length; i < len; i++) {
5120
+ newArr.push(arr[i].substr(0, sLen));
5121
+ }
5122
+ return newArr;
5123
+ }
5124
+
5125
+ function monthUpdate() {
5126
+ return function (d, v) {
5127
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5128
+ if (~index) {
5129
+ d.month = index;
5130
+ }
5131
+ };
5132
+ }
5133
+
5134
+ function pad(val, len) {
5135
+ val = String(val);
5136
+ len = len || 2;
5137
+ while (val.length < len) {
5138
+ val = '0' + val;
5139
+ }
5140
+ return val;
5141
+ }
5142
+
5143
+ // 直接使用中文日期名称常量
5144
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5145
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5146
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5147
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5148
+ var amPm = ['上午', '下午'];
5149
+ var DoFn = function DoFn(D) {
5150
+ return D + '日';
5151
+ };
5152
+
5153
+ var formatFlags = {
5154
+ D: function D(dateObj) {
5155
+ return dateObj.getDay();
5156
+ },
5157
+ DD: function DD(dateObj) {
5158
+ return pad(dateObj.getDay());
5159
+ },
5160
+ Do: function Do(dateObj) {
5161
+ return DoFn(dateObj.getDate());
5162
+ },
5163
+ d: function d(dateObj) {
5164
+ return dateObj.getDate();
5165
+ },
5166
+ dd: function dd(dateObj) {
5167
+ return pad(dateObj.getDate());
5168
+ },
5169
+ ddd: function ddd(dateObj) {
5170
+ return dayNamesShort[dateObj.getDay()];
5171
+ },
5172
+ dddd: function dddd(dateObj) {
5173
+ return dayNames[dateObj.getDay()];
5174
+ },
5175
+ M: function M(dateObj) {
5176
+ return dateObj.getMonth() + 1;
5177
+ },
5178
+ MM: function MM(dateObj) {
5179
+ return pad(dateObj.getMonth() + 1);
5180
+ },
5181
+ MMM: function MMM(dateObj) {
5182
+ return monthNamesShort[dateObj.getMonth()];
5183
+ },
5184
+ MMMM: function MMMM(dateObj) {
5185
+ return monthNames[dateObj.getMonth()];
5186
+ },
5187
+ yy: function yy(dateObj) {
5188
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
5189
+ },
5190
+ yyyy: function yyyy(dateObj) {
5191
+ return pad(dateObj.getFullYear(), 4);
5192
+ },
5193
+ h: function h(dateObj) {
5194
+ return dateObj.getHours() % 12 || 12;
5195
+ },
5196
+ hh: function hh(dateObj) {
5197
+ return pad(dateObj.getHours() % 12 || 12);
5198
+ },
5199
+ H: function H(dateObj) {
5200
+ return dateObj.getHours();
5201
+ },
5202
+ HH: function HH(dateObj) {
5203
+ return pad(dateObj.getHours());
5204
+ },
5205
+ m: function m(dateObj) {
5206
+ return dateObj.getMinutes();
5207
+ },
5208
+ mm: function mm(dateObj) {
5209
+ return pad(dateObj.getMinutes());
5210
+ },
5211
+ s: function s(dateObj) {
5212
+ return dateObj.getSeconds();
5213
+ },
5214
+ ss: function ss(dateObj) {
5215
+ return pad(dateObj.getSeconds());
5216
+ },
5217
+ S: function S(dateObj) {
5218
+ return Math.round(dateObj.getMilliseconds() / 100);
5219
+ },
5220
+ SS: function SS(dateObj) {
5221
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5222
+ },
5223
+ SSS: function SSS(dateObj) {
5224
+ return pad(dateObj.getMilliseconds(), 3);
5225
+ },
5226
+ a: function a(dateObj) {
5227
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5228
+ },
5229
+ A: function A(dateObj) {
5230
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5231
+ },
5232
+ ZZ: function ZZ(dateObj) {
5233
+ var o = dateObj.getTimezoneOffset();
5234
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5235
+ }
5236
+ };
5237
+
5238
+ var parseFlags = {
5239
+ d: [twoDigits, function (d, v) {
5240
+ d.day = v;
5241
+ }],
5242
+ Do: [twoDigits + word, function (d, v) {
5243
+ d.day = parseInt(v, 10);
5244
+ }],
5245
+ M: [twoDigits, function (d, v) {
5246
+ d.month = v - 1;
5247
+ }],
5248
+ yy: [twoDigits, function (d, v) {
5249
+ var da = new Date(),
5250
+ cent = +('' + da.getFullYear()).substr(0, 2);
5251
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5252
+ }],
5253
+ h: [twoDigits, function (d, v) {
5254
+ d.hour = v;
5255
+ }],
5256
+ m: [twoDigits, function (d, v) {
5257
+ d.minute = v;
5258
+ }],
5259
+ s: [twoDigits, function (d, v) {
5260
+ d.second = v;
5261
+ }],
5262
+ yyyy: [fourDigits, function (d, v) {
5263
+ d.year = v;
5264
+ }],
5265
+ S: ['\\d', function (d, v) {
5266
+ d.millisecond = v * 100;
5267
+ }],
5268
+ SS: ['\\d{2}', function (d, v) {
5269
+ d.millisecond = v * 10;
5270
+ }],
5271
+ SSS: [threeDigits, function (d, v) {
5272
+ d.millisecond = v;
5273
+ }],
5274
+ D: [twoDigits, noop],
5275
+ ddd: [word, noop],
5276
+ MMM: [word, monthUpdate('monthNamesShort')],
5277
+ MMMM: [word, monthUpdate('monthNames')],
5278
+ a: [word, function (d, v) {
5279
+ var val = v.toLowerCase();
5280
+ if (val === '上午') {
5281
+ d.isPm = false;
5282
+ } else if (val === '下午') {
5283
+ d.isPm = true;
5284
+ }
5285
+ }],
5286
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5287
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
5288
+ minutes = void 0;
5289
+
5290
+ if (parts) {
5291
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5292
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5293
+ }
5294
+ }]
5295
+ };
5296
+ parseFlags.dd = parseFlags.d;
5297
+ parseFlags.dddd = parseFlags.ddd;
5298
+ parseFlags.DD = parseFlags.D;
5299
+ parseFlags.mm = parseFlags.m;
5300
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5301
+ parseFlags.MM = parseFlags.M;
5302
+ parseFlags.ss = parseFlags.s;
5303
+ parseFlags.A = parseFlags.a;
5304
+
5305
+ // Some common format strings
5306
+ fecha.masks = {
5307
+ default: 'ddd MMM dd yyyy HH:mm:ss',
5308
+ shortDate: 'M/D/yy',
5309
+ mediumDate: 'MMM d, yyyy',
5310
+ longDate: 'MMMM d, yyyy',
5311
+ fullDate: 'dddd, MMMM d, yyyy',
5312
+ shortTime: 'HH:mm',
5313
+ mediumTime: 'HH:mm:ss',
5314
+ longTime: 'HH:mm:ss.SSS'
5315
+ };
5316
+
5343
5317
  /***
5344
5318
  * Format a date
5345
5319
  * @method format
5346
5320
  * @param {Date|number} dateObj
5347
5321
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
5348
- */
5349
- fecha.format = function (dateObj, mask) {
5350
- if (typeof dateObj === 'number') {
5351
- dateObj = new Date(dateObj);
5352
- }
5353
-
5354
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5355
- throw new Error('Invalid Date in fecha.format');
5356
- }
5357
-
5358
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
5359
-
5360
- const literals = [];
5361
-
5362
- // Make literals inactive by replacing them with ??
5363
- mask = mask.replace(literal, function($0, $1) {
5364
- literals.push($1);
5365
- return '@@@';
5366
- });
5367
- // Apply formatting rules
5368
- mask = mask.replace(token, function ($0) {
5369
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5370
- });
5371
- // Inline literal values back into the formatted value
5372
- return mask.replace(/@@@/g, function() {
5373
- return literals.shift();
5374
- });
5375
- };
5376
-
5322
+ */
5323
+ fecha.format = function (dateObj, mask) {
5324
+ if (typeof dateObj === 'number') {
5325
+ dateObj = new Date(dateObj);
5326
+ }
5327
+
5328
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5329
+ throw new Error('Invalid Date in fecha.format');
5330
+ }
5331
+
5332
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
5333
+
5334
+ var literals = [];
5335
+
5336
+ // Make literals inactive by replacing them with ??
5337
+ mask = mask.replace(literal, function ($0, $1) {
5338
+ literals.push($1);
5339
+ return '@@@';
5340
+ });
5341
+ // Apply formatting rules
5342
+ mask = mask.replace(token, function ($0) {
5343
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5344
+ });
5345
+ // Inline literal values back into the formatted value
5346
+ return mask.replace(/@@@/g, function () {
5347
+ return literals.shift();
5348
+ });
5349
+ };
5350
+
5377
5351
  /**
5378
5352
  * Parse a date string into an object, changes - into /
5379
5353
  * @method parse
5380
5354
  * @param {string} dateStr Date string
5381
5355
  * @param {string} format Date parse format
5382
5356
  * @returns {Date|boolean}
5383
- */
5384
- fecha.parse = function (dateStr, format) {
5385
- if (typeof format !== 'string') {
5386
- throw new Error('Invalid format in fecha.parse');
5387
- }
5388
-
5389
- format = fecha.masks[format] || format;
5390
-
5391
- // Avoid regular expression denial of service, fail early for really long strings
5392
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5393
- if (dateStr.length > 1000) {
5394
- return null;
5395
- }
5396
-
5397
- const dateInfo = {};
5398
- const parseInfo = [];
5399
- const literals = [];
5400
- format = format.replace(literal, function($0, $1) {
5401
- literals.push($1);
5402
- return '@@@';
5403
- });
5404
- let newFormat = regexEscape(format).replace(token, function ($0) {
5405
- if (parseFlags[$0]) {
5406
- const info = parseFlags[$0];
5407
- parseInfo.push(info[1]);
5408
- return '(' + info[0] + ')';
5409
- }
5410
-
5411
- return $0;
5412
- });
5413
- newFormat = newFormat.replace(/@@@/g, function() {
5414
- return literals.shift();
5415
- });
5416
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
5417
- if (!matches) {
5418
- return null;
5419
- }
5420
-
5421
- for (let i = 1; i < matches.length; i++) {
5422
- parseInfo[i - 1](dateInfo, matches[i]);
5423
- }
5424
-
5425
- const today = new Date();
5426
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5427
- dateInfo.hour = +dateInfo.hour + 12;
5428
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5429
- dateInfo.hour = 0;
5430
- }
5431
-
5432
- let date;
5433
- if (dateInfo.timezoneOffset != null) {
5434
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5435
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5436
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5437
- } else {
5438
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5439
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5440
- }
5441
- return date;
5442
- };
5443
-
5444
- // 导出fecha对象
5445
-
5446
-
5447
- // 以下是从date-util.js合并的函数
5448
- const newArray = function(start, end) {
5449
- let result = [];
5450
- for (let i = start; i <= end; i++) {
5451
- result.push(i);
5452
- }
5453
- return result;
5454
- };
5455
-
5456
- const getSettings = () => {
5457
- return {
5458
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5459
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5460
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5461
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5462
- amPm: ['上午', '下午']
5463
- };
5464
- };
5465
-
5466
- const toDate = function(date) {
5467
- return isDate(date) ? new Date(date) : null;
5468
- };
5469
-
5470
- const isDate = function(date) {
5471
- if (date === null || date === undefined) return false;
5472
- if (isNaN(new Date(date).getTime())) return false;
5473
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5474
- return true;
5475
- };
5476
-
5477
- const isDateObject = function(val) {
5478
- return val instanceof Date;
5479
- };
5480
-
5481
- const formatDate = function (date, format = 'yyyy-MM-dd') {
5482
- // 处理多种输入类型
5483
- if (!date) return '';
5484
-
5485
- // 如果是时间戳,转成日期对象
5486
- if (typeof date === 'number') {
5487
- date = new Date(date);
5488
- }
5489
- // 如果是字符串,转成日期对象
5490
- if (typeof date === 'string') {
5491
- date = new Date(date);
5492
- }
5493
-
5494
- // 调用toDate进一步验证和转换
5495
- date = toDate(date);
5496
- if (!date) return '';
5497
-
5498
- // 兼容大写和小写的格式标记
5499
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5500
- const lowercaseFormat = format
5501
- .replace(/YYYY/g, 'yyyy')
5502
- .replace(/D/g, 'd')
5503
-
5504
- // 使用fecha库进行格式化,支持中文配置
5505
- const str = fecha.format(date, lowercaseFormat, getSettings());
5506
- return str;
5507
- };
5508
-
5509
- const parseDate = function(string, format) {
5510
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5511
- };
5512
-
5513
- const getDayCountOfMonth = function(year, month) {
5514
- if (month === 3 || month === 5 || month === 8 || month === 10) {
5515
- return 30;
5516
- }
5517
-
5518
- if (month === 1) {
5519
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5520
- return 29;
5521
- } else {
5522
- return 28;
5523
- }
5524
- }
5525
-
5526
- return 31;
5527
- };
5528
-
5529
- const getDayCountOfYear = function(year) {
5530
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
5531
- return isLeapYear ? 366 : 365;
5532
- };
5533
-
5534
- const getFirstDayOfMonth = function(date) {
5535
- const temp = new Date(date.getTime());
5536
- temp.setDate(1);
5537
- return temp.getDay();
5538
- };
5539
-
5540
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5541
- // {prev, next} Date should work for Daylight Saving Time
5542
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5543
- const prevDate = function(date, amount = 1) {
5544
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5545
- };
5546
-
5547
- const nextDate = function(date, amount = 1) {
5548
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5549
- };
5550
-
5551
- const getStartDateOfMonth = function(year, month) {
5552
- const result = new Date(year, month, 1);
5553
- const day = result.getDay();
5554
-
5555
- if (day === 0) {
5556
- return prevDate(result, 7);
5557
- } else {
5558
- return prevDate(result, day);
5559
- }
5560
- };
5561
-
5562
- const getWeekNumber = function(date) {
5563
- // 支持多种输入类型
5564
- if (!date||!isDate(date)) {
5565
- date = new Date();
5566
- }
5567
- if (typeof date === 'string') {
5568
- date = new Date(date);
5569
- }
5570
-
5571
- // 验证日期有效性
5572
- if (!isDate(date)) return null;
5573
-
5574
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5575
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5576
- // 将星期日的星期数设为7
5577
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5578
- // 获取当年的第一天
5579
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5580
- // 计算到最近的星期四的完整周数
5581
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
5582
- // 返回周数
5583
- return weekNo;
5584
- };
5585
-
5586
- const getRangeHours = function(ranges) {
5587
- const hours = [];
5588
- let disabledHours = [];
5589
-
5590
- (ranges || []).forEach(range => {
5591
- const value = range.map(date => date.getHours());
5592
-
5593
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5594
- });
5595
-
5596
- if (disabledHours.length) {
5597
- for (let i = 0; i < 24; i++) {
5598
- hours[i] = disabledHours.indexOf(i) === -1;
5599
- }
5600
- } else {
5601
- for (let i = 0; i < 24; i++) {
5602
- hours[i] = false;
5603
- }
5604
- }
5605
-
5606
- return hours;
5607
- };
5608
-
5609
- const getPrevMonthLastDays = (date, amount) => {
5610
- if (amount <= 0) return [];
5611
- const temp = new Date(date.getTime());
5612
- temp.setDate(0);
5613
- const lastDay = temp.getDate();
5614
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
5615
- };
5616
-
5617
- const getMonthDays = (date) => {
5618
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5619
- const days = temp.getDate();
5620
- return range(days).map((_, index) => index + 1);
5621
- };
5622
-
5623
- function setRangeData(arr, start, end, value) {
5624
- for (let i = start; i < end; i++) {
5625
- arr[i] = value;
5626
- }
5627
- }
5628
-
5629
- const getRangeMinutes = function(ranges, hour) {
5630
- const minutes = new Array(60);
5631
-
5632
- if (ranges.length > 0) {
5633
- ranges.forEach(range => {
5634
- const start = range[0];
5635
- const end = range[1];
5636
- const startHour = start.getHours();
5637
- const startMinute = start.getMinutes();
5638
- const endHour = end.getHours();
5639
- const endMinute = end.getMinutes();
5640
- if (startHour === hour && endHour !== hour) {
5641
- setRangeData(minutes, startMinute, 60, true);
5642
- } else if (startHour === hour && endHour === hour) {
5643
- setRangeData(minutes, startMinute, endMinute + 1, true);
5644
- } else if (startHour !== hour && endHour === hour) {
5645
- setRangeData(minutes, 0, endMinute + 1, true);
5646
- } else if (startHour < hour && endHour > hour) {
5647
- setRangeData(minutes, 0, 60, true);
5648
- }
5649
- });
5650
- } else {
5651
- setRangeData(minutes, 0, 60, true);
5652
- }
5653
- return minutes;
5654
- };
5655
-
5656
- const range = function(n) {
5657
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5658
- return Array.apply(null, {length: n}).map((_, n) => n);
5659
- };
5660
-
5661
- const modifyDate = function(date, y, m, d) {
5662
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5663
- };
5664
-
5665
- const modifyTime = function(date, h, m, s) {
5666
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5667
- };
5668
-
5669
- const modifyWithTimeString = (date, time) => {
5670
- if (date == null || !time) {
5671
- return date;
5672
- }
5673
- time = parseDate(time, 'HH:mm:ss');
5674
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5675
- };
5676
-
5677
- const clearTime = function(date) {
5678
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5679
- };
5680
-
5681
- const clearMilliseconds = function(date) {
5682
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5683
- };
5684
-
5685
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5686
- // TODO: refactory a more elegant solution
5687
- if (ranges.length === 0) return date;
5688
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5689
- const ndate = normalizeDate(date);
5690
- const nranges = ranges.map(range => range.map(normalizeDate));
5691
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5692
-
5693
- let minDate = nranges[0][0];
5694
- let maxDate = nranges[0][0];
5695
-
5696
- nranges.forEach(nrange => {
5697
- minDate = new Date(Math.min(nrange[0], minDate));
5698
- maxDate = new Date(Math.max(nrange[1], minDate));
5699
- });
5700
-
5701
- const ret = ndate < minDate ? minDate : maxDate;
5702
- // preserve Year/Month/Date
5703
- return modifyDate(
5704
- ret,
5705
- date.getFullYear(),
5706
- date.getMonth(),
5707
- date.getDate()
5708
- );
5709
- };
5710
-
5711
- const timeWithinRange = function(date, selectableRange, format) {
5712
- const limitedDate = limitTimeRange(date, selectableRange, format);
5713
- return limitedDate.getTime() === date.getTime();
5714
- };
5715
-
5716
- const changeYearMonthAndClampDate = function(date, year, month) {
5717
- // clamp date to the number of days in `year`, `month`
5718
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5719
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5720
- return modifyDate(date, year, month, monthDate);
5721
- };
5722
-
5723
- const prevMonth = function(date) {
5724
- const year = date.getFullYear();
5725
- const month = date.getMonth();
5726
- return month === 0
5727
- ? changeYearMonthAndClampDate(date, year - 1, 11)
5728
- : changeYearMonthAndClampDate(date, year, month - 1);
5729
- };
5730
-
5731
- const nextMonth = function(date) {
5732
- const year = date.getFullYear();
5733
- const month = date.getMonth();
5734
- return month === 11
5735
- ? changeYearMonthAndClampDate(date, year + 1, 0)
5736
- : changeYearMonthAndClampDate(date, year, month + 1);
5737
- };
5738
-
5739
- const prevYear = function(date, amount = 1) {
5740
- const year = date.getFullYear();
5741
- const month = date.getMonth();
5742
- return changeYearMonthAndClampDate(date, year - amount, month);
5743
- };
5744
-
5745
- const nextYear = function(date, amount = 1) {
5746
- const year = date.getFullYear();
5747
- const month = date.getMonth();
5748
- return changeYearMonthAndClampDate(date, year + amount, month);
5749
- };
5750
-
5751
- const extractDateFormat = function(format) {
5752
- return format
5753
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
5754
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5755
- .trim();
5756
- };
5757
-
5758
- const extractTimeFormat = function(format) {
5759
- return format
5760
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5761
- .trim();
5762
- };
5763
-
5764
- const validateRangeInOneMonth = function(start, end) {
5765
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5766
- };
5767
-
5357
+ */
5358
+ fecha.parse = function (dateStr, format) {
5359
+ if (typeof format !== 'string') {
5360
+ throw new Error('Invalid format in fecha.parse');
5361
+ }
5362
+
5363
+ format = fecha.masks[format] || format;
5364
+
5365
+ // Avoid regular expression denial of service, fail early for really long strings
5366
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5367
+ if (dateStr.length > 1000) {
5368
+ return null;
5369
+ }
5370
+
5371
+ var dateInfo = {};
5372
+ var parseInfo = [];
5373
+ var literals = [];
5374
+ format = format.replace(literal, function ($0, $1) {
5375
+ literals.push($1);
5376
+ return '@@@';
5377
+ });
5378
+ var newFormat = regexEscape(format).replace(token, function ($0) {
5379
+ if (parseFlags[$0]) {
5380
+ var info = parseFlags[$0];
5381
+ parseInfo.push(info[1]);
5382
+ return '(' + info[0] + ')';
5383
+ }
5384
+
5385
+ return $0;
5386
+ });
5387
+ newFormat = newFormat.replace(/@@@/g, function () {
5388
+ return literals.shift();
5389
+ });
5390
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
5391
+ if (!matches) {
5392
+ return null;
5393
+ }
5394
+
5395
+ for (var i = 1; i < matches.length; i++) {
5396
+ parseInfo[i - 1](dateInfo, matches[i]);
5397
+ }
5398
+
5399
+ var today = new Date();
5400
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5401
+ dateInfo.hour = +dateInfo.hour + 12;
5402
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5403
+ dateInfo.hour = 0;
5404
+ }
5405
+
5406
+ var date = void 0;
5407
+ if (dateInfo.timezoneOffset != null) {
5408
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5409
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5410
+ } else {
5411
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5412
+ }
5413
+ return date;
5414
+ };
5415
+
5416
+ // 导出fecha对象
5417
+
5418
+
5419
+ // 以下是从date-util.js合并的函数
5420
+ var newArray = function newArray(start, end) {
5421
+ var result = [];
5422
+ for (var i = start; i <= end; i++) {
5423
+ result.push(i);
5424
+ }
5425
+ return result;
5426
+ };
5427
+
5428
+ var getSettings = function getSettings() {
5429
+ return {
5430
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5431
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5432
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5433
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5434
+ amPm: ['上午', '下午']
5435
+ };
5436
+ };
5437
+
5438
+ var toDate = function toDate(date) {
5439
+ return isDate(date) ? new Date(date) : null;
5440
+ };
5441
+
5442
+ var isDate = function isDate(date) {
5443
+ if (date === null || date === undefined) return false;
5444
+ if (isNaN(new Date(date).getTime())) return false;
5445
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5446
+ return true;
5447
+ };
5448
+
5449
+ var isDateObject = function isDateObject(val) {
5450
+ return val instanceof Date;
5451
+ };
5452
+
5453
+ var formatDate = function formatDate(date) {
5454
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
5455
+
5456
+ // 处理多种输入类型
5457
+ if (!date) return '';
5458
+
5459
+ // 如果是时间戳,转成日期对象
5460
+ if (typeof date === 'number') {
5461
+ date = new Date(date);
5462
+ }
5463
+ // 如果是字符串,转成日期对象
5464
+ if (typeof date === 'string') {
5465
+ date = new Date(date);
5466
+ }
5467
+
5468
+ // 调用toDate进一步验证和转换
5469
+ date = toDate(date);
5470
+ if (!date) return '';
5471
+
5472
+ // 兼容大写和小写的格式标记
5473
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5474
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
5475
+
5476
+ // 使用fecha库进行格式化,支持中文配置
5477
+ var str = fecha.format(date, lowercaseFormat, getSettings());
5478
+ return str;
5479
+ };
5480
+
5481
+ var parseDate = function parseDate(string, format) {
5482
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5483
+ };
5484
+
5485
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
5486
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
5487
+ return 30;
5488
+ }
5489
+
5490
+ if (month === 1) {
5491
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5492
+ return 29;
5493
+ } else {
5494
+ return 28;
5495
+ }
5496
+ }
5497
+
5498
+ return 31;
5499
+ };
5500
+
5501
+ var getDayCountOfYear = function getDayCountOfYear(year) {
5502
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
5503
+ return isLeapYear ? 366 : 365;
5504
+ };
5505
+
5506
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
5507
+ var temp = new Date(date.getTime());
5508
+ temp.setDate(1);
5509
+ return temp.getDay();
5510
+ };
5511
+
5512
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5513
+ // {prev, next} Date should work for Daylight Saving Time
5514
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5515
+ var prevDate = function prevDate(date) {
5516
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5517
+
5518
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5519
+ };
5520
+
5521
+ var nextDate = function nextDate(date) {
5522
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5523
+
5524
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5525
+ };
5526
+
5527
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
5528
+ var result = new Date(year, month, 1);
5529
+ var day = result.getDay();
5530
+
5531
+ if (day === 0) {
5532
+ return prevDate(result, 7);
5533
+ } else {
5534
+ return prevDate(result, day);
5535
+ }
5536
+ };
5537
+
5538
+ var getWeekNumber = function getWeekNumber(date) {
5539
+ // 支持多种输入类型
5540
+ if (!date || !isDate(date)) {
5541
+ date = new Date();
5542
+ }
5543
+ if (typeof date === 'string') {
5544
+ date = new Date(date);
5545
+ }
5546
+
5547
+ // 验证日期有效性
5548
+ if (!isDate(date)) return null;
5549
+
5550
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5551
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5552
+ // 将星期日的星期数设为7
5553
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5554
+ // 获取当年的第一天
5555
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5556
+ // 计算到最近的星期四的完整周数
5557
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
5558
+ // 返回周数
5559
+ return weekNo;
5560
+ };
5561
+
5562
+ var getRangeHours = function getRangeHours(ranges) {
5563
+ var hours = [];
5564
+ var disabledHours = [];
5565
+
5566
+ (ranges || []).forEach(function (range) {
5567
+ var value = range.map(function (date) {
5568
+ return date.getHours();
5569
+ });
5570
+
5571
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5572
+ });
5573
+
5574
+ if (disabledHours.length) {
5575
+ for (var i = 0; i < 24; i++) {
5576
+ hours[i] = disabledHours.indexOf(i) === -1;
5577
+ }
5578
+ } else {
5579
+ for (var _i = 0; _i < 24; _i++) {
5580
+ hours[_i] = false;
5581
+ }
5582
+ }
5583
+
5584
+ return hours;
5585
+ };
5586
+
5587
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5588
+ if (amount <= 0) return [];
5589
+ var temp = new Date(date.getTime());
5590
+ temp.setDate(0);
5591
+ var lastDay = temp.getDate();
5592
+ return range(amount).map(function (_, index) {
5593
+ return lastDay - (amount - index - 1);
5594
+ });
5595
+ };
5596
+
5597
+ var getMonthDays = function getMonthDays(date) {
5598
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5599
+ var days = temp.getDate();
5600
+ return range(days).map(function (_, index) {
5601
+ return index + 1;
5602
+ });
5603
+ };
5604
+
5605
+ function setRangeData(arr, start, end, value) {
5606
+ for (var i = start; i < end; i++) {
5607
+ arr[i] = value;
5608
+ }
5609
+ }
5610
+
5611
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5612
+ var minutes = new Array(60);
5613
+
5614
+ if (ranges.length > 0) {
5615
+ ranges.forEach(function (range) {
5616
+ var start = range[0];
5617
+ var end = range[1];
5618
+ var startHour = start.getHours();
5619
+ var startMinute = start.getMinutes();
5620
+ var endHour = end.getHours();
5621
+ var endMinute = end.getMinutes();
5622
+ if (startHour === hour && endHour !== hour) {
5623
+ setRangeData(minutes, startMinute, 60, true);
5624
+ } else if (startHour === hour && endHour === hour) {
5625
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5626
+ } else if (startHour !== hour && endHour === hour) {
5627
+ setRangeData(minutes, 0, endMinute + 1, true);
5628
+ } else if (startHour < hour && endHour > hour) {
5629
+ setRangeData(minutes, 0, 60, true);
5630
+ }
5631
+ });
5632
+ } else {
5633
+ setRangeData(minutes, 0, 60, true);
5634
+ }
5635
+ return minutes;
5636
+ };
5637
+
5638
+ var range = function range(n) {
5639
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5640
+ return Array.apply(null, { length: n }).map(function (_, n) {
5641
+ return n;
5642
+ });
5643
+ };
5644
+
5645
+ var modifyDate = function modifyDate(date, y, m, d) {
5646
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5647
+ };
5648
+
5649
+ var modifyTime = function modifyTime(date, h, m, s) {
5650
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5651
+ };
5652
+
5653
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
5654
+ if (date == null || !time) {
5655
+ return date;
5656
+ }
5657
+ time = parseDate(time, 'HH:mm:ss');
5658
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5659
+ };
5660
+
5661
+ var clearTime = function clearTime(date) {
5662
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5663
+ };
5664
+
5665
+ var clearMilliseconds = function clearMilliseconds(date) {
5666
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5667
+ };
5668
+
5669
+ var limitTimeRange = function limitTimeRange(date, ranges) {
5670
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5671
+
5672
+ // TODO: refactory a more elegant solution
5673
+ if (ranges.length === 0) return date;
5674
+ var normalizeDate = function normalizeDate(date) {
5675
+ return fecha.parse(fecha.format(date, format), format);
5676
+ };
5677
+ var ndate = normalizeDate(date);
5678
+ var nranges = ranges.map(function (range) {
5679
+ return range.map(normalizeDate);
5680
+ });
5681
+ if (nranges.some(function (nrange) {
5682
+ return ndate >= nrange[0] && ndate <= nrange[1];
5683
+ })) return date;
5684
+
5685
+ var minDate = nranges[0][0];
5686
+ var maxDate = nranges[0][0];
5687
+
5688
+ nranges.forEach(function (nrange) {
5689
+ minDate = new Date(Math.min(nrange[0], minDate));
5690
+ maxDate = new Date(Math.max(nrange[1], minDate));
5691
+ });
5692
+
5693
+ var ret = ndate < minDate ? minDate : maxDate;
5694
+ // preserve Year/Month/Date
5695
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5696
+ };
5697
+
5698
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5699
+ var limitedDate = limitTimeRange(date, selectableRange, format);
5700
+ return limitedDate.getTime() === date.getTime();
5701
+ };
5702
+
5703
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5704
+ // clamp date to the number of days in `year`, `month`
5705
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5706
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5707
+ return modifyDate(date, year, month, monthDate);
5708
+ };
5709
+
5710
+ var prevMonth = function prevMonth(date) {
5711
+ var year = date.getFullYear();
5712
+ var month = date.getMonth();
5713
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5714
+ };
5715
+
5716
+ var nextMonth = function nextMonth(date) {
5717
+ var year = date.getFullYear();
5718
+ var month = date.getMonth();
5719
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5720
+ };
5721
+
5722
+ var prevYear = function prevYear(date) {
5723
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5724
+
5725
+ var year = date.getFullYear();
5726
+ var month = date.getMonth();
5727
+ return changeYearMonthAndClampDate(date, year - amount, month);
5728
+ };
5729
+
5730
+ var nextYear = function nextYear(date) {
5731
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5732
+
5733
+ var year = date.getFullYear();
5734
+ var month = date.getMonth();
5735
+ return changeYearMonthAndClampDate(date, year + amount, month);
5736
+ };
5737
+
5738
+ var extractDateFormat = function extractDateFormat(format) {
5739
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5740
+ };
5741
+
5742
+ var extractTimeFormat = function extractTimeFormat(format) {
5743
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5744
+ };
5745
+
5746
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5747
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5748
+ };
5749
+
5768
5750
  /**
5769
5751
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5770
5752
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5771
5753
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5772
5754
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5773
5755
  * @returns {number} 工作日数量
5774
- */
5775
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5776
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5777
- throw new Error(
5778
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5779
- );
5780
- }
5781
-
5782
- const startDateObj = new Date(start_date);
5783
- const endDateObj = new Date(end_date);
5784
-
5785
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5786
- throw new Error(
5787
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5788
- );
5789
- }
5790
-
5791
- if (startDateObj > endDateObj) {
5792
- throw new Error('Start date should be earlier than or equal to end date.');
5793
- }
5794
-
5795
- let workdays = 0;
5796
-
5797
- // Iterate through each day in the date range
5798
- for (
5799
- let currentDate = new Date(startDateObj);
5800
- currentDate <= endDateObj;
5801
- currentDate.setDate(currentDate.getDate() + 1)
5802
- ) {
5803
- // Check if the current day is a weekend (Saturday or Sunday)
5804
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5805
-
5806
- // Check if the current day is a holiday
5807
- const isHoliday = holidays.some((holiday) => {
5808
- const holidayDate = new Date(holiday);
5809
- return currentDate.toDateString() === holidayDate.toDateString();
5810
- });
5811
-
5812
- // If it's a workday (not a weekend or holiday), increment the workdays count
5813
- if (!isWeekend && !isHoliday) {
5814
- workdays++;
5815
- }
5816
- }
5817
-
5818
- return workdays;
5819
- };
5820
-
5756
+ */
5757
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5758
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5759
+
5760
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5761
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5762
+ }
5763
+
5764
+ var startDateObj = new Date(start_date);
5765
+ var endDateObj = new Date(end_date);
5766
+
5767
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5768
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5769
+ }
5770
+
5771
+ if (startDateObj > endDateObj) {
5772
+ throw new Error('Start date should be earlier than or equal to end date.');
5773
+ }
5774
+
5775
+ var workdays = 0;
5776
+
5777
+ // Iterate through each day in the date range
5778
+
5779
+ var _loop = function _loop(currentDate) {
5780
+ // Check if the current day is a weekend (Saturday or Sunday)
5781
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5782
+
5783
+ // Check if the current day is a holiday
5784
+ var isHoliday = holidays.some(function (holiday) {
5785
+ var holidayDate = new Date(holiday);
5786
+ return currentDate.toDateString() === holidayDate.toDateString();
5787
+ });
5788
+
5789
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5790
+ if (!isWeekend && !isHoliday) {
5791
+ workdays++;
5792
+ }
5793
+ };
5794
+
5795
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5796
+ _loop(currentDate);
5797
+ }
5798
+
5799
+ return workdays;
5800
+ };
5801
+
5821
5802
  /**
5822
5803
  * 日期加减天数
5823
5804
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5824
5805
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5825
5806
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5826
- */
5827
- const dateAddDays = function (start_date, days) {
5828
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5829
- throw new Error(
5830
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5831
- );
5832
- }
5833
-
5834
- const startDateObj = new Date(start_date);
5835
- if (isNaN(startDateObj.getTime())) {
5836
- throw new Error(
5837
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5838
- );
5839
- }
5840
-
5841
- const resultDateObj = new Date(startDateObj);
5842
- resultDateObj.setDate(resultDateObj.getDate() + days);
5843
-
5844
- const resultYear = resultDateObj.getFullYear();
5845
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5846
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5847
-
5848
- return `${resultYear}-${resultMonth}-${resultDay}`;
5849
- };
5850
-
5807
+ */
5808
+ var dateAddDays = function dateAddDays(start_date, days) {
5809
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5810
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days.");
5811
+ }
5812
+
5813
+ var startDateObj = new Date(start_date);
5814
+ if (isNaN(startDateObj.getTime())) {
5815
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5816
+ }
5817
+
5818
+ var resultDateObj = new Date(startDateObj);
5819
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5820
+
5821
+ var resultYear = resultDateObj.getFullYear();
5822
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5823
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5824
+
5825
+ return resultYear + '-' + resultMonth + '-' + resultDay;
5826
+ };
5827
+
5851
5828
  /**
5852
5829
  * 计算两个日期之间的差值
5853
5830
  * @date 2023年12月14日
@@ -5855,182 +5832,180 @@ const dateAddDays = function (start_date, days) {
5855
5832
  * @param {String} end_date - 结束日期字符串
5856
5833
  * @param {String} unit - 单位:year/month/day
5857
5834
  * @returns {Number} 差值
5858
- */
5859
- const dateDiff = function (start_date, end_date, unit = 'day') {
5860
- // Assuming date strings are in "YYYY-MM-DD" format
5861
- var startDate = new Date(start_date);
5862
- var endDate = new Date(end_date);
5863
-
5864
- // If the date is invalid, return 0
5865
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5866
- return 0;
5867
- }
5868
-
5869
- if (unit === 'year') {
5870
- return endDate.getFullYear() - startDate.getFullYear();
5871
- } else if (unit === 'month') {
5872
- return (
5873
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5874
- (endDate.getMonth() - startDate.getMonth())
5875
- );
5876
- } else {
5877
- // Default to day
5878
- var timeDifference = endDate - startDate;
5879
- // Calculate days (86400000 milliseconds per day)
5880
- return Math.floor(timeDifference / 86400000);
5881
- }
5882
- };
5883
-
5835
+ */
5836
+ var dateDiff = function dateDiff(start_date, end_date) {
5837
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5838
+
5839
+ // Assuming date strings are in "YYYY-MM-DD" format
5840
+ var startDate = new Date(start_date);
5841
+ var endDate = new Date(end_date);
5842
+
5843
+ // If the date is invalid, return 0
5844
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5845
+ return 0;
5846
+ }
5847
+
5848
+ if (unit === 'year') {
5849
+ return endDate.getFullYear() - startDate.getFullYear();
5850
+ } else if (unit === 'month') {
5851
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5852
+ } else {
5853
+ // Default to day
5854
+ var timeDifference = endDate - startDate;
5855
+ // Calculate days (86400000 milliseconds per day)
5856
+ return Math.floor(timeDifference / 86400000);
5857
+ }
5858
+ };
5859
+
5884
5860
  /**
5885
5861
  * 获取月份中的日期
5886
5862
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5887
5863
  * @returns {number} 月份中的日期(1-31)
5888
- */
5889
- const dayOfMonth = function (date) {
5890
- if (typeof date !== 'string') {
5891
- throw new Error(
5892
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
5893
- );
5894
- }
5895
-
5896
- const dateObj = new Date(date);
5897
- if (isNaN(dateObj.getTime())) {
5898
- throw new Error(
5899
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5900
- );
5901
- }
5902
-
5903
- return dateObj.getDate();
5904
- };
5905
-
5864
+ */
5865
+ var dayOfMonth = function dayOfMonth(date) {
5866
+ if (typeof date !== 'string') {
5867
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5868
+ }
5869
+
5870
+ var dateObj = new Date(date);
5871
+ if (isNaN(dateObj.getTime())) {
5872
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5873
+ }
5874
+
5875
+ return dateObj.getDate();
5876
+ };
5877
+
5906
5878
  /**
5907
5879
  * 获取当前日期
5908
5880
  * @date 2022年5月7日
5909
5881
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
5910
5882
  * @returns {string} 当前日期的格式化字符串
5911
- */
5912
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
5913
- return formatDate(new Date(), format);
5914
- };
5915
-
5883
+ */
5884
+ var getCurrentDate = function getCurrentDate() {
5885
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5886
+
5887
+ return formatDate(new Date(), format);
5888
+ };
5889
+
5916
5890
  /**
5917
5891
  * 获取当前日期时间
5918
5892
  * @date 2022年5月7日
5919
5893
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
5920
5894
  * @returns {string} 当前日期时间的格式化字符串
5921
- */
5922
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
5923
- return formatDate(new Date(), format);
5924
- };
5925
-
5895
+ */
5896
+ var getCurrentDateTime = function getCurrentDateTime() {
5897
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
5898
+
5899
+ return formatDate(new Date(), format);
5900
+ };
5901
+
5926
5902
  /**
5927
5903
  * 获取小时
5928
5904
  * @date 2022年5月7日
5929
5905
  * @param {Date|string} [date] - 日期对象或日期字符串
5930
5906
  * @returns {number} 小时数(0-23)
5931
- */
5932
- const getHour = function (date) {
5933
- if (!date) {
5934
- return new Date().getHours();
5935
- }
5936
- if (typeof date === 'string') {
5937
- date = new Date(date);
5938
- }
5939
- return date.getHours();
5940
- };
5941
-
5907
+ */
5908
+ var getHour = function getHour(date) {
5909
+ if (!date) {
5910
+ return new Date().getHours();
5911
+ }
5912
+ if (typeof date === 'string') {
5913
+ date = new Date(date);
5914
+ }
5915
+ return date.getHours();
5916
+ };
5917
+
5942
5918
  /**
5943
5919
  * 获取分钟
5944
5920
  * @date 2022年5月7日
5945
5921
  * @param {Date|string} [date] - 日期对象或日期字符串
5946
5922
  * @returns {number} 分钟数(0-59)
5947
- */
5948
- const getMinute = function (date) {
5949
- if (!date) {
5950
- return new Date().getMinutes();
5951
- }
5952
- if (typeof date === 'string') {
5953
- date = new Date(date);
5954
- }
5955
- return date.getMinutes();
5956
- };
5957
-
5923
+ */
5924
+ var getMinute = function getMinute(date) {
5925
+ if (!date) {
5926
+ return new Date().getMinutes();
5927
+ }
5928
+ if (typeof date === 'string') {
5929
+ date = new Date(date);
5930
+ }
5931
+ return date.getMinutes();
5932
+ };
5933
+
5958
5934
  /**
5959
5935
  * 获取月份
5960
5936
  * @date 2022年5月7日
5961
5937
  * @param {Date|string} [date] - 日期对象或日期字符串
5962
5938
  * @returns {number} 月份数(1-12)
5963
- */
5964
- const getMonth = function (date) {
5965
- if (!date) {
5966
- return new Date().getMonth() + 1;
5967
- }
5968
- if (typeof date === 'string') {
5969
- date = new Date(date);
5970
- }
5971
- return date.getMonth() + 1;
5972
- };
5973
-
5939
+ */
5940
+ var getMonth = function getMonth(date) {
5941
+ if (!date) {
5942
+ return new Date().getMonth() + 1;
5943
+ }
5944
+ if (typeof date === 'string') {
5945
+ date = new Date(date);
5946
+ }
5947
+ return date.getMonth() + 1;
5948
+ };
5949
+
5974
5950
  /**
5975
5951
  * 获取秒
5976
5952
  * @date 2022年5月7日
5977
5953
  * @param {Date|string} [date] - 日期对象或日期字符串
5978
5954
  * @returns {number} 秒数(0-59)
5979
- */
5980
- const getSecond = function (date) {
5981
- if (!date) {
5982
- return new Date().getSeconds();
5983
- }
5984
- if (typeof date === 'string') {
5985
- date = new Date(date);
5986
- }
5987
- return date.getSeconds();
5988
- };
5989
-
5955
+ */
5956
+ var getSecond = function getSecond(date) {
5957
+ if (!date) {
5958
+ return new Date().getSeconds();
5959
+ }
5960
+ if (typeof date === 'string') {
5961
+ date = new Date(date);
5962
+ }
5963
+ return date.getSeconds();
5964
+ };
5965
+
5990
5966
  /**
5991
5967
  * 获取星期几
5992
5968
  * @date 2022年5月7日
5993
5969
  * @param {Date|string} [date] - 日期对象或日期字符串
5994
5970
  * @returns {number} 星期几(0-6,0表示星期日)
5995
- */
5996
- const getWeekday = function (date) {
5997
- if (!date) {
5998
- return new Date().getDay();
5999
- }
6000
- if (typeof date === 'string') {
6001
- date = new Date(date);
6002
- }
6003
- return date.getDay();
6004
- };
6005
-
6006
-
5971
+ */
5972
+ var getWeekday = function getWeekday(date) {
5973
+ if (!date) {
5974
+ return new Date().getDay();
5975
+ }
5976
+ if (typeof date === 'string') {
5977
+ date = new Date(date);
5978
+ }
5979
+ return date.getDay();
5980
+ };
5981
+
6007
5982
  /**
6008
5983
  * @desc 获取上午/下午/晚上
6009
5984
  * @author huangbo
6010
5985
  * @date 2022年5月7日
6011
5986
  * @param {String} [time] - 时间
6012
- **/
6013
- const timeCycle = function (time) {
6014
- let hour = 0;
6015
- if (!time) {
6016
- hour = new Date().getHours();
6017
- } else if (typeof time === 'string') {
6018
- // 从时间字符串中提取小时
6019
- const match = time.match(/^(\d{1,2})/);
6020
- if (match) {
6021
- hour = parseInt(match[1], 10);
6022
- }
6023
- } else if (typeof time === 'number') {
6024
- hour = time;
6025
- }
6026
- // 判断时间段
6027
- if (hour >= 5 && hour < 12) {
6028
- return '上午';
6029
- } else if (hour >= 12 && hour < 18) {
6030
- return '下午';
6031
- } else {
6032
- return '晚上';
6033
- }
5987
+ **/
5988
+ var timeCycle = function timeCycle(time) {
5989
+ var hour = 0;
5990
+ if (!time) {
5991
+ hour = new Date().getHours();
5992
+ } else if (typeof time === 'string') {
5993
+ // 从时间字符串中提取小时
5994
+ var match = time.match(/^(\d{1,2})/);
5995
+ if (match) {
5996
+ hour = parseInt(match[1], 10);
5997
+ }
5998
+ } else if (typeof time === 'number') {
5999
+ hour = time;
6000
+ }
6001
+ // 判断时间段
6002
+ if (hour >= 5 && hour < 12) {
6003
+ return '上午';
6004
+ } else if (hour >= 12 && hour < 18) {
6005
+ return '下午';
6006
+ } else {
6007
+ return '晚上';
6008
+ }
6034
6009
  };
6035
6010
 
6036
6011
  /***/ }),