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/option.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 = 171);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 178);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3285,7 +3285,7 @@ var warning = function warning(content, _callback3) {
3285
3285
 
3286
3286
  /***/ }),
3287
3287
 
3288
- /***/ 109:
3288
+ /***/ 111:
3289
3289
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3290
3290
 
3291
3291
  "use strict";
@@ -3877,12 +3877,12 @@ module.exports = require("lodash/get");
3877
3877
 
3878
3878
  /***/ }),
3879
3879
 
3880
- /***/ 171:
3880
+ /***/ 178:
3881
3881
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3882
3882
 
3883
3883
  "use strict";
3884
3884
  __webpack_require__.r(__webpack_exports__);
3885
- /* harmony import */ var _select_src_option__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(109);
3885
+ /* harmony import */ var _select_src_option__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(111);
3886
3886
 
3887
3887
 
3888
3888
  /* istanbul ignore next */
@@ -4137,759 +4137,736 @@ function normalizeComponent(
4137
4137
  /* unused harmony export getSecond */
4138
4138
  /* unused harmony export getWeekday */
4139
4139
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
4140
- /* Modified from https://github.com/taylorhakes/fecha
4141
- *
4142
- * The MIT License (MIT)
4143
- *
4144
- * Copyright (c) 2015 Taylor Hakes
4145
- *
4146
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4147
- * of this software and associated documentation files (the "Software"), to deal
4148
- * in the Software without restriction, including without limitation the rights
4149
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4150
- * copies of the Software, and to permit persons to whom the Software is
4151
- * furnished to do so, subject to the following conditions:
4152
- *
4153
- * The above copyright notice and this permission notice shall be included in all
4154
- * copies or substantial portions of the Software.
4155
- *
4156
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4157
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4158
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4159
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4160
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4161
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4162
- * SOFTWARE.
4163
- */
4164
-
4165
- /*eslint-disable*/
4166
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
4167
-
4168
-
4140
+
4141
+
4169
4142
  /**
4170
4143
  * Parse or format dates
4171
4144
  * @class fecha
4172
- */
4173
- const fecha = {};
4174
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4175
- const twoDigits = '\\d\\d?';
4176
- const threeDigits = '\\d{3}';
4177
- const fourDigits = '\\d{4}';
4178
- const word = '[^\\s]+';
4179
- const literal = /\[([^]*?)\]/gm;
4180
- const noop = function () {};
4181
-
4182
- function regexEscape(str) {
4183
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4184
- }
4185
-
4186
- function shorten(arr, sLen) {
4187
- const newArr = [];
4188
- for (let i = 0, len = arr.length; i < len; i++) {
4189
- newArr.push(arr[i].substr(0, sLen));
4190
- }
4191
- return newArr;
4192
- }
4193
-
4194
- function monthUpdate() {
4195
- return function (d, v) {
4196
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4197
- if (~index) {
4198
- d.month = index;
4199
- }
4200
- };
4201
- }
4202
-
4203
- function pad(val, len) {
4204
- val = String(val);
4205
- len = len || 2;
4206
- while (val.length < len) {
4207
- val = '0' + val;
4208
- }
4209
- return val;
4210
- }
4211
-
4212
- // 直接使用中文日期名称常量
4213
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4214
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4215
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4216
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4217
- const amPm = ['上午', '下午'];
4218
- const DoFn = function DoFn(D) {
4219
- return D + '日';
4220
- };
4221
-
4222
- const formatFlags = {
4223
- D: function(dateObj) {
4224
- return dateObj.getDay();
4225
- },
4226
- DD: function(dateObj) {
4227
- return pad(dateObj.getDay());
4228
- },
4229
- Do: function(dateObj) {
4230
- return DoFn(dateObj.getDate());
4231
- },
4232
- d: function(dateObj) {
4233
- return dateObj.getDate();
4234
- },
4235
- dd: function(dateObj) {
4236
- return pad(dateObj.getDate());
4237
- },
4238
- ddd: function(dateObj) {
4239
- return dayNamesShort[dateObj.getDay()];
4240
- },
4241
- dddd: function(dateObj) {
4242
- return dayNames[dateObj.getDay()];
4243
- },
4244
- M: function(dateObj) {
4245
- return dateObj.getMonth() + 1;
4246
- },
4247
- MM: function(dateObj) {
4248
- return pad(dateObj.getMonth() + 1);
4249
- },
4250
- MMM: function(dateObj) {
4251
- return monthNamesShort[dateObj.getMonth()];
4252
- },
4253
- MMMM: function(dateObj) {
4254
- return monthNames[dateObj.getMonth()];
4255
- },
4256
- yy: function(dateObj) {
4257
- return pad(String(dateObj.getFullYear()), 4).substr(2);
4258
- },
4259
- yyyy: function(dateObj) {
4260
- return pad(dateObj.getFullYear(), 4);
4261
- },
4262
- h: function(dateObj) {
4263
- return dateObj.getHours() % 12 || 12;
4264
- },
4265
- hh: function(dateObj) {
4266
- return pad(dateObj.getHours() % 12 || 12);
4267
- },
4268
- H: function(dateObj) {
4269
- return dateObj.getHours();
4270
- },
4271
- HH: function(dateObj) {
4272
- return pad(dateObj.getHours());
4273
- },
4274
- m: function(dateObj) {
4275
- return dateObj.getMinutes();
4276
- },
4277
- mm: function(dateObj) {
4278
- return pad(dateObj.getMinutes());
4279
- },
4280
- s: function(dateObj) {
4281
- return dateObj.getSeconds();
4282
- },
4283
- ss: function(dateObj) {
4284
- return pad(dateObj.getSeconds());
4285
- },
4286
- S: function(dateObj) {
4287
- return Math.round(dateObj.getMilliseconds() / 100);
4288
- },
4289
- SS: function(dateObj) {
4290
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4291
- },
4292
- SSS: function(dateObj) {
4293
- return pad(dateObj.getMilliseconds(), 3);
4294
- },
4295
- a: function(dateObj) {
4296
- return dateObj.getHours() < 12 ? '上午' : '下午';
4297
- },
4298
- A: function(dateObj) {
4299
- return dateObj.getHours() < 12 ? '上午' : '下午';
4300
- },
4301
- ZZ: function(dateObj) {
4302
- const o = dateObj.getTimezoneOffset();
4303
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4304
- }
4305
- };
4306
-
4307
- const parseFlags = {
4308
- d: [twoDigits, function (d, v) {
4309
- d.day = v;
4310
- }],
4311
- Do: [twoDigits + word, function (d, v) {
4312
- d.day = parseInt(v, 10);
4313
- }],
4314
- M: [twoDigits, function (d, v) {
4315
- d.month = v - 1;
4316
- }],
4317
- yy: [twoDigits, function (d, v) {
4318
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
4319
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4320
- }],
4321
- h: [twoDigits, function (d, v) {
4322
- d.hour = v;
4323
- }],
4324
- m: [twoDigits, function (d, v) {
4325
- d.minute = v;
4326
- }],
4327
- s: [twoDigits, function (d, v) {
4328
- d.second = v;
4329
- }],
4330
- yyyy: [fourDigits, function (d, v) {
4331
- d.year = v;
4332
- }],
4333
- S: ['\\d', function (d, v) {
4334
- d.millisecond = v * 100;
4335
- }],
4336
- SS: ['\\d{2}', function (d, v) {
4337
- d.millisecond = v * 10;
4338
- }],
4339
- SSS: [threeDigits, function (d, v) {
4340
- d.millisecond = v;
4341
- }],
4342
- D: [twoDigits, noop],
4343
- ddd: [word, noop],
4344
- MMM: [word, monthUpdate('monthNamesShort')],
4345
- MMMM: [word, monthUpdate('monthNames')],
4346
- a: [word, function (d, v) {
4347
- const val = v.toLowerCase();
4348
- if (val === '上午') {
4349
- d.isPm = false;
4350
- } else if (val === '下午') {
4351
- d.isPm = true;
4352
- }
4353
- }],
4354
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
4355
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
4356
-
4357
- if (parts) {
4358
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
4359
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
4360
- }
4361
- }]
4362
- };
4363
- parseFlags.dd = parseFlags.d;
4364
- parseFlags.dddd = parseFlags.ddd;
4365
- parseFlags.DD = parseFlags.D;
4366
- parseFlags.mm = parseFlags.m;
4367
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
4368
- parseFlags.MM = parseFlags.M;
4369
- parseFlags.ss = parseFlags.s;
4370
- parseFlags.A = parseFlags.a;
4371
-
4372
-
4373
- // Some common format strings
4374
- fecha.masks = {
4375
- default: 'ddd MMM dd yyyy HH:mm:ss',
4376
- shortDate: 'M/D/yy',
4377
- mediumDate: 'MMM d, yyyy',
4378
- longDate: 'MMMM d, yyyy',
4379
- fullDate: 'dddd, MMMM d, yyyy',
4380
- shortTime: 'HH:mm',
4381
- mediumTime: 'HH:mm:ss',
4382
- longTime: 'HH:mm:ss.SSS'
4383
- };
4384
-
4145
+ */
4146
+ var fecha = {};
4147
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
4148
+ var twoDigits = '\\d\\d?';
4149
+ var threeDigits = '\\d{3}';
4150
+ var fourDigits = '\\d{4}';
4151
+ var word = '[^\\s]+';
4152
+ var literal = /\[([^]*?)\]/gm;
4153
+ var noop = function noop() {};
4154
+
4155
+ function regexEscape(str) {
4156
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
4157
+ }
4158
+
4159
+ function shorten(arr, sLen) {
4160
+ var newArr = [];
4161
+ for (var i = 0, len = arr.length; i < len; i++) {
4162
+ newArr.push(arr[i].substr(0, sLen));
4163
+ }
4164
+ return newArr;
4165
+ }
4166
+
4167
+ function monthUpdate() {
4168
+ return function (d, v) {
4169
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
4170
+ if (~index) {
4171
+ d.month = index;
4172
+ }
4173
+ };
4174
+ }
4175
+
4176
+ function pad(val, len) {
4177
+ val = String(val);
4178
+ len = len || 2;
4179
+ while (val.length < len) {
4180
+ val = '0' + val;
4181
+ }
4182
+ return val;
4183
+ }
4184
+
4185
+ // 直接使用中文日期名称常量
4186
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
4187
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
4188
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
4189
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
4190
+ var amPm = ['上午', '下午'];
4191
+ var DoFn = function DoFn(D) {
4192
+ return D + '日';
4193
+ };
4194
+
4195
+ var formatFlags = {
4196
+ D: function D(dateObj) {
4197
+ return dateObj.getDay();
4198
+ },
4199
+ DD: function DD(dateObj) {
4200
+ return pad(dateObj.getDay());
4201
+ },
4202
+ Do: function Do(dateObj) {
4203
+ return DoFn(dateObj.getDate());
4204
+ },
4205
+ d: function d(dateObj) {
4206
+ return dateObj.getDate();
4207
+ },
4208
+ dd: function dd(dateObj) {
4209
+ return pad(dateObj.getDate());
4210
+ },
4211
+ ddd: function ddd(dateObj) {
4212
+ return dayNamesShort[dateObj.getDay()];
4213
+ },
4214
+ dddd: function dddd(dateObj) {
4215
+ return dayNames[dateObj.getDay()];
4216
+ },
4217
+ M: function M(dateObj) {
4218
+ return dateObj.getMonth() + 1;
4219
+ },
4220
+ MM: function MM(dateObj) {
4221
+ return pad(dateObj.getMonth() + 1);
4222
+ },
4223
+ MMM: function MMM(dateObj) {
4224
+ return monthNamesShort[dateObj.getMonth()];
4225
+ },
4226
+ MMMM: function MMMM(dateObj) {
4227
+ return monthNames[dateObj.getMonth()];
4228
+ },
4229
+ yy: function yy(dateObj) {
4230
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
4231
+ },
4232
+ yyyy: function yyyy(dateObj) {
4233
+ return pad(dateObj.getFullYear(), 4);
4234
+ },
4235
+ h: function h(dateObj) {
4236
+ return dateObj.getHours() % 12 || 12;
4237
+ },
4238
+ hh: function hh(dateObj) {
4239
+ return pad(dateObj.getHours() % 12 || 12);
4240
+ },
4241
+ H: function H(dateObj) {
4242
+ return dateObj.getHours();
4243
+ },
4244
+ HH: function HH(dateObj) {
4245
+ return pad(dateObj.getHours());
4246
+ },
4247
+ m: function m(dateObj) {
4248
+ return dateObj.getMinutes();
4249
+ },
4250
+ mm: function mm(dateObj) {
4251
+ return pad(dateObj.getMinutes());
4252
+ },
4253
+ s: function s(dateObj) {
4254
+ return dateObj.getSeconds();
4255
+ },
4256
+ ss: function ss(dateObj) {
4257
+ return pad(dateObj.getSeconds());
4258
+ },
4259
+ S: function S(dateObj) {
4260
+ return Math.round(dateObj.getMilliseconds() / 100);
4261
+ },
4262
+ SS: function SS(dateObj) {
4263
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
4264
+ },
4265
+ SSS: function SSS(dateObj) {
4266
+ return pad(dateObj.getMilliseconds(), 3);
4267
+ },
4268
+ a: function a(dateObj) {
4269
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4270
+ },
4271
+ A: function A(dateObj) {
4272
+ return dateObj.getHours() < 12 ? '上午' : '下午';
4273
+ },
4274
+ ZZ: function ZZ(dateObj) {
4275
+ var o = dateObj.getTimezoneOffset();
4276
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
4277
+ }
4278
+ };
4279
+
4280
+ var parseFlags = {
4281
+ d: [twoDigits, function (d, v) {
4282
+ d.day = v;
4283
+ }],
4284
+ Do: [twoDigits + word, function (d, v) {
4285
+ d.day = parseInt(v, 10);
4286
+ }],
4287
+ M: [twoDigits, function (d, v) {
4288
+ d.month = v - 1;
4289
+ }],
4290
+ yy: [twoDigits, function (d, v) {
4291
+ var da = new Date(),
4292
+ cent = +('' + da.getFullYear()).substr(0, 2);
4293
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
4294
+ }],
4295
+ h: [twoDigits, function (d, v) {
4296
+ d.hour = v;
4297
+ }],
4298
+ m: [twoDigits, function (d, v) {
4299
+ d.minute = v;
4300
+ }],
4301
+ s: [twoDigits, function (d, v) {
4302
+ d.second = v;
4303
+ }],
4304
+ yyyy: [fourDigits, function (d, v) {
4305
+ d.year = v;
4306
+ }],
4307
+ S: ['\\d', function (d, v) {
4308
+ d.millisecond = v * 100;
4309
+ }],
4310
+ SS: ['\\d{2}', function (d, v) {
4311
+ d.millisecond = v * 10;
4312
+ }],
4313
+ SSS: [threeDigits, function (d, v) {
4314
+ d.millisecond = v;
4315
+ }],
4316
+ D: [twoDigits, noop],
4317
+ ddd: [word, noop],
4318
+ MMM: [word, monthUpdate('monthNamesShort')],
4319
+ MMMM: [word, monthUpdate('monthNames')],
4320
+ a: [word, function (d, v) {
4321
+ var val = v.toLowerCase();
4322
+ if (val === '上午') {
4323
+ d.isPm = false;
4324
+ } else if (val === '下午') {
4325
+ d.isPm = true;
4326
+ }
4327
+ }],
4328
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
4329
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
4330
+ minutes = void 0;
4331
+
4332
+ if (parts) {
4333
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
4334
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
4335
+ }
4336
+ }]
4337
+ };
4338
+ parseFlags.dd = parseFlags.d;
4339
+ parseFlags.dddd = parseFlags.ddd;
4340
+ parseFlags.DD = parseFlags.D;
4341
+ parseFlags.mm = parseFlags.m;
4342
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
4343
+ parseFlags.MM = parseFlags.M;
4344
+ parseFlags.ss = parseFlags.s;
4345
+ parseFlags.A = parseFlags.a;
4346
+
4347
+ // Some common format strings
4348
+ fecha.masks = {
4349
+ default: 'ddd MMM dd yyyy HH:mm:ss',
4350
+ shortDate: 'M/D/yy',
4351
+ mediumDate: 'MMM d, yyyy',
4352
+ longDate: 'MMMM d, yyyy',
4353
+ fullDate: 'dddd, MMMM d, yyyy',
4354
+ shortTime: 'HH:mm',
4355
+ mediumTime: 'HH:mm:ss',
4356
+ longTime: 'HH:mm:ss.SSS'
4357
+ };
4358
+
4385
4359
  /***
4386
4360
  * Format a date
4387
4361
  * @method format
4388
4362
  * @param {Date|number} dateObj
4389
4363
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
4390
- */
4391
- fecha.format = function (dateObj, mask) {
4392
- if (typeof dateObj === 'number') {
4393
- dateObj = new Date(dateObj);
4394
- }
4395
-
4396
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
4397
- throw new Error('Invalid Date in fecha.format');
4398
- }
4399
-
4400
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
4401
-
4402
- const literals = [];
4403
-
4404
- // Make literals inactive by replacing them with ??
4405
- mask = mask.replace(literal, function($0, $1) {
4406
- literals.push($1);
4407
- return '@@@';
4408
- });
4409
- // Apply formatting rules
4410
- mask = mask.replace(token, function ($0) {
4411
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
4412
- });
4413
- // Inline literal values back into the formatted value
4414
- return mask.replace(/@@@/g, function() {
4415
- return literals.shift();
4416
- });
4417
- };
4418
-
4364
+ */
4365
+ fecha.format = function (dateObj, mask) {
4366
+ if (typeof dateObj === 'number') {
4367
+ dateObj = new Date(dateObj);
4368
+ }
4369
+
4370
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
4371
+ throw new Error('Invalid Date in fecha.format');
4372
+ }
4373
+
4374
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
4375
+
4376
+ var literals = [];
4377
+
4378
+ // Make literals inactive by replacing them with ??
4379
+ mask = mask.replace(literal, function ($0, $1) {
4380
+ literals.push($1);
4381
+ return '@@@';
4382
+ });
4383
+ // Apply formatting rules
4384
+ mask = mask.replace(token, function ($0) {
4385
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
4386
+ });
4387
+ // Inline literal values back into the formatted value
4388
+ return mask.replace(/@@@/g, function () {
4389
+ return literals.shift();
4390
+ });
4391
+ };
4392
+
4419
4393
  /**
4420
4394
  * Parse a date string into an object, changes - into /
4421
4395
  * @method parse
4422
4396
  * @param {string} dateStr Date string
4423
4397
  * @param {string} format Date parse format
4424
4398
  * @returns {Date|boolean}
4425
- */
4426
- fecha.parse = function (dateStr, format) {
4427
- if (typeof format !== 'string') {
4428
- throw new Error('Invalid format in fecha.parse');
4429
- }
4430
-
4431
- format = fecha.masks[format] || format;
4432
-
4433
- // Avoid regular expression denial of service, fail early for really long strings
4434
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
4435
- if (dateStr.length > 1000) {
4436
- return null;
4437
- }
4438
-
4439
- const dateInfo = {};
4440
- const parseInfo = [];
4441
- const literals = [];
4442
- format = format.replace(literal, function($0, $1) {
4443
- literals.push($1);
4444
- return '@@@';
4445
- });
4446
- let newFormat = regexEscape(format).replace(token, function ($0) {
4447
- if (parseFlags[$0]) {
4448
- const info = parseFlags[$0];
4449
- parseInfo.push(info[1]);
4450
- return '(' + info[0] + ')';
4451
- }
4452
-
4453
- return $0;
4454
- });
4455
- newFormat = newFormat.replace(/@@@/g, function() {
4456
- return literals.shift();
4457
- });
4458
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
4459
- if (!matches) {
4460
- return null;
4461
- }
4462
-
4463
- for (let i = 1; i < matches.length; i++) {
4464
- parseInfo[i - 1](dateInfo, matches[i]);
4465
- }
4466
-
4467
- const today = new Date();
4468
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
4469
- dateInfo.hour = +dateInfo.hour + 12;
4470
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
4471
- dateInfo.hour = 0;
4472
- }
4473
-
4474
- let date;
4475
- if (dateInfo.timezoneOffset != null) {
4476
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
4477
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
4478
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
4479
- } else {
4480
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
4481
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
4482
- }
4483
- return date;
4484
- };
4485
-
4486
- // 导出fecha对象
4487
-
4488
-
4489
- // 以下是从date-util.js合并的函数
4490
- const newArray = function(start, end) {
4491
- let result = [];
4492
- for (let i = start; i <= end; i++) {
4493
- result.push(i);
4494
- }
4495
- return result;
4496
- };
4497
-
4498
- const getSettings = () => {
4499
- return {
4500
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
4501
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
4502
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
4503
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
4504
- amPm: ['上午', '下午']
4505
- };
4506
- };
4507
-
4508
- const toDate = function(date) {
4509
- return isDate(date) ? new Date(date) : null;
4510
- };
4511
-
4512
- const isDate = function(date) {
4513
- if (date === null || date === undefined) return false;
4514
- if (isNaN(new Date(date).getTime())) return false;
4515
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
4516
- return true;
4517
- };
4518
-
4519
- const isDateObject = function(val) {
4520
- return val instanceof Date;
4521
- };
4522
-
4523
- const formatDate = function (date, format = 'yyyy-MM-dd') {
4524
- // 处理多种输入类型
4525
- if (!date) return '';
4526
-
4527
- // 如果是时间戳,转成日期对象
4528
- if (typeof date === 'number') {
4529
- date = new Date(date);
4530
- }
4531
- // 如果是字符串,转成日期对象
4532
- if (typeof date === 'string') {
4533
- date = new Date(date);
4534
- }
4535
-
4536
- // 调用toDate进一步验证和转换
4537
- date = toDate(date);
4538
- if (!date) return '';
4539
-
4540
- // 兼容大写和小写的格式标记
4541
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
4542
- const lowercaseFormat = format
4543
- .replace(/YYYY/g, 'yyyy')
4544
- .replace(/D/g, 'd')
4545
-
4546
- // 使用fecha库进行格式化,支持中文配置
4547
- const str = fecha.format(date, lowercaseFormat, getSettings());
4548
- return str;
4549
- };
4550
-
4551
- const parseDate = function(string, format) {
4552
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
4553
- };
4554
-
4555
- const getDayCountOfMonth = function(year, month) {
4556
- if (month === 3 || month === 5 || month === 8 || month === 10) {
4557
- return 30;
4558
- }
4559
-
4560
- if (month === 1) {
4561
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
4562
- return 29;
4563
- } else {
4564
- return 28;
4565
- }
4566
- }
4567
-
4568
- return 31;
4569
- };
4570
-
4571
- const getDayCountOfYear = function(year) {
4572
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
4573
- return isLeapYear ? 366 : 365;
4574
- };
4575
-
4576
- const getFirstDayOfMonth = function(date) {
4577
- const temp = new Date(date.getTime());
4578
- temp.setDate(1);
4579
- return temp.getDay();
4580
- };
4581
-
4582
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
4583
- // {prev, next} Date should work for Daylight Saving Time
4584
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
4585
- const prevDate = function(date, amount = 1) {
4586
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
4587
- };
4588
-
4589
- const nextDate = function(date, amount = 1) {
4590
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
4591
- };
4592
-
4593
- const getStartDateOfMonth = function(year, month) {
4594
- const result = new Date(year, month, 1);
4595
- const day = result.getDay();
4596
-
4597
- if (day === 0) {
4598
- return prevDate(result, 7);
4599
- } else {
4600
- return prevDate(result, day);
4601
- }
4602
- };
4603
-
4604
- const getWeekNumber = function(date) {
4605
- // 支持多种输入类型
4606
- if (!date||!isDate(date)) {
4607
- date = new Date();
4608
- }
4609
- if (typeof date === 'string') {
4610
- date = new Date(date);
4611
- }
4612
-
4613
- // 验证日期有效性
4614
- if (!isDate(date)) return null;
4615
-
4616
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
4617
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
4618
- // 将星期日的星期数设为7
4619
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
4620
- // 获取当年的第一天
4621
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4622
- // 计算到最近的星期四的完整周数
4623
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
4624
- // 返回周数
4625
- return weekNo;
4626
- };
4627
-
4628
- const getRangeHours = function(ranges) {
4629
- const hours = [];
4630
- let disabledHours = [];
4631
-
4632
- (ranges || []).forEach(range => {
4633
- const value = range.map(date => date.getHours());
4634
-
4635
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
4636
- });
4637
-
4638
- if (disabledHours.length) {
4639
- for (let i = 0; i < 24; i++) {
4640
- hours[i] = disabledHours.indexOf(i) === -1;
4641
- }
4642
- } else {
4643
- for (let i = 0; i < 24; i++) {
4644
- hours[i] = false;
4645
- }
4646
- }
4647
-
4648
- return hours;
4649
- };
4650
-
4651
- const getPrevMonthLastDays = (date, amount) => {
4652
- if (amount <= 0) return [];
4653
- const temp = new Date(date.getTime());
4654
- temp.setDate(0);
4655
- const lastDay = temp.getDate();
4656
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
4657
- };
4658
-
4659
- const getMonthDays = (date) => {
4660
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
4661
- const days = temp.getDate();
4662
- return range(days).map((_, index) => index + 1);
4663
- };
4664
-
4665
- function setRangeData(arr, start, end, value) {
4666
- for (let i = start; i < end; i++) {
4667
- arr[i] = value;
4668
- }
4669
- }
4670
-
4671
- const getRangeMinutes = function(ranges, hour) {
4672
- const minutes = new Array(60);
4673
-
4674
- if (ranges.length > 0) {
4675
- ranges.forEach(range => {
4676
- const start = range[0];
4677
- const end = range[1];
4678
- const startHour = start.getHours();
4679
- const startMinute = start.getMinutes();
4680
- const endHour = end.getHours();
4681
- const endMinute = end.getMinutes();
4682
- if (startHour === hour && endHour !== hour) {
4683
- setRangeData(minutes, startMinute, 60, true);
4684
- } else if (startHour === hour && endHour === hour) {
4685
- setRangeData(minutes, startMinute, endMinute + 1, true);
4686
- } else if (startHour !== hour && endHour === hour) {
4687
- setRangeData(minutes, 0, endMinute + 1, true);
4688
- } else if (startHour < hour && endHour > hour) {
4689
- setRangeData(minutes, 0, 60, true);
4690
- }
4691
- });
4692
- } else {
4693
- setRangeData(minutes, 0, 60, true);
4694
- }
4695
- return minutes;
4696
- };
4697
-
4698
- const range = function(n) {
4699
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
4700
- return Array.apply(null, {length: n}).map((_, n) => n);
4701
- };
4702
-
4703
- const modifyDate = function(date, y, m, d) {
4704
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
4705
- };
4706
-
4707
- const modifyTime = function(date, h, m, s) {
4708
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
4709
- };
4710
-
4711
- const modifyWithTimeString = (date, time) => {
4712
- if (date == null || !time) {
4713
- return date;
4714
- }
4715
- time = parseDate(time, 'HH:mm:ss');
4716
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
4717
- };
4718
-
4719
- const clearTime = function(date) {
4720
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
4721
- };
4722
-
4723
- const clearMilliseconds = function(date) {
4724
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
4725
- };
4726
-
4727
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
4728
- // TODO: refactory a more elegant solution
4729
- if (ranges.length === 0) return date;
4730
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
4731
- const ndate = normalizeDate(date);
4732
- const nranges = ranges.map(range => range.map(normalizeDate));
4733
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
4734
-
4735
- let minDate = nranges[0][0];
4736
- let maxDate = nranges[0][0];
4737
-
4738
- nranges.forEach(nrange => {
4739
- minDate = new Date(Math.min(nrange[0], minDate));
4740
- maxDate = new Date(Math.max(nrange[1], minDate));
4741
- });
4742
-
4743
- const ret = ndate < minDate ? minDate : maxDate;
4744
- // preserve Year/Month/Date
4745
- return modifyDate(
4746
- ret,
4747
- date.getFullYear(),
4748
- date.getMonth(),
4749
- date.getDate()
4750
- );
4751
- };
4752
-
4753
- const timeWithinRange = function(date, selectableRange, format) {
4754
- const limitedDate = limitTimeRange(date, selectableRange, format);
4755
- return limitedDate.getTime() === date.getTime();
4756
- };
4757
-
4758
- const changeYearMonthAndClampDate = function(date, year, month) {
4759
- // clamp date to the number of days in `year`, `month`
4760
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
4761
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
4762
- return modifyDate(date, year, month, monthDate);
4763
- };
4764
-
4765
- const prevMonth = function(date) {
4766
- const year = date.getFullYear();
4767
- const month = date.getMonth();
4768
- return month === 0
4769
- ? changeYearMonthAndClampDate(date, year - 1, 11)
4770
- : changeYearMonthAndClampDate(date, year, month - 1);
4771
- };
4772
-
4773
- const nextMonth = function(date) {
4774
- const year = date.getFullYear();
4775
- const month = date.getMonth();
4776
- return month === 11
4777
- ? changeYearMonthAndClampDate(date, year + 1, 0)
4778
- : changeYearMonthAndClampDate(date, year, month + 1);
4779
- };
4780
-
4781
- const prevYear = function(date, amount = 1) {
4782
- const year = date.getFullYear();
4783
- const month = date.getMonth();
4784
- return changeYearMonthAndClampDate(date, year - amount, month);
4785
- };
4786
-
4787
- const nextYear = function(date, amount = 1) {
4788
- const year = date.getFullYear();
4789
- const month = date.getMonth();
4790
- return changeYearMonthAndClampDate(date, year + amount, month);
4791
- };
4792
-
4793
- const extractDateFormat = function(format) {
4794
- return format
4795
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
4796
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
4797
- .trim();
4798
- };
4799
-
4800
- const extractTimeFormat = function(format) {
4801
- return format
4802
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
4803
- .trim();
4804
- };
4805
-
4806
- const validateRangeInOneMonth = function(start, end) {
4807
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
4808
- };
4809
-
4399
+ */
4400
+ fecha.parse = function (dateStr, format) {
4401
+ if (typeof format !== 'string') {
4402
+ throw new Error('Invalid format in fecha.parse');
4403
+ }
4404
+
4405
+ format = fecha.masks[format] || format;
4406
+
4407
+ // Avoid regular expression denial of service, fail early for really long strings
4408
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
4409
+ if (dateStr.length > 1000) {
4410
+ return null;
4411
+ }
4412
+
4413
+ var dateInfo = {};
4414
+ var parseInfo = [];
4415
+ var literals = [];
4416
+ format = format.replace(literal, function ($0, $1) {
4417
+ literals.push($1);
4418
+ return '@@@';
4419
+ });
4420
+ var newFormat = regexEscape(format).replace(token, function ($0) {
4421
+ if (parseFlags[$0]) {
4422
+ var info = parseFlags[$0];
4423
+ parseInfo.push(info[1]);
4424
+ return '(' + info[0] + ')';
4425
+ }
4426
+
4427
+ return $0;
4428
+ });
4429
+ newFormat = newFormat.replace(/@@@/g, function () {
4430
+ return literals.shift();
4431
+ });
4432
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
4433
+ if (!matches) {
4434
+ return null;
4435
+ }
4436
+
4437
+ for (var i = 1; i < matches.length; i++) {
4438
+ parseInfo[i - 1](dateInfo, matches[i]);
4439
+ }
4440
+
4441
+ var today = new Date();
4442
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
4443
+ dateInfo.hour = +dateInfo.hour + 12;
4444
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
4445
+ dateInfo.hour = 0;
4446
+ }
4447
+
4448
+ var date = void 0;
4449
+ if (dateInfo.timezoneOffset != null) {
4450
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
4451
+ 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));
4452
+ } else {
4453
+ 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);
4454
+ }
4455
+ return date;
4456
+ };
4457
+
4458
+ // 导出fecha对象
4459
+
4460
+
4461
+ // 以下是从date-util.js合并的函数
4462
+ var newArray = function newArray(start, end) {
4463
+ var result = [];
4464
+ for (var i = start; i <= end; i++) {
4465
+ result.push(i);
4466
+ }
4467
+ return result;
4468
+ };
4469
+
4470
+ var getSettings = function getSettings() {
4471
+ return {
4472
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
4473
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
4474
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
4475
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
4476
+ amPm: ['上午', '下午']
4477
+ };
4478
+ };
4479
+
4480
+ var toDate = function toDate(date) {
4481
+ return isDate(date) ? new Date(date) : null;
4482
+ };
4483
+
4484
+ var isDate = function isDate(date) {
4485
+ if (date === null || date === undefined) return false;
4486
+ if (isNaN(new Date(date).getTime())) return false;
4487
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
4488
+ return true;
4489
+ };
4490
+
4491
+ var isDateObject = function isDateObject(val) {
4492
+ return val instanceof Date;
4493
+ };
4494
+
4495
+ var formatDate = function formatDate(date) {
4496
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
4497
+
4498
+ // 处理多种输入类型
4499
+ if (!date) return '';
4500
+
4501
+ // 如果是时间戳,转成日期对象
4502
+ if (typeof date === 'number') {
4503
+ date = new Date(date);
4504
+ }
4505
+ // 如果是字符串,转成日期对象
4506
+ if (typeof date === 'string') {
4507
+ date = new Date(date);
4508
+ }
4509
+
4510
+ // 调用toDate进一步验证和转换
4511
+ date = toDate(date);
4512
+ if (!date) return '';
4513
+
4514
+ // 兼容大写和小写的格式标记
4515
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
4516
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
4517
+
4518
+ // 使用fecha库进行格式化,支持中文配置
4519
+ var str = fecha.format(date, lowercaseFormat, getSettings());
4520
+ return str;
4521
+ };
4522
+
4523
+ var parseDate = function parseDate(string, format) {
4524
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
4525
+ };
4526
+
4527
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
4528
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
4529
+ return 30;
4530
+ }
4531
+
4532
+ if (month === 1) {
4533
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
4534
+ return 29;
4535
+ } else {
4536
+ return 28;
4537
+ }
4538
+ }
4539
+
4540
+ return 31;
4541
+ };
4542
+
4543
+ var getDayCountOfYear = function getDayCountOfYear(year) {
4544
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
4545
+ return isLeapYear ? 366 : 365;
4546
+ };
4547
+
4548
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
4549
+ var temp = new Date(date.getTime());
4550
+ temp.setDate(1);
4551
+ return temp.getDay();
4552
+ };
4553
+
4554
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
4555
+ // {prev, next} Date should work for Daylight Saving Time
4556
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
4557
+ var prevDate = function prevDate(date) {
4558
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4559
+
4560
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
4561
+ };
4562
+
4563
+ var nextDate = function nextDate(date) {
4564
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4565
+
4566
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
4567
+ };
4568
+
4569
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
4570
+ var result = new Date(year, month, 1);
4571
+ var day = result.getDay();
4572
+
4573
+ if (day === 0) {
4574
+ return prevDate(result, 7);
4575
+ } else {
4576
+ return prevDate(result, day);
4577
+ }
4578
+ };
4579
+
4580
+ var getWeekNumber = function getWeekNumber(date) {
4581
+ // 支持多种输入类型
4582
+ if (!date || !isDate(date)) {
4583
+ date = new Date();
4584
+ }
4585
+ if (typeof date === 'string') {
4586
+ date = new Date(date);
4587
+ }
4588
+
4589
+ // 验证日期有效性
4590
+ if (!isDate(date)) return null;
4591
+
4592
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
4593
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
4594
+ // 将星期日的星期数设为7
4595
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
4596
+ // 获取当年的第一天
4597
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
4598
+ // 计算到最近的星期四的完整周数
4599
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
4600
+ // 返回周数
4601
+ return weekNo;
4602
+ };
4603
+
4604
+ var getRangeHours = function getRangeHours(ranges) {
4605
+ var hours = [];
4606
+ var disabledHours = [];
4607
+
4608
+ (ranges || []).forEach(function (range) {
4609
+ var value = range.map(function (date) {
4610
+ return date.getHours();
4611
+ });
4612
+
4613
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
4614
+ });
4615
+
4616
+ if (disabledHours.length) {
4617
+ for (var i = 0; i < 24; i++) {
4618
+ hours[i] = disabledHours.indexOf(i) === -1;
4619
+ }
4620
+ } else {
4621
+ for (var _i = 0; _i < 24; _i++) {
4622
+ hours[_i] = false;
4623
+ }
4624
+ }
4625
+
4626
+ return hours;
4627
+ };
4628
+
4629
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
4630
+ if (amount <= 0) return [];
4631
+ var temp = new Date(date.getTime());
4632
+ temp.setDate(0);
4633
+ var lastDay = temp.getDate();
4634
+ return range(amount).map(function (_, index) {
4635
+ return lastDay - (amount - index - 1);
4636
+ });
4637
+ };
4638
+
4639
+ var getMonthDays = function getMonthDays(date) {
4640
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
4641
+ var days = temp.getDate();
4642
+ return range(days).map(function (_, index) {
4643
+ return index + 1;
4644
+ });
4645
+ };
4646
+
4647
+ function setRangeData(arr, start, end, value) {
4648
+ for (var i = start; i < end; i++) {
4649
+ arr[i] = value;
4650
+ }
4651
+ }
4652
+
4653
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
4654
+ var minutes = new Array(60);
4655
+
4656
+ if (ranges.length > 0) {
4657
+ ranges.forEach(function (range) {
4658
+ var start = range[0];
4659
+ var end = range[1];
4660
+ var startHour = start.getHours();
4661
+ var startMinute = start.getMinutes();
4662
+ var endHour = end.getHours();
4663
+ var endMinute = end.getMinutes();
4664
+ if (startHour === hour && endHour !== hour) {
4665
+ setRangeData(minutes, startMinute, 60, true);
4666
+ } else if (startHour === hour && endHour === hour) {
4667
+ setRangeData(minutes, startMinute, endMinute + 1, true);
4668
+ } else if (startHour !== hour && endHour === hour) {
4669
+ setRangeData(minutes, 0, endMinute + 1, true);
4670
+ } else if (startHour < hour && endHour > hour) {
4671
+ setRangeData(minutes, 0, 60, true);
4672
+ }
4673
+ });
4674
+ } else {
4675
+ setRangeData(minutes, 0, 60, true);
4676
+ }
4677
+ return minutes;
4678
+ };
4679
+
4680
+ var range = function range(n) {
4681
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
4682
+ return Array.apply(null, { length: n }).map(function (_, n) {
4683
+ return n;
4684
+ });
4685
+ };
4686
+
4687
+ var modifyDate = function modifyDate(date, y, m, d) {
4688
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
4689
+ };
4690
+
4691
+ var modifyTime = function modifyTime(date, h, m, s) {
4692
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
4693
+ };
4694
+
4695
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
4696
+ if (date == null || !time) {
4697
+ return date;
4698
+ }
4699
+ time = parseDate(time, 'HH:mm:ss');
4700
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
4701
+ };
4702
+
4703
+ var clearTime = function clearTime(date) {
4704
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
4705
+ };
4706
+
4707
+ var clearMilliseconds = function clearMilliseconds(date) {
4708
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
4709
+ };
4710
+
4711
+ var limitTimeRange = function limitTimeRange(date, ranges) {
4712
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
4713
+
4714
+ // TODO: refactory a more elegant solution
4715
+ if (ranges.length === 0) return date;
4716
+ var normalizeDate = function normalizeDate(date) {
4717
+ return fecha.parse(fecha.format(date, format), format);
4718
+ };
4719
+ var ndate = normalizeDate(date);
4720
+ var nranges = ranges.map(function (range) {
4721
+ return range.map(normalizeDate);
4722
+ });
4723
+ if (nranges.some(function (nrange) {
4724
+ return ndate >= nrange[0] && ndate <= nrange[1];
4725
+ })) return date;
4726
+
4727
+ var minDate = nranges[0][0];
4728
+ var maxDate = nranges[0][0];
4729
+
4730
+ nranges.forEach(function (nrange) {
4731
+ minDate = new Date(Math.min(nrange[0], minDate));
4732
+ maxDate = new Date(Math.max(nrange[1], minDate));
4733
+ });
4734
+
4735
+ var ret = ndate < minDate ? minDate : maxDate;
4736
+ // preserve Year/Month/Date
4737
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
4738
+ };
4739
+
4740
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
4741
+ var limitedDate = limitTimeRange(date, selectableRange, format);
4742
+ return limitedDate.getTime() === date.getTime();
4743
+ };
4744
+
4745
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
4746
+ // clamp date to the number of days in `year`, `month`
4747
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
4748
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
4749
+ return modifyDate(date, year, month, monthDate);
4750
+ };
4751
+
4752
+ var prevMonth = function prevMonth(date) {
4753
+ var year = date.getFullYear();
4754
+ var month = date.getMonth();
4755
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
4756
+ };
4757
+
4758
+ var nextMonth = function nextMonth(date) {
4759
+ var year = date.getFullYear();
4760
+ var month = date.getMonth();
4761
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
4762
+ };
4763
+
4764
+ var prevYear = function prevYear(date) {
4765
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4766
+
4767
+ var year = date.getFullYear();
4768
+ var month = date.getMonth();
4769
+ return changeYearMonthAndClampDate(date, year - amount, month);
4770
+ };
4771
+
4772
+ var nextYear = function nextYear(date) {
4773
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4774
+
4775
+ var year = date.getFullYear();
4776
+ var month = date.getMonth();
4777
+ return changeYearMonthAndClampDate(date, year + amount, month);
4778
+ };
4779
+
4780
+ var extractDateFormat = function extractDateFormat(format) {
4781
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
4782
+ };
4783
+
4784
+ var extractTimeFormat = function extractTimeFormat(format) {
4785
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
4786
+ };
4787
+
4788
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
4789
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
4790
+ };
4791
+
4810
4792
  /**
4811
4793
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
4812
4794
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
4813
4795
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
4814
4796
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
4815
4797
  * @returns {number} 工作日数量
4816
- */
4817
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
4818
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
4819
- throw new Error(
4820
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
4821
- );
4822
- }
4823
-
4824
- const startDateObj = new Date(start_date);
4825
- const endDateObj = new Date(end_date);
4826
-
4827
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
4828
- throw new Error(
4829
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
4830
- );
4831
- }
4832
-
4833
- if (startDateObj > endDateObj) {
4834
- throw new Error('Start date should be earlier than or equal to end date.');
4835
- }
4836
-
4837
- let workdays = 0;
4838
-
4839
- // Iterate through each day in the date range
4840
- for (
4841
- let currentDate = new Date(startDateObj);
4842
- currentDate <= endDateObj;
4843
- currentDate.setDate(currentDate.getDate() + 1)
4844
- ) {
4845
- // Check if the current day is a weekend (Saturday or Sunday)
4846
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
4847
-
4848
- // Check if the current day is a holiday
4849
- const isHoliday = holidays.some((holiday) => {
4850
- const holidayDate = new Date(holiday);
4851
- return currentDate.toDateString() === holidayDate.toDateString();
4852
- });
4853
-
4854
- // If it's a workday (not a weekend or holiday), increment the workdays count
4855
- if (!isWeekend && !isHoliday) {
4856
- workdays++;
4857
- }
4858
- }
4859
-
4860
- return workdays;
4861
- };
4862
-
4798
+ */
4799
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
4800
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
4801
+
4802
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
4803
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
4804
+ }
4805
+
4806
+ var startDateObj = new Date(start_date);
4807
+ var endDateObj = new Date(end_date);
4808
+
4809
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
4810
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
4811
+ }
4812
+
4813
+ if (startDateObj > endDateObj) {
4814
+ throw new Error('Start date should be earlier than or equal to end date.');
4815
+ }
4816
+
4817
+ var workdays = 0;
4818
+
4819
+ // Iterate through each day in the date range
4820
+
4821
+ var _loop = function _loop(currentDate) {
4822
+ // Check if the current day is a weekend (Saturday or Sunday)
4823
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
4824
+
4825
+ // Check if the current day is a holiday
4826
+ var isHoliday = holidays.some(function (holiday) {
4827
+ var holidayDate = new Date(holiday);
4828
+ return currentDate.toDateString() === holidayDate.toDateString();
4829
+ });
4830
+
4831
+ // If it's a workday (not a weekend or holiday), increment the workdays count
4832
+ if (!isWeekend && !isHoliday) {
4833
+ workdays++;
4834
+ }
4835
+ };
4836
+
4837
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
4838
+ _loop(currentDate);
4839
+ }
4840
+
4841
+ return workdays;
4842
+ };
4843
+
4863
4844
  /**
4864
4845
  * 日期加减天数
4865
4846
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
4866
4847
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
4867
4848
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
4868
- */
4869
- const dateAddDays = function (start_date, days) {
4870
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
4871
- throw new Error(
4872
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
4873
- );
4874
- }
4875
-
4876
- const startDateObj = new Date(start_date);
4877
- if (isNaN(startDateObj.getTime())) {
4878
- throw new Error(
4879
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
4880
- );
4881
- }
4882
-
4883
- const resultDateObj = new Date(startDateObj);
4884
- resultDateObj.setDate(resultDateObj.getDate() + days);
4885
-
4886
- const resultYear = resultDateObj.getFullYear();
4887
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
4888
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
4889
-
4890
- return `${resultYear}-${resultMonth}-${resultDay}`;
4891
- };
4892
-
4849
+ */
4850
+ var dateAddDays = function dateAddDays(start_date, days) {
4851
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
4852
+ 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.");
4853
+ }
4854
+
4855
+ var startDateObj = new Date(start_date);
4856
+ if (isNaN(startDateObj.getTime())) {
4857
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
4858
+ }
4859
+
4860
+ var resultDateObj = new Date(startDateObj);
4861
+ resultDateObj.setDate(resultDateObj.getDate() + days);
4862
+
4863
+ var resultYear = resultDateObj.getFullYear();
4864
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
4865
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
4866
+
4867
+ return resultYear + '-' + resultMonth + '-' + resultDay;
4868
+ };
4869
+
4893
4870
  /**
4894
4871
  * 计算两个日期之间的差值
4895
4872
  * @date 2023年12月14日
@@ -4897,182 +4874,180 @@ const dateAddDays = function (start_date, days) {
4897
4874
  * @param {String} end_date - 结束日期字符串
4898
4875
  * @param {String} unit - 单位:year/month/day
4899
4876
  * @returns {Number} 差值
4900
- */
4901
- const dateDiff = function (start_date, end_date, unit = 'day') {
4902
- // Assuming date strings are in "YYYY-MM-DD" format
4903
- var startDate = new Date(start_date);
4904
- var endDate = new Date(end_date);
4905
-
4906
- // If the date is invalid, return 0
4907
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
4908
- return 0;
4909
- }
4910
-
4911
- if (unit === 'year') {
4912
- return endDate.getFullYear() - startDate.getFullYear();
4913
- } else if (unit === 'month') {
4914
- return (
4915
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
4916
- (endDate.getMonth() - startDate.getMonth())
4917
- );
4918
- } else {
4919
- // Default to day
4920
- var timeDifference = endDate - startDate;
4921
- // Calculate days (86400000 milliseconds per day)
4922
- return Math.floor(timeDifference / 86400000);
4923
- }
4924
- };
4925
-
4877
+ */
4878
+ var dateDiff = function dateDiff(start_date, end_date) {
4879
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
4880
+
4881
+ // Assuming date strings are in "YYYY-MM-DD" format
4882
+ var startDate = new Date(start_date);
4883
+ var endDate = new Date(end_date);
4884
+
4885
+ // If the date is invalid, return 0
4886
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
4887
+ return 0;
4888
+ }
4889
+
4890
+ if (unit === 'year') {
4891
+ return endDate.getFullYear() - startDate.getFullYear();
4892
+ } else if (unit === 'month') {
4893
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
4894
+ } else {
4895
+ // Default to day
4896
+ var timeDifference = endDate - startDate;
4897
+ // Calculate days (86400000 milliseconds per day)
4898
+ return Math.floor(timeDifference / 86400000);
4899
+ }
4900
+ };
4901
+
4926
4902
  /**
4927
4903
  * 获取月份中的日期
4928
4904
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
4929
4905
  * @returns {number} 月份中的日期(1-31)
4930
- */
4931
- const dayOfMonth = function (date) {
4932
- if (typeof date !== 'string') {
4933
- throw new Error(
4934
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
4935
- );
4936
- }
4937
-
4938
- const dateObj = new Date(date);
4939
- if (isNaN(dateObj.getTime())) {
4940
- throw new Error(
4941
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
4942
- );
4943
- }
4944
-
4945
- return dateObj.getDate();
4946
- };
4947
-
4906
+ */
4907
+ var dayOfMonth = function dayOfMonth(date) {
4908
+ if (typeof date !== 'string') {
4909
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
4910
+ }
4911
+
4912
+ var dateObj = new Date(date);
4913
+ if (isNaN(dateObj.getTime())) {
4914
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
4915
+ }
4916
+
4917
+ return dateObj.getDate();
4918
+ };
4919
+
4948
4920
  /**
4949
4921
  * 获取当前日期
4950
4922
  * @date 2022年5月7日
4951
4923
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
4952
4924
  * @returns {string} 当前日期的格式化字符串
4953
- */
4954
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
4955
- return formatDate(new Date(), format);
4956
- };
4957
-
4925
+ */
4926
+ var getCurrentDate = function getCurrentDate() {
4927
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
4928
+
4929
+ return formatDate(new Date(), format);
4930
+ };
4931
+
4958
4932
  /**
4959
4933
  * 获取当前日期时间
4960
4934
  * @date 2022年5月7日
4961
4935
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
4962
4936
  * @returns {string} 当前日期时间的格式化字符串
4963
- */
4964
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
4965
- return formatDate(new Date(), format);
4966
- };
4967
-
4937
+ */
4938
+ var getCurrentDateTime = function getCurrentDateTime() {
4939
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
4940
+
4941
+ return formatDate(new Date(), format);
4942
+ };
4943
+
4968
4944
  /**
4969
4945
  * 获取小时
4970
4946
  * @date 2022年5月7日
4971
4947
  * @param {Date|string} [date] - 日期对象或日期字符串
4972
4948
  * @returns {number} 小时数(0-23)
4973
- */
4974
- const getHour = function (date) {
4975
- if (!date) {
4976
- return new Date().getHours();
4977
- }
4978
- if (typeof date === 'string') {
4979
- date = new Date(date);
4980
- }
4981
- return date.getHours();
4982
- };
4983
-
4949
+ */
4950
+ var getHour = function getHour(date) {
4951
+ if (!date) {
4952
+ return new Date().getHours();
4953
+ }
4954
+ if (typeof date === 'string') {
4955
+ date = new Date(date);
4956
+ }
4957
+ return date.getHours();
4958
+ };
4959
+
4984
4960
  /**
4985
4961
  * 获取分钟
4986
4962
  * @date 2022年5月7日
4987
4963
  * @param {Date|string} [date] - 日期对象或日期字符串
4988
4964
  * @returns {number} 分钟数(0-59)
4989
- */
4990
- const getMinute = function (date) {
4991
- if (!date) {
4992
- return new Date().getMinutes();
4993
- }
4994
- if (typeof date === 'string') {
4995
- date = new Date(date);
4996
- }
4997
- return date.getMinutes();
4998
- };
4999
-
4965
+ */
4966
+ var getMinute = function getMinute(date) {
4967
+ if (!date) {
4968
+ return new Date().getMinutes();
4969
+ }
4970
+ if (typeof date === 'string') {
4971
+ date = new Date(date);
4972
+ }
4973
+ return date.getMinutes();
4974
+ };
4975
+
5000
4976
  /**
5001
4977
  * 获取月份
5002
4978
  * @date 2022年5月7日
5003
4979
  * @param {Date|string} [date] - 日期对象或日期字符串
5004
4980
  * @returns {number} 月份数(1-12)
5005
- */
5006
- const getMonth = function (date) {
5007
- if (!date) {
5008
- return new Date().getMonth() + 1;
5009
- }
5010
- if (typeof date === 'string') {
5011
- date = new Date(date);
5012
- }
5013
- return date.getMonth() + 1;
5014
- };
5015
-
4981
+ */
4982
+ var getMonth = function getMonth(date) {
4983
+ if (!date) {
4984
+ return new Date().getMonth() + 1;
4985
+ }
4986
+ if (typeof date === 'string') {
4987
+ date = new Date(date);
4988
+ }
4989
+ return date.getMonth() + 1;
4990
+ };
4991
+
5016
4992
  /**
5017
4993
  * 获取秒
5018
4994
  * @date 2022年5月7日
5019
4995
  * @param {Date|string} [date] - 日期对象或日期字符串
5020
4996
  * @returns {number} 秒数(0-59)
5021
- */
5022
- const getSecond = function (date) {
5023
- if (!date) {
5024
- return new Date().getSeconds();
5025
- }
5026
- if (typeof date === 'string') {
5027
- date = new Date(date);
5028
- }
5029
- return date.getSeconds();
5030
- };
5031
-
4997
+ */
4998
+ var getSecond = function getSecond(date) {
4999
+ if (!date) {
5000
+ return new Date().getSeconds();
5001
+ }
5002
+ if (typeof date === 'string') {
5003
+ date = new Date(date);
5004
+ }
5005
+ return date.getSeconds();
5006
+ };
5007
+
5032
5008
  /**
5033
5009
  * 获取星期几
5034
5010
  * @date 2022年5月7日
5035
5011
  * @param {Date|string} [date] - 日期对象或日期字符串
5036
5012
  * @returns {number} 星期几(0-6,0表示星期日)
5037
- */
5038
- const getWeekday = function (date) {
5039
- if (!date) {
5040
- return new Date().getDay();
5041
- }
5042
- if (typeof date === 'string') {
5043
- date = new Date(date);
5044
- }
5045
- return date.getDay();
5046
- };
5047
-
5048
-
5013
+ */
5014
+ var getWeekday = function getWeekday(date) {
5015
+ if (!date) {
5016
+ return new Date().getDay();
5017
+ }
5018
+ if (typeof date === 'string') {
5019
+ date = new Date(date);
5020
+ }
5021
+ return date.getDay();
5022
+ };
5023
+
5049
5024
  /**
5050
5025
  * @desc 获取上午/下午/晚上
5051
5026
  * @author huangbo
5052
5027
  * @date 2022年5月7日
5053
5028
  * @param {String} [time] - 时间
5054
- **/
5055
- const timeCycle = function (time) {
5056
- let hour = 0;
5057
- if (!time) {
5058
- hour = new Date().getHours();
5059
- } else if (typeof time === 'string') {
5060
- // 从时间字符串中提取小时
5061
- const match = time.match(/^(\d{1,2})/);
5062
- if (match) {
5063
- hour = parseInt(match[1], 10);
5064
- }
5065
- } else if (typeof time === 'number') {
5066
- hour = time;
5067
- }
5068
- // 判断时间段
5069
- if (hour >= 5 && hour < 12) {
5070
- return '上午';
5071
- } else if (hour >= 12 && hour < 18) {
5072
- return '下午';
5073
- } else {
5074
- return '晚上';
5075
- }
5029
+ **/
5030
+ var timeCycle = function timeCycle(time) {
5031
+ var hour = 0;
5032
+ if (!time) {
5033
+ hour = new Date().getHours();
5034
+ } else if (typeof time === 'string') {
5035
+ // 从时间字符串中提取小时
5036
+ var match = time.match(/^(\d{1,2})/);
5037
+ if (match) {
5038
+ hour = parseInt(match[1], 10);
5039
+ }
5040
+ } else if (typeof time === 'number') {
5041
+ hour = time;
5042
+ }
5043
+ // 判断时间段
5044
+ if (hour >= 5 && hour < 12) {
5045
+ return '上午';
5046
+ } else if (hour >= 12 && hour < 18) {
5047
+ return '下午';
5048
+ } else {
5049
+ return '晚上';
5050
+ }
5076
5051
  };
5077
5052
 
5078
5053
  /***/ }),