eoss 0.1.0-alpha.35 → 0.1.0-alpha.36

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 (136) hide show
  1. package/lib/account-login.js +912 -856
  2. package/lib/alert.js +2 -2
  3. package/lib/aside.js +2 -2
  4. package/lib/audit-trajectory.js +2 -2
  5. package/lib/autocomplete.js +2001 -1777
  6. package/lib/avatar.js +2 -2
  7. package/lib/backtop.js +2 -2
  8. package/lib/badge.js +2 -2
  9. package/lib/breadcrumb-item.js +4 -4
  10. package/lib/breadcrumb.js +4 -4
  11. package/lib/button-group.js +2 -2
  12. package/lib/button.js +2 -2
  13. package/lib/ca-login.js +862 -837
  14. package/lib/calendar.js +862 -837
  15. package/lib/card.js +2 -2
  16. package/lib/carousel-item.js +864 -839
  17. package/lib/carousel.js +864 -839
  18. package/lib/cascader-panel.js +864 -839
  19. package/lib/cascader.js +2003 -1779
  20. package/lib/checkbox-button.js +2 -2
  21. package/lib/checkbox-group.js +864 -839
  22. package/lib/checkbox.js +2 -2
  23. package/lib/col.js +2 -2
  24. package/lib/collapse-item.js +864 -839
  25. package/lib/collapse.js +864 -839
  26. package/lib/color-picker.js +1141 -942
  27. package/lib/container.js +2 -2
  28. package/lib/cron.js +2 -2
  29. package/lib/data-table.js +871 -846
  30. package/lib/date-picker.js +2003 -1779
  31. package/lib/descriptions-item.js +144 -0
  32. package/lib/descriptions.js +561 -0
  33. package/lib/dialog.js +862 -837
  34. package/lib/divider.js +2 -2
  35. package/lib/drawer.js +2 -2
  36. package/lib/dropdown-item.js +4 -4
  37. package/lib/dropdown-menu.js +1141 -942
  38. package/lib/dropdown.js +862 -837
  39. package/lib/email-login.js +862 -837
  40. package/lib/empty.js +2 -2
  41. package/lib/eoss.common.js +2485 -1819
  42. package/lib/flip.js +2 -2
  43. package/lib/flow-group.js +866 -841
  44. package/lib/flow.js +871 -846
  45. package/lib/flows.js +862 -837
  46. package/lib/footer.js +2 -2
  47. package/lib/form-item.js +875 -850
  48. package/lib/form.js +876 -849
  49. package/lib/guide.js +2 -2
  50. package/lib/header.js +2 -2
  51. package/lib/icon.js +862 -837
  52. package/lib/icons.js +2 -2
  53. package/lib/image-viewer.js +862 -837
  54. package/lib/image.js +4 -4
  55. package/lib/index.js +1 -1
  56. package/lib/infinite-scroll.js +2 -2
  57. package/lib/input-number.js +2 -2
  58. package/lib/input.js +884 -859
  59. package/lib/link.js +2 -2
  60. package/lib/loading.js +2 -2
  61. package/lib/login.js +913 -873
  62. package/lib/lowcode-view.js +862 -837
  63. package/lib/lowcode.js +901 -876
  64. package/lib/main.js +908 -880
  65. package/lib/marquee.js +862 -837
  66. package/lib/menu-item-group.js +2 -2
  67. package/lib/menu-item.js +2 -2
  68. package/lib/menu.js +2003 -1779
  69. package/lib/message-box.js +862 -837
  70. package/lib/message.js +884 -859
  71. package/lib/notification.js +862 -837
  72. package/lib/option-group.js +4 -4
  73. package/lib/option.js +871 -846
  74. package/lib/page-header.js +2 -2
  75. package/lib/pagination.js +862 -837
  76. package/lib/phone-login.js +862 -837
  77. package/lib/popconfirm.js +4 -4
  78. package/lib/popover.js +2001 -1777
  79. package/lib/process-config.js +869 -844
  80. package/lib/process-module.js +862 -837
  81. package/lib/process-rule.js +862 -837
  82. package/lib/progress.js +2 -2
  83. package/lib/qr-code.js +4 -4
  84. package/lib/qrcode-login.js +870 -845
  85. package/lib/radio-button.js +2 -2
  86. package/lib/radio-group.js +871 -846
  87. package/lib/radio.js +2 -2
  88. package/lib/rate.js +862 -837
  89. package/lib/row.js +2 -2
  90. package/lib/scrollbar.js +862 -837
  91. package/lib/select.js +2005 -1781
  92. package/lib/selector-panel.js +873 -848
  93. package/lib/selector.js +866 -841
  94. package/lib/slider.js +2 -2
  95. package/lib/step.js +5 -5
  96. package/lib/steps.js +865 -840
  97. package/lib/submenu.js +1143 -944
  98. package/lib/switch.js +862 -837
  99. package/lib/tab-pane.js +4 -4
  100. package/lib/table-column.js +862 -837
  101. package/lib/table.js +2003 -1779
  102. package/lib/tabs.js +864 -839
  103. package/lib/tag.js +2 -2
  104. package/lib/theme-chalk/base.css +1 -1
  105. package/lib/theme-chalk/descriptions.css +1 -1
  106. package/lib/theme-chalk/index.css +1 -1
  107. package/lib/theme-chalk/main.css +1 -1
  108. package/lib/time-picker.js +2004 -1780
  109. package/lib/time-select.js +2001 -1777
  110. package/lib/timeline-item.js +2 -2
  111. package/lib/timeline.js +2 -2
  112. package/lib/tips.js +862 -837
  113. package/lib/toolbar.js +2 -2
  114. package/lib/tooltip.js +2003 -1779
  115. package/lib/transfer.js +869 -844
  116. package/lib/tree-group.js +862 -837
  117. package/lib/tree.js +862 -837
  118. package/lib/update-history.js +2 -2
  119. package/lib/upload.js +868 -843
  120. package/lib/utils/popper.js +97 -48
  121. package/lib/wujie.js +866 -841
  122. package/package.json +1 -1
  123. package/packages/account-login/src/account-login.vue +29 -0
  124. package/packages/descriptions/index.js +8 -0
  125. package/packages/descriptions/src/index.js +181 -0
  126. package/packages/descriptions/src/item.js +30 -0
  127. package/packages/descriptions/src/row.js +120 -0
  128. package/packages/descriptions-item/index.js +8 -0
  129. package/packages/login/src/login.vue +8 -0
  130. package/packages/login/src/mixins.js +3 -1
  131. package/packages/main/src/minxs.js +1 -0
  132. package/packages/theme-chalk/src/base.scss +2 -1
  133. package/packages/theme-chalk/src/descriptions.scss +0 -1
  134. package/packages/theme-chalk/src/index.scss +2 -0
  135. package/src/index.js +333 -327
  136. package/src/utils/popper.js +109 -70
@@ -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 = 215);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 217);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3601,14 +3601,14 @@ var doDecrypt = function doDecrypt(_ref2) {
3601
3601
 
3602
3602
  /***/ }),
3603
3603
 
3604
- /***/ 215:
3604
+ /***/ 217:
3605
3605
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3606
3606
 
3607
3607
  "use strict";
3608
3608
  // ESM COMPAT FLAG
3609
3609
  __webpack_require__.r(__webpack_exports__);
3610
3610
 
3611
- // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/account-login/src/account-login.vue?vue&type=template&id=18cdaf78&
3611
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/account-login/src/account-login.vue?vue&type=template&id=43e7d724&
3612
3612
  var render = function () {
3613
3613
  var _vm = this
3614
3614
  var _h = _vm.$createElement
@@ -3831,7 +3831,7 @@ var staticRenderFns = []
3831
3831
  render._withStripped = true
3832
3832
 
3833
3833
 
3834
- // CONCATENATED MODULE: ./packages/account-login/src/account-login.vue?vue&type=template&id=18cdaf78&
3834
+ // CONCATENATED MODULE: ./packages/account-login/src/account-login.vue?vue&type=template&id=43e7d724&
3835
3835
 
3836
3836
  // EXTERNAL MODULE: ./src/utils/util.js
3837
3837
  var util = __webpack_require__(1);
@@ -4090,6 +4090,11 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
4090
4090
  },
4091
4091
  isSubmit: function isSubmit(val) {
4092
4092
  this.submit = val;
4093
+ },
4094
+
4095
+ //账号变化时回传给父组件(如 login.vue 重置密码弹窗需要)
4096
+ 'formData.username': function formDataUsername(val) {
4097
+ this.$emit('username-change', val);
4093
4098
  }
4094
4099
  },
4095
4100
  computed: {
@@ -4159,6 +4164,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
4159
4164
  },
4160
4165
  created: function created() {
4161
4166
  this.getImgCode();
4167
+ this.fillRemembered();
4162
4168
  },
