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