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