4163
4169
  mounted: function mounted() {
4164
4170
  window.addEventListener('keyup', this.handleKeyup);
@@ -4181,30 +4187,55 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
4181
4187
  this.formData.password = user.password;
4182
4188
  }
4183
4189
  },
4190
+
4191
+ //页面加载后若存在“记住密码”缓存,回填账号密码并把username同步给父组件
4192
+ fillRemembered: function fillRemembered() {
4193
+ var _this2 = this;
4194
+
4195
+ var keys = Object.keys(this.remembers);
4196
+ if (!keys.length) {
4197
+ return;
4198
+ }
4199
+ var lastKey = keys[keys.length - 1];
4200
+ //外部model已指定账号时仅按命中缓存补密码,否则回填最近一次记住的账号
4201
+ var target = this.users.find(function (item) {
4202
+ return item.username === _this2.formData.username;
4203
+ }) || (this.formData.username ? null : {
4204
+ username: Object(util["i" /* decode */])(lastKey),
4205
+ password: Object(util["i" /* decode */])(this.remembers[lastKey])
4206
+ });
4207
+ if (!target) {
4208
+ return;
4209
+ }
4210
+ this.formData.username = target.username;
4211
+ this.formData.password = target.password;
4212
+ this.checked = true;
4213
+ this.$emit('username-change', target.username);
4214
+ },
4184
4215
  handlePaste: function handlePaste(event) {
4185
4216
  this.$emit('paste', event);
4186
4217
  },
4187
4218
  handleSubmit: function handleSubmit() {
4188
- var _this2 = this;
4219
+ var _this3 = this;
4189
4220
 
4190
4221
  this.$refs.loginForm && this.$refs.loginForm.validate().then(function () {
4191
- _this2.submit = true;
4192
- if (_this2.action) {
4222
+ _this3.submit = true;
4223
+ if (_this3.action) {
4193
4224
  var loadingInstance = Object(util["K" /* loading */])('登录中...');
4194
4225
  var extUserBindHandleId = sessionStorage.getItem('extUserBindHandleId');
4195
4226
  // const extUserBindHandleId = sessionStorage.getItem(
4196
4227
  // 'extUserBindHandleId'
4197
4228
  // );
4198
- var data = _extends({}, _this2.formData, _this2.data, {
4199
- identifyingId: _this2.identifyingId
4229
+ var data = _extends({}, _this3.formData, _this3.data, {
4230
+ identifyingId: _this3.identifyingId
4200
4231
  });
4201
4232
  if (extUserBindHandleId) {
4202
4233
  data.extUserBindHandleId = extUserBindHandleId;
4203
4234
  }
4204
4235
  Object(ajax["a" /* ajax */])({
4205
4236
  method: 'POST',
4206
- url: _this2.action,
4207
- encryption: _this2.encryption,
4237
+ url: _this3.action,
4238
+ encryption: _this3.encryption,
4208
4239
  data: data
4209
4240
  }).then(function (res) {
4210
4241
  var rCode = res.rCode,
@@ -4216,29 +4247,29 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
4216
4247
 
4217
4248
  if (statusCode === 1) {
4218
4249
  Object(util["m" /* error */])(msg || '登录失败!', function () {
4219
- _this2.$emit('error', res);
4220
- _this2.resetCode();
4250
+ _this3.$emit('error', res);
4251
+ _this3.resetCode();
4221
4252
  });
4222
4253
  } else {
4223
- if (_this2.checked) {
4224
- _this2.$set(_this2.remembers, Object(util["l" /* encode */])(_this2.formData.username), Object(util["l" /* encode */])(_this2.formData.password));
4225
- localStorage.setItem('remembers', JSON.stringify(_this2.remembers));
4254
+ if (_this3.checked) {
4255
+ _this3.$set(_this3.remembers, Object(util["l" /* encode */])(_this3.formData.username), Object(util["l" /* encode */])(_this3.formData.password));
4256
+ localStorage.setItem('remembers', JSON.stringify(_this3.remembers));
4226
4257
  }
4227
- _this2.$emit('success', results);
4258
+ _this3.$emit('success', results);
4228
4259
  }
4229
4260
  } else {
4230
4261
  Object(util["m" /* error */])(res.msg || '登录失败!', function () {
4231
- _this2.$emit('error', res);
4232
- _this2.resetCode();
4262
+ _this3.$emit('error', res);
4263
+ _this3.resetCode();
4233
4264
  });
4234
4265
  }
4235
4266
  loadingInstance.close();
4236
4267
  }).catch(function () {
4237
4268
  loadingInstance.close();
4238
- _this2.resetCode();
4269
+ _this3.resetCode();
4239
4270
  });
4240
4271
  }
4241
- _this2.$emit('submit', _this2.formData);
4272
+ _this3.$emit('submit', _this3.formData);
4242
4273
  }).catch(function () {});
4243
4274
  },
4244
4275
  resetCode: function resetCode() {
@@ -5149,736 +5180,759 @@ var changeInTime = '/baseIssueRules/changeInTime';
5149
5180
  /* unused harmony export getSecond */
5150
5181
  /* unused harmony export getWeekday */
5151
5182
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5152
-
5153
-
5183
+ /* Modified from https://github.com/taylorhakes/fecha
5184
+ *
5185
+ * The MIT License (MIT)
5186
+ *
5187
+ * Copyright (c) 2015 Taylor Hakes
5188
+ *
5189
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5190
+ * of this software and associated documentation files (the "Software"), to deal
5191
+ * in the Software without restriction, including without limitation the rights
5192
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5193
+ * copies of the Software, and to permit persons to whom the Software is
5194
+ * furnished to do so, subject to the following conditions:
5195
+ *
5196
+ * The above copyright notice and this permission notice shall be included in all
5197
+ * copies or substantial portions of the Software.
5198
+ *
5199
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5200
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5201
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5202
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5203
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5204
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5205
+ * SOFTWARE.
5206
+ */
5207
+
5208
+ /*eslint-disable*/
5209
+ // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5210
+
5211
+
5154
5212
  /**
5155
5213
  * Parse or format dates
5156
5214
  * @class fecha
5157
- */
5158
- var fecha = {};
5159
- var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5160
- var twoDigits = '\\d\\d?';
5161
- var threeDigits = '\\d{3}';
5162
- var fourDigits = '\\d{4}';
5163
- var word = '[^\\s]+';
5164
- var literal = /\[([^]*?)\]/gm;
5165
- var noop = function noop() {};
5166
-
5167
- function regexEscape(str) {
5168
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5169
- }
5170
-
5171
- function shorten(arr, sLen) {
5172
- var newArr = [];
5173
- for (var i = 0, len = arr.length; i < len; i++) {
5174
- newArr.push(arr[i].substr(0, sLen));
5175
- }
5176
- return newArr;
5177
- }
5178
-
5179
- function monthUpdate() {
5180
- return function (d, v) {
5181
- var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5182
- if (~index) {
5183
- d.month = index;
5184
- }
5185
- };
5186
- }
5187
-
5188
- function pad(val, len) {
5189
- val = String(val);
5190
- len = len || 2;
5191
- while (val.length < len) {
5192
- val = '0' + val;
5193
- }
5194
- return val;
5195
- }
5196
-
5197
- // 直接使用中文日期名称常量
5198
- var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5199
- var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5200
- var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5201
- var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5202
- var amPm = ['上午', '下午'];
5203
- var DoFn = function DoFn(D) {
5204
- return D + '日';
5205
- };
5206
-
5207
- var formatFlags = {
5208
- D: function D(dateObj) {
5209
- return dateObj.getDay();
5210
- },
5211
- DD: function DD(dateObj) {
5212
- return pad(dateObj.getDay());
5213
- },
5214
- Do: function Do(dateObj) {
5215
- return DoFn(dateObj.getDate());
5216
- },
5217
- d: function d(dateObj) {
5218
- return dateObj.getDate();
5219
- },
5220
- dd: function dd(dateObj) {
5221
- return pad(dateObj.getDate());
5222
- },
5223
- ddd: function ddd(dateObj) {
5224
- return dayNamesShort[dateObj.getDay()];
5225
- },
5226
- dddd: function dddd(dateObj) {
5227
- return dayNames[dateObj.getDay()];
5228
- },
5229
- M: function M(dateObj) {
5230
- return dateObj.getMonth() + 1;
5231
- },
5232
- MM: function MM(dateObj) {
5233
- return pad(dateObj.getMonth() + 1);
5234
- },
5235
- MMM: function MMM(dateObj) {
5236
- return monthNamesShort[dateObj.getMonth()];
5237
- },
5238
- MMMM: function MMMM(dateObj) {
5239
- return monthNames[dateObj.getMonth()];
5240
- },
5241
- yy: function yy(dateObj) {
5242
- return pad(String(dateObj.getFullYear()), 4).substr(2);
5243
- },
5244
- yyyy: function yyyy(dateObj) {
5245
- return pad(dateObj.getFullYear(), 4);
5246
- },
5247
- h: function h(dateObj) {
5248
- return dateObj.getHours() % 12 || 12;
5249
- },
5250
- hh: function hh(dateObj) {
5251
- return pad(dateObj.getHours() % 12 || 12);
5252
- },
5253
- H: function H(dateObj) {
5254
- return dateObj.getHours();
5255
- },
5256
- HH: function HH(dateObj) {
5257
- return pad(dateObj.getHours());
5258
- },
5259
- m: function m(dateObj) {
5260
- return dateObj.getMinutes();
5261
- },
5262
- mm: function mm(dateObj) {
5263
- return pad(dateObj.getMinutes());
5264
- },
5265
- s: function s(dateObj) {
5266
- return dateObj.getSeconds();
5267
- },
5268
- ss: function ss(dateObj) {
5269
- return pad(dateObj.getSeconds());
5270
- },
5271
- S: function S(dateObj) {
5272
- return Math.round(dateObj.getMilliseconds() / 100);
5273
- },
5274
- SS: function SS(dateObj) {
5275
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5276
- },
5277
- SSS: function SSS(dateObj) {
5278
- return pad(dateObj.getMilliseconds(), 3);
5279
- },
5280
- a: function a(dateObj) {
5281
- return dateObj.getHours() < 12 ? '上午' : '下午';
5282
- },
5283
- A: function A(dateObj) {
5284
- return dateObj.getHours() < 12 ? '上午' : '下午';
5285
- },
5286
- ZZ: function ZZ(dateObj) {
5287
- var o = dateObj.getTimezoneOffset();
5288
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5289
- }
5290
- };
5291
-
5292
- var parseFlags = {
5293
- d: [twoDigits, function (d, v) {
5294
- d.day = v;
5295
- }],
5296
- Do: [twoDigits + word, function (d, v) {
5297
- d.day = parseInt(v, 10);
5298
- }],
5299
- M: [twoDigits, function (d, v) {
5300
- d.month = v - 1;
5301
- }],
5302
- yy: [twoDigits, function (d, v) {
5303
- var da = new Date(),
5304
- cent = +('' + da.getFullYear()).substr(0, 2);
5305
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5306
- }],
5307
- h: [twoDigits, function (d, v) {
5308
- d.hour = v;
5309
- }],
5310
- m: [twoDigits, function (d, v) {
5311
- d.minute = v;
5312
- }],
5313
- s: [twoDigits, function (d, v) {
5314
- d.second = v;
5315
- }],
5316
- yyyy: [fourDigits, function (d, v) {
5317
- d.year = v;
5318
- }],
5319
- S: ['\\d', function (d, v) {
5320
- d.millisecond = v * 100;
5321
- }],
5322
- SS: ['\\d{2}', function (d, v) {
5323
- d.millisecond = v * 10;
5324
- }],
5325
- SSS: [threeDigits, function (d, v) {
5326
- d.millisecond = v;
5327
- }],
5328
- D: [twoDigits, noop],
5329
- ddd: [word, noop],
5330
- MMM: [word, monthUpdate('monthNamesShort')],
5331
- MMMM: [word, monthUpdate('monthNames')],
5332
- a: [word, function (d, v) {
5333
- var val = v.toLowerCase();
5334
- if (val === '上午') {
5335
- d.isPm = false;
5336
- } else if (val === '下午') {
5337
- d.isPm = true;
5338
- }
5339
- }],
5340
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5341
- var parts = (v + '').match(/([+-]|\d\d)/gi),
5342
- minutes = void 0;
5343
-
5344
- if (parts) {
5345
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5346
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5347
- }
5348
- }]
5349
- };
5350
- parseFlags.dd = parseFlags.d;
5351
- parseFlags.dddd = parseFlags.ddd;
5352
- parseFlags.DD = parseFlags.D;
5353
- parseFlags.mm = parseFlags.m;
5354
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5355
- parseFlags.MM = parseFlags.M;
5356
- parseFlags.ss = parseFlags.s;
5357
- parseFlags.A = parseFlags.a;
5358
-
5359
- // Some common format strings
5360
- fecha.masks = {
5361
- default: 'ddd MMM dd yyyy HH:mm:ss',
5362
- shortDate: 'M/D/yy',
5363
- mediumDate: 'MMM d, yyyy',
5364
- longDate: 'MMMM d, yyyy',
5365
- fullDate: 'dddd, MMMM d, yyyy',
5366
- shortTime: 'HH:mm',
5367
- mediumTime: 'HH:mm:ss',
5368
- longTime: 'HH:mm:ss.SSS'
5369
- };
5370
-
5215
+ */
5216
+ const fecha = {};
5217
+ const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5218
+ const twoDigits = '\\d\\d?';
5219
+ const threeDigits = '\\d{3}';
5220
+ const fourDigits = '\\d{4}';
5221
+ const word = '[^\\s]+';
5222
+ const literal = /\[([^]*?)\]/gm;
5223
+ const noop = function () {};
5224
+
5225
+ function regexEscape(str) {
5226
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5227
+ }
5228
+
5229
+ function shorten(arr, sLen) {
5230
+ const newArr = [];
5231
+ for (let i = 0, len = arr.length; i < len; i++) {
5232
+ newArr.push(arr[i].substr(0, sLen));
5233
+ }
5234
+ return newArr;
5235
+ }
5236
+
5237
+ function monthUpdate() {
5238
+ return function (d, v) {
5239
+ const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5240
+ if (~index) {
5241
+ d.month = index;
5242
+ }
5243
+ };
5244
+ }
5245
+
5246
+ function pad(val, len) {
5247
+ val = String(val);
5248
+ len = len || 2;
5249
+ while (val.length < len) {
5250
+ val = '0' + val;
5251
+ }
5252
+ return val;
5253
+ }
5254
+
5255
+ // 直接使用中文日期名称常量
5256
+ const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
5257
+ const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
5258
+ const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
5259
+ const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
5260
+ const amPm = ['上午', '下午'];
5261
+ const DoFn = function DoFn(D) {
5262
+ return D + '日';
5263
+ };
5264
+
5265
+ const formatFlags = {
5266
+ D: function(dateObj) {
5267
+ return dateObj.getDay();
5268
+ },
5269
+ DD: function(dateObj) {
5270
+ return pad(dateObj.getDay());
5271
+ },
5272
+ Do: function(dateObj) {
5273
+ return DoFn(dateObj.getDate());
5274
+ },
5275
+ d: function(dateObj) {
5276
+ return dateObj.getDate();
5277
+ },
5278
+ dd: function(dateObj) {
5279
+ return pad(dateObj.getDate());
5280
+ },
5281
+ ddd: function(dateObj) {
5282
+ return dayNamesShort[dateObj.getDay()];
5283
+ },
5284
+ dddd: function(dateObj) {
5285
+ return dayNames[dateObj.getDay()];
5286
+ },
5287
+ M: function(dateObj) {
5288
+ return dateObj.getMonth() + 1;
5289
+ },
5290
+ MM: function(dateObj) {
5291
+ return pad(dateObj.getMonth() + 1);
5292
+ },
5293
+ MMM: function(dateObj) {
5294
+ return monthNamesShort[dateObj.getMonth()];
5295
+ },
5296
+ MMMM: function(dateObj) {
5297
+ return monthNames[dateObj.getMonth()];
5298
+ },
5299
+ yy: function(dateObj) {
5300
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
5301
+ },
5302
+ yyyy: function(dateObj) {
5303
+ return pad(dateObj.getFullYear(), 4);
5304
+ },
5305
+ h: function(dateObj) {
5306
+ return dateObj.getHours() % 12 || 12;
5307
+ },
5308
+ hh: function(dateObj) {
5309
+ return pad(dateObj.getHours() % 12 || 12);
5310
+ },
5311
+ H: function(dateObj) {
5312
+ return dateObj.getHours();
5313
+ },
5314
+ HH: function(dateObj) {
5315
+ return pad(dateObj.getHours());
5316
+ },
5317
+ m: function(dateObj) {
5318
+ return dateObj.getMinutes();
5319
+ },
5320
+ mm: function(dateObj) {
5321
+ return pad(dateObj.getMinutes());
5322
+ },
5323
+ s: function(dateObj) {
5324
+ return dateObj.getSeconds();
5325
+ },
5326
+ ss: function(dateObj) {
5327
+ return pad(dateObj.getSeconds());
5328
+ },
5329
+ S: function(dateObj) {
5330
+ return Math.round(dateObj.getMilliseconds() / 100);
5331
+ },
5332
+ SS: function(dateObj) {
5333
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
5334
+ },
5335
+ SSS: function(dateObj) {
5336
+ return pad(dateObj.getMilliseconds(), 3);
5337
+ },
5338
+ a: function(dateObj) {
5339
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5340
+ },
5341
+ A: function(dateObj) {
5342
+ return dateObj.getHours() < 12 ? '上午' : '下午';
5343
+ },
5344
+ ZZ: function(dateObj) {
5345
+ const o = dateObj.getTimezoneOffset();
5346
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
5347
+ }
5348
+ };
5349
+
5350
+ const parseFlags = {
5351
+ d: [twoDigits, function (d, v) {
5352
+ d.day = v;
5353
+ }],
5354
+ Do: [twoDigits + word, function (d, v) {
5355
+ d.day = parseInt(v, 10);
5356
+ }],
5357
+ M: [twoDigits, function (d, v) {
5358
+ d.month = v - 1;
5359
+ }],
5360
+ yy: [twoDigits, function (d, v) {
5361
+ const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
5362
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
5363
+ }],
5364
+ h: [twoDigits, function (d, v) {
5365
+ d.hour = v;
5366
+ }],
5367
+ m: [twoDigits, function (d, v) {
5368
+ d.minute = v;
5369
+ }],
5370
+ s: [twoDigits, function (d, v) {
5371
+ d.second = v;
5372
+ }],
5373
+ yyyy: [fourDigits, function (d, v) {
5374
+ d.year = v;
5375
+ }],
5376
+ S: ['\\d', function (d, v) {
5377
+ d.millisecond = v * 100;
5378
+ }],
5379
+ SS: ['\\d{2}', function (d, v) {
5380
+ d.millisecond = v * 10;
5381
+ }],
5382
+ SSS: [threeDigits, function (d, v) {
5383
+ d.millisecond = v;
5384
+ }],
5385
+ D: [twoDigits, noop],
5386
+ ddd: [word, noop],
5387
+ MMM: [word, monthUpdate('monthNamesShort')],
5388
+ MMMM: [word, monthUpdate('monthNames')],
5389
+ a: [word, function (d, v) {
5390
+ const val = v.toLowerCase();
5391
+ if (val === '上午') {
5392
+ d.isPm = false;
5393
+ } else if (val === '下午') {
5394
+ d.isPm = true;
5395
+ }
5396
+ }],
5397
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
5398
+ let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
5399
+
5400
+ if (parts) {
5401
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
5402
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
5403
+ }
5404
+ }]
5405
+ };
5406
+ parseFlags.dd = parseFlags.d;
5407
+ parseFlags.dddd = parseFlags.ddd;
5408
+ parseFlags.DD = parseFlags.D;
5409
+ parseFlags.mm = parseFlags.m;
5410
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
5411
+ parseFlags.MM = parseFlags.M;
5412
+ parseFlags.ss = parseFlags.s;
5413
+ parseFlags.A = parseFlags.a;
5414
+
5415
+
5416
+ // Some common format strings
5417
+ fecha.masks = {
5418
+ default: 'ddd MMM dd yyyy HH:mm:ss',
5419
+ shortDate: 'M/D/yy',
5420
+ mediumDate: 'MMM d, yyyy',
5421
+ longDate: 'MMMM d, yyyy',
5422
+ fullDate: 'dddd, MMMM d, yyyy',
5423
+ shortTime: 'HH:mm',
5424
+ mediumTime: 'HH:mm:ss',
5425
+ longTime: 'HH:mm:ss.SSS'
5426
+ };
5427
+
5371
5428
  /***
5372
5429
  * Format a date
5373
5430
  * @method format
5374
5431
  * @param {Date|number} dateObj
5375
5432
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
5376
- */
5377
- fecha.format = function (dateObj, mask) {
5378
- if (typeof dateObj === 'number') {
5379
- dateObj = new Date(dateObj);
5380
- }
5381
-
5382
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5383
- throw new Error('Invalid Date in fecha.format');
5384
- }
5385
-
5386
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
5387
-
5388
- var literals = [];
5389
-
5390
- // Make literals inactive by replacing them with ??
5391
- mask = mask.replace(literal, function ($0, $1) {
5392
- literals.push($1);
5393
- return '@@@';
5394
- });
5395
- // Apply formatting rules
5396
- mask = mask.replace(token, function ($0) {
5397
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5398
- });
5399
- // Inline literal values back into the formatted value
5400
- return mask.replace(/@@@/g, function () {
5401
- return literals.shift();
5402
- });
5403
- };
5404
-
5433
+ */
5434
+ fecha.format = function (dateObj, mask) {
5435
+ if (typeof dateObj === 'number') {
5436
+ dateObj = new Date(dateObj);
5437
+ }
5438
+
5439
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
5440
+ throw new Error('Invalid Date in fecha.format');
5441
+ }
5442
+
5443
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
5444
+
5445
+ const literals = [];
5446
+
5447
+ // Make literals inactive by replacing them with ??
5448
+ mask = mask.replace(literal, function($0, $1) {
5449
+ literals.push($1);
5450
+ return '@@@';
5451
+ });
5452
+ // Apply formatting rules
5453
+ mask = mask.replace(token, function ($0) {
5454
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
5455
+ });
5456
+ // Inline literal values back into the formatted value
5457
+ return mask.replace(/@@@/g, function() {
5458
+ return literals.shift();
5459
+ });
5460
+ };
5461
+
5405
5462
  /**
5406
5463
  * Parse a date string into an object, changes - into /
5407
5464
  * @method parse
5408
5465
  * @param {string} dateStr Date string
5409
5466
  * @param {string} format Date parse format
5410
5467
  * @returns {Date|boolean}
5411
- */
5412
- fecha.parse = function (dateStr, format) {
5413
- if (typeof format !== 'string') {
5414
- throw new Error('Invalid format in fecha.parse');
5415
- }
5416
-
5417
- format = fecha.masks[format] || format;
5418
-
5419
- // Avoid regular expression denial of service, fail early for really long strings
5420
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5421
- if (dateStr.length > 1000) {
5422
- return null;
5423
- }
5424
-
5425
- var dateInfo = {};
5426
- var parseInfo = [];
5427
- var literals = [];
5428
- format = format.replace(literal, function ($0, $1) {
5429
- literals.push($1);
5430
- return '@@@';
5431
- });
5432
- var newFormat = regexEscape(format).replace(token, function ($0) {
5433
- if (parseFlags[$0]) {
5434
- var info = parseFlags[$0];
5435
- parseInfo.push(info[1]);
5436
- return '(' + info[0] + ')';
5437
- }
5438
-
5439
- return $0;
5440
- });
5441
- newFormat = newFormat.replace(/@@@/g, function () {
5442
- return literals.shift();
5443
- });
5444
- var matches = dateStr.match(new RegExp(newFormat, 'i'));
5445
- if (!matches) {
5446
- return null;
5447
- }
5448
-
5449
- for (var i = 1; i < matches.length; i++) {
5450
- parseInfo[i - 1](dateInfo, matches[i]);
5451
- }
5452
-
5453
- var today = new Date();
5454
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5455
- dateInfo.hour = +dateInfo.hour + 12;
5456
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5457
- dateInfo.hour = 0;
5458
- }
5459
-
5460
- var date = void 0;
5461
- if (dateInfo.timezoneOffset != null) {
5462
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5463
- 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));
5464
- } else {
5465
- 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);
5466
- }
5467
- return date;
5468
- };
5469
-
5470
- // 导出fecha对象
5471
-
5472
-
5473
- // 以下是从date-util.js合并的函数
5474
- var newArray = function newArray(start, end) {
5475
- var result = [];
5476
- for (var i = start; i <= end; i++) {
5477
- result.push(i);
5478
- }
5479
- return result;
5480
- };
5481
-
5482
- var getSettings = function getSettings() {
5483
- return {
5484
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5485
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5486
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5487
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5488
- amPm: ['上午', '下午']
5489
- };
5490
- };
5491
-
5492
- var toDate = function toDate(date) {
5493
- return isDate(date) ? new Date(date) : null;
5494
- };
5495
-
5496
- var isDate = function isDate(date) {
5497
- if (date === null || date === undefined) return false;
5498
- if (isNaN(new Date(date).getTime())) return false;
5499
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5500
- return true;
5501
- };
5502
-
5503
- var isDateObject = function isDateObject(val) {
5504
- return val instanceof Date;
5505
- };
5506
-
5507
- var formatDate = function formatDate(date) {
5508
- var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
5509
-
5510
- // 处理多种输入类型
5511
- if (!date) return '';
5512
-
5513
- // 如果是时间戳,转成日期对象
5514
- if (typeof date === 'number') {
5515
- date = new Date(date);
5516
- }
5517
- // 如果是字符串,转成日期对象
5518
- if (typeof date === 'string') {
5519
- date = new Date(date);
5520
- }
5521
-
5522
- // 调用toDate进一步验证和转换
5523
- date = toDate(date);
5524
- if (!date) return '';
5525
-
5526
- // 兼容大写和小写的格式标记
5527
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5528
- var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
5529
-
5530
- // 使用fecha库进行格式化,支持中文配置
5531
- var str = fecha.format(date, lowercaseFormat, getSettings());
5532
- return str;
5533
- };
5534
-
5535
- var parseDate = function parseDate(string, format) {
5536
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5537
- };
5538
-
5539
- var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
5540
- if (month === 3 || month === 5 || month === 8 || month === 10) {
5541
- return 30;
5542
- }
5543
-
5544
- if (month === 1) {
5545
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5546
- return 29;
5547
- } else {
5548
- return 28;
5549
- }
5550
- }
5551
-
5552
- return 31;
5553
- };
5554
-
5555
- var getDayCountOfYear = function getDayCountOfYear(year) {
5556
- var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
5557
- return isLeapYear ? 366 : 365;
5558
- };
5559
-
5560
- var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
5561
- var temp = new Date(date.getTime());
5562
- temp.setDate(1);
5563
- return temp.getDay();
5564
- };
5565
-
5566
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5567
- // {prev, next} Date should work for Daylight Saving Time
5568
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5569
- var prevDate = function prevDate(date) {
5570
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5571
-
5572
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5573
- };
5574
-
5575
- var nextDate = function nextDate(date) {
5576
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5577
-
5578
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5579
- };
5580
-
5581
- var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
5582
- var result = new Date(year, month, 1);
5583
- var day = result.getDay();
5584
-
5585
- if (day === 0) {
5586
- return prevDate(result, 7);
5587
- } else {
5588
- return prevDate(result, day);
5589
- }
5590
- };
5591
-
5592
- var getWeekNumber = function getWeekNumber(date) {
5593
- // 支持多种输入类型
5594
- if (!date || !isDate(date)) {
5595
- date = new Date();
5596
- }
5597
- if (typeof date === 'string') {
5598
- date = new Date(date);
5599
- }
5600
-
5601
- // 验证日期有效性
5602
- if (!isDate(date)) return null;
5603
-
5604
- var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5605
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5606
- // 将星期日的星期数设为7
5607
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5608
- // 获取当年的第一天
5609
- var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5610
- // 计算到最近的星期四的完整周数
5611
- var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
5612
- // 返回周数
5613
- return weekNo;
5614
- };
5615
-
5616
- var getRangeHours = function getRangeHours(ranges) {
5617
- var hours = [];
5618
- var disabledHours = [];
5619
-
5620
- (ranges || []).forEach(function (range) {
5621
- var value = range.map(function (date) {
5622
- return date.getHours();
5623
- });
5624
-
5625
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5626
- });
5627
-
5628
- if (disabledHours.length) {
5629
- for (var i = 0; i < 24; i++) {
5630
- hours[i] = disabledHours.indexOf(i) === -1;
5631
- }
5632
- } else {
5633
- for (var _i = 0; _i < 24; _i++) {
5634
- hours[_i] = false;
5635
- }
5636
- }
5637
-
5638
- return hours;
5639
- };
5640
-
5641
- var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
5642
- if (amount <= 0) return [];
5643
- var temp = new Date(date.getTime());
5644
- temp.setDate(0);
5645
- var lastDay = temp.getDate();
5646
- return range(amount).map(function (_, index) {
5647
- return lastDay - (amount - index - 1);
5648
- });
5649
- };
5650
-
5651
- var getMonthDays = function getMonthDays(date) {
5652
- var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5653
- var days = temp.getDate();
5654
- return range(days).map(function (_, index) {
5655
- return index + 1;
5656
- });
5657
- };
5658
-
5659
- function setRangeData(arr, start, end, value) {
5660
- for (var i = start; i < end; i++) {
5661
- arr[i] = value;
5662
- }
5663
- }
5664
-
5665
- var getRangeMinutes = function getRangeMinutes(ranges, hour) {
5666
- var minutes = new Array(60);
5667
-
5668
- if (ranges.length > 0) {
5669
- ranges.forEach(function (range) {
5670
- var start = range[0];
5671
- var end = range[1];
5672
- var startHour = start.getHours();
5673
- var startMinute = start.getMinutes();
5674
- var endHour = end.getHours();
5675
- var endMinute = end.getMinutes();
5676
- if (startHour === hour && endHour !== hour) {
5677
- setRangeData(minutes, startMinute, 60, true);
5678
- } else if (startHour === hour && endHour === hour) {
5679
- setRangeData(minutes, startMinute, endMinute + 1, true);
5680
- } else if (startHour !== hour && endHour === hour) {
5681
- setRangeData(minutes, 0, endMinute + 1, true);
5682
- } else if (startHour < hour && endHour > hour) {
5683
- setRangeData(minutes, 0, 60, true);
5684
- }
5685
- });
5686
- } else {
5687
- setRangeData(minutes, 0, 60, true);
5688
- }
5689
- return minutes;
5690
- };
5691
-
5692
- var range = function range(n) {
5693
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5694
- return Array.apply(null, { length: n }).map(function (_, n) {
5695
- return n;
5696
- });
5697
- };
5698
-
5699
- var modifyDate = function modifyDate(date, y, m, d) {
5700
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5701
- };
5702
-
5703
- var modifyTime = function modifyTime(date, h, m, s) {
5704
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5705
- };
5706
-
5707
- var modifyWithTimeString = function modifyWithTimeString(date, time) {
5708
- if (date == null || !time) {
5709
- return date;
5710
- }
5711
- time = parseDate(time, 'HH:mm:ss');
5712
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5713
- };
5714
-
5715
- var clearTime = function clearTime(date) {
5716
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5717
- };
5718
-
5719
- var clearMilliseconds = function clearMilliseconds(date) {
5720
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5721
- };
5722
-
5723
- var limitTimeRange = function limitTimeRange(date, ranges) {
5724
- var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
5725
-
5726
- // TODO: refactory a more elegant solution
5727
- if (ranges.length === 0) return date;
5728
- var normalizeDate = function normalizeDate(date) {
5729
- return fecha.parse(fecha.format(date, format), format);
5730
- };
5731
- var ndate = normalizeDate(date);
5732
- var nranges = ranges.map(function (range) {
5733
- return range.map(normalizeDate);
5734
- });
5735
- if (nranges.some(function (nrange) {
5736
- return ndate >= nrange[0] && ndate <= nrange[1];
5737
- })) return date;
5738
-
5739
- var minDate = nranges[0][0];
5740
- var maxDate = nranges[0][0];
5741
-
5742
- nranges.forEach(function (nrange) {
5743
- minDate = new Date(Math.min(nrange[0], minDate));
5744
- maxDate = new Date(Math.max(nrange[1], minDate));
5745
- });
5746
-
5747
- var ret = ndate < minDate ? minDate : maxDate;
5748
- // preserve Year/Month/Date
5749
- return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
5750
- };
5751
-
5752
- var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
5753
- var limitedDate = limitTimeRange(date, selectableRange, format);
5754
- return limitedDate.getTime() === date.getTime();
5755
- };
5756
-
5757
- var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
5758
- // clamp date to the number of days in `year`, `month`
5759
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
5760
- var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5761
- return modifyDate(date, year, month, monthDate);
5762
- };
5763
-
5764
- var prevMonth = function prevMonth(date) {
5765
- var year = date.getFullYear();
5766
- var month = date.getMonth();
5767
- return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
5768
- };
5769
-
5770
- var nextMonth = function nextMonth(date) {
5771
- var year = date.getFullYear();
5772
- var month = date.getMonth();
5773
- return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
5774
- };
5775
-
5776
- var prevYear = function prevYear(date) {
5777
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5778
-
5779
- var year = date.getFullYear();
5780
- var month = date.getMonth();
5781
- return changeYearMonthAndClampDate(date, year - amount, month);
5782
- };
5783
-
5784
- var nextYear = function nextYear(date) {
5785
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5786
-
5787
- var year = date.getFullYear();
5788
- var month = date.getMonth();
5789
- return changeYearMonthAndClampDate(date, year + amount, month);
5790
- };
5791
-
5792
- var extractDateFormat = function extractDateFormat(format) {
5793
- return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
5794
- };
5795
-
5796
- var extractTimeFormat = function extractTimeFormat(format) {
5797
- return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
5798
- };
5799
-
5800
- var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
5801
- return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
5802
- };
5803
-
5468
+ */
5469
+ fecha.parse = function (dateStr, format) {
5470
+ if (typeof format !== 'string') {
5471
+ throw new Error('Invalid format in fecha.parse');
5472
+ }
5473
+
5474
+ format = fecha.masks[format] || format;
5475
+
5476
+ // Avoid regular expression denial of service, fail early for really long strings
5477
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
5478
+ if (dateStr.length > 1000) {
5479
+ return null;
5480
+ }
5481
+
5482
+ const dateInfo = {};
5483
+ const parseInfo = [];
5484
+ const literals = [];
5485
+ format = format.replace(literal, function($0, $1) {
5486
+ literals.push($1);
5487
+ return '@@@';
5488
+ });
5489
+ let newFormat = regexEscape(format).replace(token, function ($0) {
5490
+ if (parseFlags[$0]) {
5491
+ const info = parseFlags[$0];
5492
+ parseInfo.push(info[1]);
5493
+ return '(' + info[0] + ')';
5494
+ }
5495
+
5496
+ return $0;
5497
+ });
5498
+ newFormat = newFormat.replace(/@@@/g, function() {
5499
+ return literals.shift();
5500
+ });
5501
+ const matches = dateStr.match(new RegExp(newFormat, 'i'));
5502
+ if (!matches) {
5503
+ return null;
5504
+ }
5505
+
5506
+ for (let i = 1; i < matches.length; i++) {
5507
+ parseInfo[i - 1](dateInfo, matches[i]);
5508
+ }
5509
+
5510
+ const today = new Date();
5511
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
5512
+ dateInfo.hour = +dateInfo.hour + 12;
5513
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
5514
+ dateInfo.hour = 0;
5515
+ }
5516
+
5517
+ let date;
5518
+ if (dateInfo.timezoneOffset != null) {
5519
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
5520
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5521
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
5522
+ } else {
5523
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
5524
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
5525
+ }
5526
+ return date;
5527
+ };
5528
+
5529
+ // 导出fecha对象
5530
+
5531
+
5532
+ // 以下是从date-util.js合并的函数
5533
+ const newArray = function(start, end) {
5534
+ let result = [];
5535
+ for (let i = start; i <= end; i++) {
5536
+ result.push(i);
5537
+ }
5538
+ return result;
5539
+ };
5540
+
5541
+ const getSettings = () => {
5542
+ return {
5543
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
5544
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
5545
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
5546
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
5547
+ amPm: ['上午', '下午']
5548
+ };
5549
+ };
5550
+
5551
+ const toDate = function(date) {
5552
+ return isDate(date) ? new Date(date) : null;
5553
+ };
5554
+
5555
+ const isDate = function(date) {
5556
+ if (date === null || date === undefined) return false;
5557
+ if (isNaN(new Date(date).getTime())) return false;
5558
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
5559
+ return true;
5560
+ };
5561
+
5562
+ const isDateObject = function(val) {
5563
+ return val instanceof Date;
5564
+ };
5565
+
5566
+ const formatDate = function (date, format = 'yyyy-MM-dd') {
5567
+ // 处理多种输入类型
5568
+ if (!date) return '';
5569
+
5570
+ // 如果是时间戳,转成日期对象
5571
+ if (typeof date === 'number') {
5572
+ date = new Date(date);
5573
+ }
5574
+ // 如果是字符串,转成日期对象
5575
+ if (typeof date === 'string') {
5576
+ date = new Date(date);
5577
+ }
5578
+
5579
+ // 调用toDate进一步验证和转换
5580
+ date = toDate(date);
5581
+ if (!date) return '';
5582
+
5583
+ // 兼容大写和小写的格式标记
5584
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
5585
+ const lowercaseFormat = format
5586
+ .replace(/YYYY/g, 'yyyy')
5587
+ .replace(/D/g, 'd')
5588
+
5589
+ // 使用fecha库进行格式化,支持中文配置
5590
+ const str = fecha.format(date, lowercaseFormat, getSettings());
5591
+ return str;
5592
+ };
5593
+
5594
+ const parseDate = function(string, format) {
5595
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
5596
+ };
5597
+
5598
+ const getDayCountOfMonth = function(year, month) {
5599
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
5600
+ return 30;
5601
+ }
5602
+
5603
+ if (month === 1) {
5604
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
5605
+ return 29;
5606
+ } else {
5607
+ return 28;
5608
+ }
5609
+ }
5610
+
5611
+ return 31;
5612
+ };
5613
+
5614
+ const getDayCountOfYear = function(year) {
5615
+ const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
5616
+ return isLeapYear ? 366 : 365;
5617
+ };
5618
+
5619
+ const getFirstDayOfMonth = function(date) {
5620
+ const temp = new Date(date.getTime());
5621
+ temp.setDate(1);
5622
+ return temp.getDay();
5623
+ };
5624
+
5625
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
5626
+ // {prev, next} Date should work for Daylight Saving Time
5627
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
5628
+ const prevDate = function(date, amount = 1) {
5629
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
5630
+ };
5631
+
5632
+ const nextDate = function(date, amount = 1) {
5633
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
5634
+ };
5635
+
5636
+ const getStartDateOfMonth = function(year, month) {
5637
+ const result = new Date(year, month, 1);
5638
+ const day = result.getDay();
5639
+
5640
+ if (day === 0) {
5641
+ return prevDate(result, 7);
5642
+ } else {
5643
+ return prevDate(result, day);
5644
+ }
5645
+ };
5646
+
5647
+ const getWeekNumber = function(date) {
5648
+ // 支持多种输入类型
5649
+ if (!date||!isDate(date)) {
5650
+ date = new Date();
5651
+ }
5652
+ if (typeof date === 'string') {
5653
+ date = new Date(date);
5654
+ }
5655
+
5656
+ // 验证日期有效性
5657
+ if (!isDate(date)) return null;
5658
+
5659
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
5660
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
5661
+ // 将星期日的星期数设为7
5662
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
5663
+ // 获取当年的第一天
5664
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
5665
+ // 计算到最近的星期四的完整周数
5666
+ const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
5667
+ // 返回周数
5668
+ return weekNo;
5669
+ };
5670
+
5671
+ const getRangeHours = function(ranges) {
5672
+ const hours = [];
5673
+ let disabledHours = [];
5674
+
5675
+ (ranges || []).forEach(range => {
5676
+ const value = range.map(date => date.getHours());
5677
+
5678
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
5679
+ });
5680
+
5681
+ if (disabledHours.length) {
5682
+ for (let i = 0; i < 24; i++) {
5683
+ hours[i] = disabledHours.indexOf(i) === -1;
5684
+ }
5685
+ } else {
5686
+ for (let i = 0; i < 24; i++) {
5687
+ hours[i] = false;
5688
+ }
5689
+ }
5690
+
5691
+ return hours;
5692
+ };
5693
+
5694
+ const getPrevMonthLastDays = (date, amount) => {
5695
+ if (amount <= 0) return [];
5696
+ const temp = new Date(date.getTime());
5697
+ temp.setDate(0);
5698
+ const lastDay = temp.getDate();
5699
+ return range(amount).map((_, index) => lastDay - (amount - index - 1));
5700
+ };
5701
+
5702
+ const getMonthDays = (date) => {
5703
+ const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
5704
+ const days = temp.getDate();
5705
+ return range(days).map((_, index) => index + 1);
5706
+ };
5707
+
5708
+ function setRangeData(arr, start, end, value) {
5709
+ for (let i = start; i < end; i++) {
5710
+ arr[i] = value;
5711
+ }
5712
+ }
5713
+
5714
+ const getRangeMinutes = function(ranges, hour) {
5715
+ const minutes = new Array(60);
5716
+
5717
+ if (ranges.length > 0) {
5718
+ ranges.forEach(range => {
5719
+ const start = range[0];
5720
+ const end = range[1];
5721
+ const startHour = start.getHours();
5722
+ const startMinute = start.getMinutes();
5723
+ const endHour = end.getHours();
5724
+ const endMinute = end.getMinutes();
5725
+ if (startHour === hour && endHour !== hour) {
5726
+ setRangeData(minutes, startMinute, 60, true);
5727
+ } else if (startHour === hour && endHour === hour) {
5728
+ setRangeData(minutes, startMinute, endMinute + 1, true);
5729
+ } else if (startHour !== hour && endHour === hour) {
5730
+ setRangeData(minutes, 0, endMinute + 1, true);
5731
+ } else if (startHour < hour && endHour > hour) {
5732
+ setRangeData(minutes, 0, 60, true);
5733
+ }
5734
+ });
5735
+ } else {
5736
+ setRangeData(minutes, 0, 60, true);
5737
+ }
5738
+ return minutes;
5739
+ };
5740
+
5741
+ const range = function(n) {
5742
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
5743
+ return Array.apply(null, {length: n}).map((_, n) => n);
5744
+ };
5745
+
5746
+ const modifyDate = function(date, y, m, d) {
5747
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
5748
+ };
5749
+
5750
+ const modifyTime = function(date, h, m, s) {
5751
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
5752
+ };
5753
+
5754
+ const modifyWithTimeString = (date, time) => {
5755
+ if (date == null || !time) {
5756
+ return date;
5757
+ }
5758
+ time = parseDate(time, 'HH:mm:ss');
5759
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
5760
+ };
5761
+
5762
+ const clearTime = function(date) {
5763
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
5764
+ };
5765
+
5766
+ const clearMilliseconds = function(date) {
5767
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
5768
+ };
5769
+
5770
+ const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
5771
+ // TODO: refactory a more elegant solution
5772
+ if (ranges.length === 0) return date;
5773
+ const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
5774
+ const ndate = normalizeDate(date);
5775
+ const nranges = ranges.map(range => range.map(normalizeDate));
5776
+ if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
5777
+
5778
+ let minDate = nranges[0][0];
5779
+ let maxDate = nranges[0][0];
5780
+
5781
+ nranges.forEach(nrange => {
5782
+ minDate = new Date(Math.min(nrange[0], minDate));
5783
+ maxDate = new Date(Math.max(nrange[1], minDate));
5784
+ });
5785
+
5786
+ const ret = ndate < minDate ? minDate : maxDate;
5787
+ // preserve Year/Month/Date
5788
+ return modifyDate(
5789
+ ret,
5790
+ date.getFullYear(),
5791
+ date.getMonth(),
5792
+ date.getDate()
5793
+ );
5794
+ };
5795
+
5796
+ const timeWithinRange = function(date, selectableRange, format) {
5797
+ const limitedDate = limitTimeRange(date, selectableRange, format);
5798
+ return limitedDate.getTime() === date.getTime();
5799
+ };
5800
+
5801
+ const changeYearMonthAndClampDate = function(date, year, month) {
5802
+ // clamp date to the number of days in `year`, `month`
5803
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
5804
+ const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
5805
+ return modifyDate(date, year, month, monthDate);
5806
+ };
5807
+
5808
+ const prevMonth = function(date) {
5809
+ const year = date.getFullYear();
5810
+ const month = date.getMonth();
5811
+ return month === 0
5812
+ ? changeYearMonthAndClampDate(date, year - 1, 11)
5813
+ : changeYearMonthAndClampDate(date, year, month - 1);
5814
+ };
5815
+
5816
+ const nextMonth = function(date) {
5817
+ const year = date.getFullYear();
5818
+ const month = date.getMonth();
5819
+ return month === 11
5820
+ ? changeYearMonthAndClampDate(date, year + 1, 0)
5821
+ : changeYearMonthAndClampDate(date, year, month + 1);
5822
+ };
5823
+
5824
+ const prevYear = function(date, amount = 1) {
5825
+ const year = date.getFullYear();
5826
+ const month = date.getMonth();
5827
+ return changeYearMonthAndClampDate(date, year - amount, month);
5828
+ };
5829
+
5830
+ const nextYear = function(date, amount = 1) {
5831
+ const year = date.getFullYear();
5832
+ const month = date.getMonth();
5833
+ return changeYearMonthAndClampDate(date, year + amount, month);
5834
+ };
5835
+
5836
+ const extractDateFormat = function(format) {
5837
+ return format
5838
+ .replace(/\W?m{1,2}|\W?ZZ/g, '')
5839
+ .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
5840
+ .trim();
5841
+ };
5842
+
5843
+ const extractTimeFormat = function(format) {
5844
+ return format
5845
+ .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
5846
+ .trim();
5847
+ };
5848
+
5849
+ const validateRangeInOneMonth = function(start, end) {
5850
+ return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
5851
+ };
5852
+
5804
5853
  /**
5805
5854
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
5806
5855
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
5807
5856
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
5808
5857
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
5809
5858
  * @returns {number} 工作日数量
5810
- */
5811
- var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
5812
- var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5813
-
5814
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5815
- throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5816
- }
5817
-
5818
- var startDateObj = new Date(start_date);
5819
- var endDateObj = new Date(end_date);
5820
-
5821
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5822
- throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
5823
- }
5824
-
5825
- if (startDateObj > endDateObj) {
5826
- throw new Error('Start date should be earlier than or equal to end date.');
5827
- }
5828
-
5829
- var workdays = 0;
5830
-
5831
- // Iterate through each day in the date range
5832
-
5833
- var _loop = function _loop(currentDate) {
5834
- // Check if the current day is a weekend (Saturday or Sunday)
5835
- var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5836
-
5837
- // Check if the current day is a holiday
5838
- var isHoliday = holidays.some(function (holiday) {
5839
- var holidayDate = new Date(holiday);
5840
- return currentDate.toDateString() === holidayDate.toDateString();
5841
- });
5842
-
5843
- // If it's a workday (not a weekend or holiday), increment the workdays count
5844
- if (!isWeekend && !isHoliday) {
5845
- workdays++;
5846
- }
5847
- };
5848
-
5849
- for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
5850
- _loop(currentDate);
5851
- }
5852
-
5853
- return workdays;
5854
- };
5855
-
5859
+ */
5860
+ const calculateNetworkDays = function (start_date, end_date, holidays = []) {
5861
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
5862
+ throw new Error(
5863
+ "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
5864
+ );
5865
+ }
5866
+
5867
+ const startDateObj = new Date(start_date);
5868
+ const endDateObj = new Date(end_date);
5869
+
5870
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
5871
+ throw new Error(
5872
+ "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
5873
+ );
5874
+ }
5875
+
5876
+ if (startDateObj > endDateObj) {
5877
+ throw new Error('Start date should be earlier than or equal to end date.');
5878
+ }
5879
+
5880
+ let workdays = 0;
5881
+
5882
+ // Iterate through each day in the date range
5883
+ for (
5884
+ let currentDate = new Date(startDateObj);
5885
+ currentDate <= endDateObj;
5886
+ currentDate.setDate(currentDate.getDate() + 1)
5887
+ ) {
5888
+ // Check if the current day is a weekend (Saturday or Sunday)
5889
+ const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
5890
+
5891
+ // Check if the current day is a holiday
5892
+ const isHoliday = holidays.some((holiday) => {
5893
+ const holidayDate = new Date(holiday);
5894
+ return currentDate.toDateString() === holidayDate.toDateString();
5895
+ });
5896
+
5897
+ // If it's a workday (not a weekend or holiday), increment the workdays count
5898
+ if (!isWeekend && !isHoliday) {
5899
+ workdays++;
5900
+ }
5901
+ }
5902
+
5903
+ return workdays;
5904
+ };
5905
+
5856
5906
  /**
5857
5907
  * 日期加减天数
5858
5908
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
5859
5909
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
5860
5910
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
5861
- */
5862
- var dateAddDays = function dateAddDays(start_date, days) {
5863
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5864
- 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.");
5865
- }
5866
-
5867
- var startDateObj = new Date(start_date);
5868
- if (isNaN(startDateObj.getTime())) {
5869
- throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5870
- }
5871
-
5872
- var resultDateObj = new Date(startDateObj);
5873
- resultDateObj.setDate(resultDateObj.getDate() + days);
5874
-
5875
- var resultYear = resultDateObj.getFullYear();
5876
- var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5877
- var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5878
-
5879
- return resultYear + '-' + resultMonth + '-' + resultDay;
5880
- };
5881
-
5911
+ */
5912
+ const dateAddDays = function (start_date, days) {
5913
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
5914
+ throw new Error(
5915
+ "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
5916
+ );
5917
+ }
5918
+
5919
+ const startDateObj = new Date(start_date);
5920
+ if (isNaN(startDateObj.getTime())) {
5921
+ throw new Error(
5922
+ "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5923
+ );
5924
+ }
5925
+
5926
+ const resultDateObj = new Date(startDateObj);
5927
+ resultDateObj.setDate(resultDateObj.getDate() + days);
5928
+
5929
+ const resultYear = resultDateObj.getFullYear();
5930
+ const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
5931
+ const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
5932
+
5933
+ return `${resultYear}-${resultMonth}-${resultDay}`;
5934
+ };
5935
+
5882
5936
  /**
5883
5937
  * 计算两个日期之间的差值
5884
5938
  * @date 2023年12月14日
@@ -5886,180 +5940,182 @@ var dateAddDays = function dateAddDays(start_date, days) {
5886
5940
  * @param {String} end_date - 结束日期字符串
5887
5941
  * @param {String} unit - 单位:year/month/day
5888
5942
  * @returns {Number} 差值
5889
- */
5890
- var dateDiff = function dateDiff(start_date, end_date) {
5891
- var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
5892
-
5893
- // Assuming date strings are in "YYYY-MM-DD" format
5894
- var startDate = new Date(start_date);
5895
- var endDate = new Date(end_date);
5896
-
5897
- // If the date is invalid, return 0
5898
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5899
- return 0;
5900
- }
5901
-
5902
- if (unit === 'year') {
5903
- return endDate.getFullYear() - startDate.getFullYear();
5904
- } else if (unit === 'month') {
5905
- return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
5906
- } else {
5907
- // Default to day
5908
- var timeDifference = endDate - startDate;
5909
- // Calculate days (86400000 milliseconds per day)
5910
- return Math.floor(timeDifference / 86400000);
5911
- }
5912
- };
5913
-
5943
+ */
5944
+ const dateDiff = function (start_date, end_date, unit = 'day') {
5945
+ // Assuming date strings are in "YYYY-MM-DD" format
5946
+ var startDate = new Date(start_date);
5947
+ var endDate = new Date(end_date);
5948
+
5949
+ // If the date is invalid, return 0
5950
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
5951
+ return 0;
5952
+ }
5953
+
5954
+ if (unit === 'year') {
5955
+ return endDate.getFullYear() - startDate.getFullYear();
5956
+ } else if (unit === 'month') {
5957
+ return (
5958
+ (endDate.getFullYear() - startDate.getFullYear()) * 12 +
5959
+ (endDate.getMonth() - startDate.getMonth())
5960
+ );
5961
+ } else {
5962
+ // Default to day
5963
+ var timeDifference = endDate - startDate;
5964
+ // Calculate days (86400000 milliseconds per day)
5965
+ return Math.floor(timeDifference / 86400000);
5966
+ }
5967
+ };
5968
+
5914
5969
  /**
5915
5970
  * 获取月份中的日期
5916
5971
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
5917
5972
  * @returns {number} 月份中的日期(1-31)
5918
- */
5919
- var dayOfMonth = function dayOfMonth(date) {
5920
- if (typeof date !== 'string') {
5921
- throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5922
- }
5923
-
5924
- var dateObj = new Date(date);
5925
- if (isNaN(dateObj.getTime())) {
5926
- throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
5927
- }
5928
-
5929
- return dateObj.getDate();
5930
- };
5931
-
5973
+ */
5974
+ const dayOfMonth = function (date) {
5975
+ if (typeof date !== 'string') {
5976
+ throw new Error(
5977
+ "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
5978
+ );
5979
+ }
5980
+
5981
+ const dateObj = new Date(date);
5982
+ if (isNaN(dateObj.getTime())) {
5983
+ throw new Error(
5984
+ "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
5985
+ );
5986
+ }
5987
+
5988
+ return dateObj.getDate();
5989
+ };
5990
+
5932
5991
  /**
5933
5992
  * 获取当前日期
5934
5993
  * @date 2022年5月7日
5935
5994
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
5936
5995
  * @returns {string} 当前日期的格式化字符串
5937
- */
5938
- var getCurrentDate = function getCurrentDate() {
5939
- var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
5940
-
5941
- return formatDate(new Date(), format);
5942
- };
5943
-
5996
+ */
5997
+ const getCurrentDate = function (format = 'YYYY-MM-DD') {
5998
+ return formatDate(new Date(), format);
5999
+ };
6000
+
5944
6001
  /**
5945
6002
  * 获取当前日期时间
5946
6003
  * @date 2022年5月7日
5947
6004
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
5948
6005
  * @returns {string} 当前日期时间的格式化字符串
5949
- */
5950
- var getCurrentDateTime = function getCurrentDateTime() {
5951
- var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
5952
-
5953
- return formatDate(new Date(), format);
5954
- };
5955
-
6006
+ */
6007
+ const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6008
+ return formatDate(new Date(), format);
6009
+ };
6010
+
5956
6011
  /**
5957
6012
  * 获取小时
5958
6013
  * @date 2022年5月7日
5959
6014
  * @param {Date|string} [date] - 日期对象或日期字符串
5960
6015
  * @returns {number} 小时数(0-23)
5961
- */
5962
- var getHour = function getHour(date) {
5963
- if (!date) {
5964
- return new Date().getHours();
5965
- }
5966
- if (typeof date === 'string') {
5967
- date = new Date(date);
5968
- }
5969
- return date.getHours();
5970
- };
5971
-
6016
+ */
6017
+ const getHour = function (date) {
6018
+ if (!date) {
6019
+ return new Date().getHours();
6020
+ }
6021
+ if (typeof date === 'string') {
6022
+ date = new Date(date);
6023
+ }
6024
+ return date.getHours();
6025
+ };
6026
+
5972
6027
  /**
5973
6028
  * 获取分钟
5974
6029
  * @date 2022年5月7日
5975
6030
  * @param {Date|string} [date] - 日期对象或日期字符串
5976
6031
  * @returns {number} 分钟数(0-59)
5977
- */
5978
- var getMinute = function getMinute(date) {
5979
- if (!date) {
5980
- return new Date().getMinutes();
5981
- }
5982
- if (typeof date === 'string') {
5983
- date = new Date(date);
5984
- }
5985
- return date.getMinutes();
5986
- };
5987
-
6032
+ */
6033
+ const getMinute = function (date) {
6034
+ if (!date) {
6035
+ return new Date().getMinutes();
6036
+ }
6037
+ if (typeof date === 'string') {
6038
+ date = new Date(date);
6039
+ }
6040
+ return date.getMinutes();
6041
+ };
6042
+
5988
6043
  /**
5989
6044
  * 获取月份
5990
6045
  * @date 2022年5月7日
5991
6046
  * @param {Date|string} [date] - 日期对象或日期字符串
5992
6047
  * @returns {number} 月份数(1-12)
5993
- */
5994
- var getMonth = function getMonth(date) {
5995
- if (!date) {
5996
- return new Date().getMonth() + 1;
5997
- }
5998
- if (typeof date === 'string') {
5999
- date = new Date(date);
6000
- }
6001
- return date.getMonth() + 1;
6002
- };
6003
-
6048
+ */
6049
+ const getMonth = function (date) {
6050
+ if (!date) {
6051
+ return new Date().getMonth() + 1;
6052
+ }
6053
+ if (typeof date === 'string') {
6054
+ date = new Date(date);
6055
+ }
6056
+ return date.getMonth() + 1;
6057
+ };
6058
+
6004
6059
  /**
6005
6060
  * 获取秒
6006
6061
  * @date 2022年5月7日
6007
6062
  * @param {Date|string} [date] - 日期对象或日期字符串
6008
6063
  * @returns {number} 秒数(0-59)
6009
- */
6010
- var getSecond = function getSecond(date) {
6011
- if (!date) {
6012
- return new Date().getSeconds();
6013
- }
6014
- if (typeof date === 'string') {
6015
- date = new Date(date);
6016
- }
6017
- return date.getSeconds();
6018
- };
6019
-
6064
+ */
6065
+ const getSecond = function (date) {
6066
+ if (!date) {
6067
+ return new Date().getSeconds();
6068
+ }
6069
+ if (typeof date === 'string') {
6070
+ date = new Date(date);
6071
+ }
6072
+ return date.getSeconds();
6073
+ };
6074
+
6020
6075
  /**
6021
6076
  * 获取星期几
6022
6077
  * @date 2022年5月7日
6023
6078
  * @param {Date|string} [date] - 日期对象或日期字符串
6024
6079
  * @returns {number} 星期几(0-6,0表示星期日)
6025
- */
6026
- var getWeekday = function getWeekday(date) {
6027
- if (!date) {
6028
- return new Date().getDay();
6029
- }
6030
- if (typeof date === 'string') {
6031
- date = new Date(date);
6032
- }
6033
- return date.getDay();
6034
- };
6035
-
6080
+ */
6081
+ const getWeekday = function (date) {
6082
+ if (!date) {
6083
+ return new Date().getDay();
6084
+ }
6085
+ if (typeof date === 'string') {
6086
+ date = new Date(date);
6087
+ }
6088
+ return date.getDay();
6089
+ };
6090
+
6091
+
6036
6092
  /**
6037
6093
  * @desc 获取上午/下午/晚上
6038
6094
  * @author huangbo
6039
6095
  * @date 2022年5月7日
6040
6096
  * @param {String} [time] - 时间
6041
- **/
6042
- var timeCycle = function timeCycle(time) {
6043
- var hour = 0;
6044
- if (!time) {
6045
- hour = new Date().getHours();
6046
- } else if (typeof time === 'string') {
6047
- // 从时间字符串中提取小时
6048
- var match = time.match(/^(\d{1,2})/);
6049
- if (match) {
6050
- hour = parseInt(match[1], 10);
6051
- }
6052
- } else if (typeof time === 'number') {
6053
- hour = time;
6054
- }
6055
- // 判断时间段
6056
- if (hour >= 5 && hour < 12) {
6057
- return '上午';
6058
- } else if (hour >= 12 && hour < 18) {
6059
- return '下午';
6060
- } else {
6061
- return '晚上';
6062
- }
6097
+ **/
6098
+ const timeCycle = function (time) {
6099
+ let hour = 0;
6100
+ if (!time) {
6101
+ hour = new Date().getHours();
6102
+ } else if (typeof time === 'string') {
6103
+ // 从时间字符串中提取小时
6104
+ const match = time.match(/^(\d{1,2})/);
6105
+ if (match) {
6106
+ hour = parseInt(match[1], 10);
6107
+ }
6108
+ } else if (typeof time === 'number') {
6109
+ hour = time;
6110
+ }
6111
+ // 判断时间段
6112
+ if (hour >= 5 && hour < 12) {
6113
+ return '上午';
6114
+ } else if (hour >= 12 && hour < 18) {
6115
+ return '下午';
6116
+ } else {
6117
+ return '晚上';
6118
+ }
6063
6119
  };
6064
6120
 
6065
6121
  /***/ }),