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
package/lib/login.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 = 189);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 191);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3292,27 +3292,20 @@ module.exports = require("eoss/lib/message");
3292
3292
 
3293
3293
  /***/ }),
3294
3294
 
3295
- /***/ 112:
3295
+ /***/ 113:
3296
3296
  /***/ (function(module, exports) {
3297
3297
 
3298
3298
  module.exports = require("eoss/lib/menu");
3299
3299
 
3300
3300
  /***/ }),
3301
3301
 
3302
- /***/ 115:
3302
+ /***/ 116:
3303
3303
  /***/ (function(module, exports) {
3304
3304
 
3305
3305
  module.exports = require("dompurify");
3306
3306
 
3307
3307
  /***/ }),
3308
3308
 
3309
- /***/ 119:
3310
- /***/ (function(module, exports) {
3311
-
3312
- module.exports = require("eoss/lib/qr-code");
3313
-
3314
- /***/ }),
3315
-
3316
3309
  /***/ 12:
3317
3310
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3318
3311
 
@@ -3517,6 +3510,13 @@ var getRgb = function getRgb($color) {
3517
3510
  /***/ 120:
3518
3511
  /***/ (function(module, exports) {
3519
3512
 
3513
+ module.exports = require("eoss/lib/qr-code");
3514
+
3515
+ /***/ }),
3516
+
3517
+ /***/ 121:
3518
+ /***/ (function(module, exports) {
3519
+
3520
3520
  module.exports = require("eoss/lib/menu-item");
3521
3521
 
3522
3522
  /***/ }),
@@ -3528,35 +3528,35 @@ module.exports = require("eoss/lib/button");
3528
3528
 
3529
3529
  /***/ }),
3530
3530
 
3531
- /***/ 136:
3531
+ /***/ 137:
3532
3532
  /***/ (function(module, exports) {
3533
3533
 
3534
3534
  module.exports = require("eoss/lib/ca-login");
3535
3535
 
3536
3536
  /***/ }),
3537
3537
 
3538
- /***/ 137:
3538
+ /***/ 138:
3539
3539
  /***/ (function(module, exports) {
3540
3540
 
3541
3541
  module.exports = require("eoss/lib/phone-login");
3542
3542
 
3543
3543
  /***/ }),
3544
3544
 
3545
- /***/ 138:
3545
+ /***/ 139:
3546
3546
  /***/ (function(module, exports) {
3547
3547
 
3548
3548
  module.exports = require("eoss/lib/email-login");
3549
3549
 
3550
3550
  /***/ }),
3551
3551
 
3552
- /***/ 139:
3552
+ /***/ 140:
3553
3553
  /***/ (function(module, exports) {
3554
3554
 
3555
3555
  module.exports = require("eoss/lib/qrcode-login");
3556
3556
 
3557
3557
  /***/ }),
3558
3558
 
3559
- /***/ 140:
3559
+ /***/ 141:
3560
3560
  /***/ (function(module, exports) {
3561
3561
 
3562
3562
  module.exports = require("eoss/lib/account-login");
@@ -3570,7 +3570,7 @@ module.exports = require("eoss/lib/loading");
3570
3570
 
3571
3571
  /***/ }),
3572
3572
 
3573
- /***/ 160:
3573
+ /***/ 162:
3574
3574
  /***/ (function(module, exports) {
3575
3575
 
3576
3576
  module.exports = require("enquire.js");
@@ -3591,14 +3591,21 @@ module.exports = require("lodash/set");
3591
3591
 
3592
3592
  /***/ }),
3593
3593
 
3594
- /***/ 189:
3594
+ /***/ 19:
3595
+ /***/ (function(module, exports) {
3596
+
3597
+ module.exports = require("lodash/cloneDeep");
3598
+
3599
+ /***/ }),
3600
+
3601
+ /***/ 191:
3595
3602
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3596
3603
 
3597
3604
  "use strict";
3598
3605
  // ESM COMPAT FLAG
3599
3606
  __webpack_require__.r(__webpack_exports__);
3600
3607
 
3601
- // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/login/src/login.vue?vue&type=template&id=42511444&
3608
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/login/src/login.vue?vue&type=template&id=0774883f&
3602
3609
  var render = function () {
3603
3610
  var _vm = this
3604
3611
  var _h = _vm.$createElement
@@ -3755,7 +3762,11 @@ var render = function () {
3755
3762
  size: _vm.size,
3756
3763
  space: "",
3757
3764
  },
3758
- on: { success: _vm.handleSuccess, open: _vm.handleDownload },
3765
+ on: {
3766
+ success: _vm.handleSuccess,
3767
+ open: _vm.handleDownload,
3768
+ "username-change": _vm.handleUsernameChange,
3769
+ },
3759
3770
  }),
3760
3771
  _c("div", { staticClass: "es-login__download-setup" }, [
3761
3772
  _vm.downloadSetup
@@ -4017,7 +4028,7 @@ var staticRenderFns = []
4017
4028
  render._withStripped = true
4018
4029
 
4019
4030
 
4020
- // CONCATENATED MODULE: ./packages/login/src/login.vue?vue&type=template&id=42511444&
4031
+ // CONCATENATED MODULE: ./packages/login/src/login.vue?vue&type=template&id=0774883f&
4021
4032
 
4022
4033
  // CONCATENATED MODULE: ./packages/login/src/mixins.js
4023
4034
  /* harmony default export */ var mixins = ({
@@ -4106,14 +4117,16 @@ render._withStripped = true
4106
4117
  // 下载App配置
4107
4118
  downloadApp: [],
4108
4119
  // 登录框位置
4109
- loginBoxAlign: this.position
4120
+ loginBoxAlign: this.position,
4121
+ // 登录用户名
4122
+ username: ''
4110
4123
  };
4111
4124
  },
4112
4125
 
4113
4126
  methods: {}
4114
4127
  });
4115
4128
  // EXTERNAL MODULE: external "dompurify"
4116
- var external_dompurify_ = __webpack_require__(115);
4129
+ var external_dompurify_ = __webpack_require__(116);
4117
4130
  var external_dompurify_default = /*#__PURE__*/__webpack_require__.n(external_dompurify_);
4118
4131
 
4119
4132
  // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/login/src/download.vue?vue&type=template&id=43920e36&
@@ -4207,7 +4220,7 @@ var icon_ = __webpack_require__(26);
4207
4220
  var icon_default = /*#__PURE__*/__webpack_require__.n(icon_);
4208
4221
 
4209
4222
  // EXTERNAL MODULE: external "eoss/lib/qr-code"
4210
- var qr_code_ = __webpack_require__(119);
4223
+ var qr_code_ = __webpack_require__(120);
4211
4224
  var qr_code_default = /*#__PURE__*/__webpack_require__.n(qr_code_);
4212
4225
 
4213
4226
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/login/src/download.vue?vue&type=script&lang=js&
@@ -4314,7 +4327,7 @@ var component = Object(componentNormalizer["a" /* default */])(
4314
4327
 
4315
4328
  /* harmony default export */ var download = (component.exports);
4316
4329
  // EXTERNAL MODULE: external "eoss/lib/ca-login"
4317
- var ca_login_ = __webpack_require__(136);
4330
+ var ca_login_ = __webpack_require__(137);
4318
4331
  var ca_login_default = /*#__PURE__*/__webpack_require__.n(ca_login_);
4319
4332
 
4320
4333
  // EXTERNAL MODULE: external "eoss/lib/message-box"
@@ -4322,19 +4335,19 @@ var message_box_ = __webpack_require__(8);
4322
4335
  var message_box_default = /*#__PURE__*/__webpack_require__.n(message_box_);
4323
4336
 
4324
4337
  // EXTERNAL MODULE: external "eoss/lib/phone-login"
4325
- var phone_login_ = __webpack_require__(137);
4338
+ var phone_login_ = __webpack_require__(138);
4326
4339
  var phone_login_default = /*#__PURE__*/__webpack_require__.n(phone_login_);
4327
4340
 
4328
4341
  // EXTERNAL MODULE: external "eoss/lib/email-login"
4329
- var email_login_ = __webpack_require__(138);
4342
+ var email_login_ = __webpack_require__(139);
4330
4343
  var email_login_default = /*#__PURE__*/__webpack_require__.n(email_login_);
4331
4344
 
4332
4345
  // EXTERNAL MODULE: external "eoss/lib/qrcode-login"
4333
- var qrcode_login_ = __webpack_require__(139);
4346
+ var qrcode_login_ = __webpack_require__(140);
4334
4347
  var qrcode_login_default = /*#__PURE__*/__webpack_require__.n(qrcode_login_);
4335
4348
 
4336
4349
  // EXTERNAL MODULE: external "eoss/lib/account-login"
4337
- var account_login_ = __webpack_require__(140);
4350
+ var account_login_ = __webpack_require__(141);
4338
4351
  var account_login_default = /*#__PURE__*/__webpack_require__.n(account_login_);
4339
4352
 
4340
4353
  // EXTERNAL MODULE: ./src/utils/resize-event.js
@@ -4362,7 +4375,7 @@ if (typeof window !== 'undefined') {
4362
4375
  };
4363
4376
  window.matchMedia = window.matchMedia || matchMediaPolyfill;
4364
4377
  // eslint-disable-next-line global-require
4365
- enquire = __webpack_require__(160);
4378
+ enquire = __webpack_require__(162);
4366
4379
  }
4367
4380
 
4368
4381
  /**
@@ -4775,11 +4788,11 @@ var form_ = __webpack_require__(25);
4775
4788
  var form_default = /*#__PURE__*/__webpack_require__.n(form_);
4776
4789
 
4777
4790
  // EXTERNAL MODULE: external "eoss/lib/menu"
4778
- var menu_ = __webpack_require__(112);
4791
+ var menu_ = __webpack_require__(113);
4779
4792
  var menu_default = /*#__PURE__*/__webpack_require__.n(menu_);
4780
4793
 
4781
4794
  // EXTERNAL MODULE: external "eoss/lib/menu-item"
4782
- var menu_item_ = __webpack_require__(120);
4795
+ var menu_item_ = __webpack_require__(121);
4783
4796
  var menu_item_default = /*#__PURE__*/__webpack_require__.n(menu_item_);
4784
4797
 
4785
4798
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/login/src/resetPassword.vue?vue&type=script&lang=js&
@@ -5490,6 +5503,7 @@ function loginvue_type_script_lang_js_objectWithoutProperties(obj, keys) { var t
5490
5503
  //
5491
5504
  //
5492
5505
  //
5506
+ //
5493
5507
 
5494
5508
  /**
5495
5509
  * 登录框组件
@@ -6154,6 +6168,14 @@ var LOGIN_TYPES = {
6154
6168
  }
6155
6169
  },
6156
6170
 
6171
+ /**
6172
+ * 接收登录子组件回传的用户名
6173
+ * @param {string} username - 用户输入的账号
6174
+ */
6175
+ handleUsernameChange: function handleUsernameChange(username) {
6176
+ this.username = username;
6177
+ },
6178
+
6157
6179
  /**
6158
6180
  * 打开下载APP弹窗
6159
6181
  */
@@ -6196,13 +6218,6 @@ login.install = function (Vue) {
6196
6218
 
6197
6219
  /***/ }),
6198
6220
 
6199
- /***/ 19:
6200
- /***/ (function(module, exports) {
6201
-
6202
- module.exports = require("lodash/cloneDeep");
6203
-
6204
- /***/ }),
6205
-
6206
6221
  /***/ 2:
6207
6222
  /***/ (function(module, exports) {
6208
6223
 
@@ -7347,736 +7362,759 @@ var changeInTime = '/baseIssueRules/changeInTime';
7347
7362
  /* unused harmony export getSecond */
7348
7363
  /* unused harmony export getWeekday */
7349
7364
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
7350
-
7351
-
7365
+ /* Modified from https://github.com/taylorhakes/fecha
7366
+ *
7367
+ * The MIT License (MIT)
7368
+ *
7369
+ * Copyright (c) 2015 Taylor Hakes
7370
+ *
7371
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7372
+ * of this software and associated documentation files (the "Software"), to deal
7373
+ * in the Software without restriction, including without limitation the rights
7374
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7375
+ * copies of the Software, and to permit persons to whom the Software is
7376
+ * furnished to do so, subject to the following conditions:
7377
+ *
7378
+ * The above copyright notice and this permission notice shall be included in all
7379
+ * copies or substantial portions of the Software.
7380
+ *
7381
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7382
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7383
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7384
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
7385
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7386
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
7387
+ * SOFTWARE.
7388
+ */
7389
+
7390
+ /*eslint-disable*/
7391
+ // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
7392
+
7393
+
7352
7394
  /**
7353
7395
  * Parse or format dates
7354
7396
  * @class fecha
7355
- */
7356
- var fecha = {};
7357
- var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
7358
- var twoDigits = '\\d\\d?';
7359
- var threeDigits = '\\d{3}';
7360
- var fourDigits = '\\d{4}';
7361
- var word = '[^\\s]+';
7362
- var literal = /\[([^]*?)\]/gm;
7363
- var noop = function noop() {};
7364
-
7365
- function regexEscape(str) {
7366
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
7367
- }
7368
-
7369
- function shorten(arr, sLen) {
7370
- var newArr = [];
7371
- for (var i = 0, len = arr.length; i < len; i++) {
7372
- newArr.push(arr[i].substr(0, sLen));
7373
- }
7374
- return newArr;
7375
- }
7376
-
7377
- function monthUpdate() {
7378
- return function (d, v) {
7379
- var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
7380
- if (~index) {
7381
- d.month = index;
7382
- }
7383
- };
7384
- }
7385
-
7386
- function pad(val, len) {
7387
- val = String(val);
7388
- len = len || 2;
7389
- while (val.length < len) {
7390
- val = '0' + val;
7391
- }
7392
- return val;
7393
- }
7394
-
7395
- // 直接使用中文日期名称常量
7396
- var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
7397
- var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
7398
- var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
7399
- var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
7400
- var amPm = ['上午', '下午'];
7401
- var DoFn = function DoFn(D) {
7402
- return D + '日';
7403
- };
7404
-
7405
- var formatFlags = {
7406
- D: function D(dateObj) {
7407
- return dateObj.getDay();
7408
- },
7409
- DD: function DD(dateObj) {
7410
- return pad(dateObj.getDay());
7411
- },
7412
- Do: function Do(dateObj) {
7413
- return DoFn(dateObj.getDate());
7414
- },
7415
- d: function d(dateObj) {
7416
- return dateObj.getDate();
7417
- },
7418
- dd: function dd(dateObj) {
7419
- return pad(dateObj.getDate());
7420
- },
7421
- ddd: function ddd(dateObj) {
7422
- return dayNamesShort[dateObj.getDay()];
7423
- },
7424
- dddd: function dddd(dateObj) {
7425
- return dayNames[dateObj.getDay()];
7426
- },
7427
- M: function M(dateObj) {
7428
- return dateObj.getMonth() + 1;
7429
- },
7430
- MM: function MM(dateObj) {
7431
- return pad(dateObj.getMonth() + 1);
7432
- },
7433
- MMM: function MMM(dateObj) {
7434
- return monthNamesShort[dateObj.getMonth()];
7435
- },
7436
- MMMM: function MMMM(dateObj) {
7437
- return monthNames[dateObj.getMonth()];
7438
- },
7439
- yy: function yy(dateObj) {
7440
- return pad(String(dateObj.getFullYear()), 4).substr(2);
7441
- },
7442
- yyyy: function yyyy(dateObj) {
7443
- return pad(dateObj.getFullYear(), 4);
7444
- },
7445
- h: function h(dateObj) {
7446
- return dateObj.getHours() % 12 || 12;
7447
- },
7448
- hh: function hh(dateObj) {
7449
- return pad(dateObj.getHours() % 12 || 12);
7450
- },
7451
- H: function H(dateObj) {
7452
- return dateObj.getHours();
7453
- },
7454
- HH: function HH(dateObj) {
7455
- return pad(dateObj.getHours());
7456
- },
7457
- m: function m(dateObj) {
7458
- return dateObj.getMinutes();
7459
- },
7460
- mm: function mm(dateObj) {
7461
- return pad(dateObj.getMinutes());
7462
- },
7463
- s: function s(dateObj) {
7464
- return dateObj.getSeconds();
7465
- },
7466
- ss: function ss(dateObj) {
7467
- return pad(dateObj.getSeconds());
7468
- },
7469
- S: function S(dateObj) {
7470
- return Math.round(dateObj.getMilliseconds() / 100);
7471
- },
7472
- SS: function SS(dateObj) {
7473
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
7474
- },
7475
- SSS: function SSS(dateObj) {
7476
- return pad(dateObj.getMilliseconds(), 3);
7477
- },
7478
- a: function a(dateObj) {
7479
- return dateObj.getHours() < 12 ? '上午' : '下午';
7480
- },
7481
- A: function A(dateObj) {
7482
- return dateObj.getHours() < 12 ? '上午' : '下午';
7483
- },
7484
- ZZ: function ZZ(dateObj) {
7485
- var o = dateObj.getTimezoneOffset();
7486
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
7487
- }
7488
- };
7489
-
7490
- var parseFlags = {
7491
- d: [twoDigits, function (d, v) {
7492
- d.day = v;
7493
- }],
7494
- Do: [twoDigits + word, function (d, v) {
7495
- d.day = parseInt(v, 10);
7496
- }],
7497
- M: [twoDigits, function (d, v) {
7498
- d.month = v - 1;
7499
- }],
7500
- yy: [twoDigits, function (d, v) {
7501
- var da = new Date(),
7502
- cent = +('' + da.getFullYear()).substr(0, 2);
7503
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
7504
- }],
7505
- h: [twoDigits, function (d, v) {
7506
- d.hour = v;
7507
- }],
7508
- m: [twoDigits, function (d, v) {
7509
- d.minute = v;
7510
- }],
7511
- s: [twoDigits, function (d, v) {
7512
- d.second = v;
7513
- }],
7514
- yyyy: [fourDigits, function (d, v) {
7515
- d.year = v;
7516
- }],
7517
- S: ['\\d', function (d, v) {
7518
- d.millisecond = v * 100;
7519
- }],
7520
- SS: ['\\d{2}', function (d, v) {
7521
- d.millisecond = v * 10;
7522
- }],
7523
- SSS: [threeDigits, function (d, v) {
7524
- d.millisecond = v;
7525
- }],
7526
- D: [twoDigits, noop],
7527
- ddd: [word, noop],
7528
- MMM: [word, monthUpdate('monthNamesShort')],
7529
- MMMM: [word, monthUpdate('monthNames')],
7530
- a: [word, function (d, v) {
7531
- var val = v.toLowerCase();
7532
- if (val === '上午') {
7533
- d.isPm = false;
7534
- } else if (val === '下午') {
7535
- d.isPm = true;
7536
- }
7537
- }],
7538
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
7539
- var parts = (v + '').match(/([+-]|\d\d)/gi),
7540
- minutes = void 0;
7541
-
7542
- if (parts) {
7543
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
7544
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
7545
- }
7546
- }]
7547
- };
7548
- parseFlags.dd = parseFlags.d;
7549
- parseFlags.dddd = parseFlags.ddd;
7550
- parseFlags.DD = parseFlags.D;
7551
- parseFlags.mm = parseFlags.m;
7552
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
7553
- parseFlags.MM = parseFlags.M;
7554
- parseFlags.ss = parseFlags.s;
7555
- parseFlags.A = parseFlags.a;
7556
-
7557
- // Some common format strings
7558
- fecha.masks = {
7559
- default: 'ddd MMM dd yyyy HH:mm:ss',
7560
- shortDate: 'M/D/yy',
7561
- mediumDate: 'MMM d, yyyy',
7562
- longDate: 'MMMM d, yyyy',
7563
- fullDate: 'dddd, MMMM d, yyyy',
7564
- shortTime: 'HH:mm',
7565
- mediumTime: 'HH:mm:ss',
7566
- longTime: 'HH:mm:ss.SSS'
7567
- };
7568
-
7397
+ */
7398
+ const fecha = {};
7399
+ const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
7400
+ const twoDigits = '\\d\\d?';
7401
+ const threeDigits = '\\d{3}';
7402
+ const fourDigits = '\\d{4}';
7403
+ const word = '[^\\s]+';
7404
+ const literal = /\[([^]*?)\]/gm;
7405
+ const noop = function () {};
7406
+
7407
+ function regexEscape(str) {
7408
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
7409
+ }
7410
+
7411
+ function shorten(arr, sLen) {
7412
+ const newArr = [];
7413
+ for (let i = 0, len = arr.length; i < len; i++) {
7414
+ newArr.push(arr[i].substr(0, sLen));
7415
+ }
7416
+ return newArr;
7417
+ }
7418
+
7419
+ function monthUpdate() {
7420
+ return function (d, v) {
7421
+ const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
7422
+ if (~index) {
7423
+ d.month = index;
7424
+ }
7425
+ };
7426
+ }
7427
+
7428
+ function pad(val, len) {
7429
+ val = String(val);
7430
+ len = len || 2;
7431
+ while (val.length < len) {
7432
+ val = '0' + val;
7433
+ }
7434
+ return val;
7435
+ }
7436
+
7437
+ // 直接使用中文日期名称常量
7438
+ const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
7439
+ const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
7440
+ const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
7441
+ const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
7442
+ const amPm = ['上午', '下午'];
7443
+ const DoFn = function DoFn(D) {
7444
+ return D + '日';
7445
+ };
7446
+
7447
+ const formatFlags = {
7448
+ D: function(dateObj) {
7449
+ return dateObj.getDay();
7450
+ },
7451
+ DD: function(dateObj) {
7452
+ return pad(dateObj.getDay());
7453
+ },
7454
+ Do: function(dateObj) {
7455
+ return DoFn(dateObj.getDate());
7456
+ },
7457
+ d: function(dateObj) {
7458
+ return dateObj.getDate();
7459
+ },
7460
+ dd: function(dateObj) {
7461
+ return pad(dateObj.getDate());
7462
+ },
7463
+ ddd: function(dateObj) {
7464
+ return dayNamesShort[dateObj.getDay()];
7465
+ },
7466
+ dddd: function(dateObj) {
7467
+ return dayNames[dateObj.getDay()];
7468
+ },
7469
+ M: function(dateObj) {
7470
+ return dateObj.getMonth() + 1;
7471
+ },
7472
+ MM: function(dateObj) {
7473
+ return pad(dateObj.getMonth() + 1);
7474
+ },
7475
+ MMM: function(dateObj) {
7476
+ return monthNamesShort[dateObj.getMonth()];
7477
+ },
7478
+ MMMM: function(dateObj) {
7479
+ return monthNames[dateObj.getMonth()];
7480
+ },
7481
+ yy: function(dateObj) {
7482
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
7483
+ },
7484
+ yyyy: function(dateObj) {
7485
+ return pad(dateObj.getFullYear(), 4);
7486
+ },
7487
+ h: function(dateObj) {
7488
+ return dateObj.getHours() % 12 || 12;
7489
+ },
7490
+ hh: function(dateObj) {
7491
+ return pad(dateObj.getHours() % 12 || 12);
7492
+ },
7493
+ H: function(dateObj) {
7494
+ return dateObj.getHours();
7495
+ },
7496
+ HH: function(dateObj) {
7497
+ return pad(dateObj.getHours());
7498
+ },
7499
+ m: function(dateObj) {
7500
+ return dateObj.getMinutes();
7501
+ },
7502
+ mm: function(dateObj) {
7503
+ return pad(dateObj.getMinutes());
7504
+ },
7505
+ s: function(dateObj) {
7506
+ return dateObj.getSeconds();
7507
+ },
7508
+ ss: function(dateObj) {
7509
+ return pad(dateObj.getSeconds());
7510
+ },
7511
+ S: function(dateObj) {
7512
+ return Math.round(dateObj.getMilliseconds() / 100);
7513
+ },
7514
+ SS: function(dateObj) {
7515
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
7516
+ },
7517
+ SSS: function(dateObj) {
7518
+ return pad(dateObj.getMilliseconds(), 3);
7519
+ },
7520
+ a: function(dateObj) {
7521
+ return dateObj.getHours() < 12 ? '上午' : '下午';
7522
+ },
7523
+ A: function(dateObj) {
7524
+ return dateObj.getHours() < 12 ? '上午' : '下午';
7525
+ },
7526
+ ZZ: function(dateObj) {
7527
+ const o = dateObj.getTimezoneOffset();
7528
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
7529
+ }
7530
+ };
7531
+
7532
+ const parseFlags = {
7533
+ d: [twoDigits, function (d, v) {
7534
+ d.day = v;
7535
+ }],
7536
+ Do: [twoDigits + word, function (d, v) {
7537
+ d.day = parseInt(v, 10);
7538
+ }],
7539
+ M: [twoDigits, function (d, v) {
7540
+ d.month = v - 1;
7541
+ }],
7542
+ yy: [twoDigits, function (d, v) {
7543
+ const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
7544
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
7545
+ }],
7546
+ h: [twoDigits, function (d, v) {
7547
+ d.hour = v;
7548
+ }],
7549
+ m: [twoDigits, function (d, v) {
7550
+ d.minute = v;
7551
+ }],
7552
+ s: [twoDigits, function (d, v) {
7553
+ d.second = v;
7554
+ }],
7555
+ yyyy: [fourDigits, function (d, v) {
7556
+ d.year = v;
7557
+ }],
7558
+ S: ['\\d', function (d, v) {
7559
+ d.millisecond = v * 100;
7560
+ }],
7561
+ SS: ['\\d{2}', function (d, v) {
7562
+ d.millisecond = v * 10;
7563
+ }],
7564
+ SSS: [threeDigits, function (d, v) {
7565
+ d.millisecond = v;
7566
+ }],
7567
+ D: [twoDigits, noop],
7568
+ ddd: [word, noop],
7569
+ MMM: [word, monthUpdate('monthNamesShort')],
7570
+ MMMM: [word, monthUpdate('monthNames')],
7571
+ a: [word, function (d, v) {
7572
+ const val = v.toLowerCase();
7573
+ if (val === '上午') {
7574
+ d.isPm = false;
7575
+ } else if (val === '下午') {
7576
+ d.isPm = true;
7577
+ }
7578
+ }],
7579
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
7580
+ let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
7581
+
7582
+ if (parts) {
7583
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
7584
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
7585
+ }
7586
+ }]
7587
+ };
7588
+ parseFlags.dd = parseFlags.d;
7589
+ parseFlags.dddd = parseFlags.ddd;
7590
+ parseFlags.DD = parseFlags.D;
7591
+ parseFlags.mm = parseFlags.m;
7592
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
7593
+ parseFlags.MM = parseFlags.M;
7594
+ parseFlags.ss = parseFlags.s;
7595
+ parseFlags.A = parseFlags.a;
7596
+
7597
+
7598
+ // Some common format strings
7599
+ fecha.masks = {
7600
+ default: 'ddd MMM dd yyyy HH:mm:ss',
7601
+ shortDate: 'M/D/yy',
7602
+ mediumDate: 'MMM d, yyyy',
7603
+ longDate: 'MMMM d, yyyy',
7604
+ fullDate: 'dddd, MMMM d, yyyy',
7605
+ shortTime: 'HH:mm',
7606
+ mediumTime: 'HH:mm:ss',
7607
+ longTime: 'HH:mm:ss.SSS'
7608
+ };
7609
+
7569
7610
  /***
7570
7611
  * Format a date
7571
7612
  * @method format
7572
7613
  * @param {Date|number} dateObj
7573
7614
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
7574
- */
7575
- fecha.format = function (dateObj, mask) {
7576
- if (typeof dateObj === 'number') {
7577
- dateObj = new Date(dateObj);
7578
- }
7579
-
7580
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
7581
- throw new Error('Invalid Date in fecha.format');
7582
- }
7583
-
7584
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
7585
-
7586
- var literals = [];
7587
-
7588
- // Make literals inactive by replacing them with ??
7589
- mask = mask.replace(literal, function ($0, $1) {
7590
- literals.push($1);
7591
- return '@@@';
7592
- });
7593
- // Apply formatting rules
7594
- mask = mask.replace(token, function ($0) {
7595
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
7596
- });
7597
- // Inline literal values back into the formatted value
7598
- return mask.replace(/@@@/g, function () {
7599
- return literals.shift();
7600
- });
7601
- };
7602
-
7615
+ */
7616
+ fecha.format = function (dateObj, mask) {
7617
+ if (typeof dateObj === 'number') {
7618
+ dateObj = new Date(dateObj);
7619
+ }
7620
+
7621
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
7622
+ throw new Error('Invalid Date in fecha.format');
7623
+ }
7624
+
7625
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
7626
+
7627
+ const literals = [];
7628
+
7629
+ // Make literals inactive by replacing them with ??
7630
+ mask = mask.replace(literal, function($0, $1) {
7631
+ literals.push($1);
7632
+ return '@@@';
7633
+ });
7634
+ // Apply formatting rules
7635
+ mask = mask.replace(token, function ($0) {
7636
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
7637
+ });
7638
+ // Inline literal values back into the formatted value
7639
+ return mask.replace(/@@@/g, function() {
7640
+ return literals.shift();
7641
+ });
7642
+ };
7643
+
7603
7644
  /**
7604
7645
  * Parse a date string into an object, changes - into /
7605
7646
  * @method parse
7606
7647
  * @param {string} dateStr Date string
7607
7648
  * @param {string} format Date parse format
7608
7649
  * @returns {Date|boolean}
7609
- */
7610
- fecha.parse = function (dateStr, format) {
7611
- if (typeof format !== 'string') {
7612
- throw new Error('Invalid format in fecha.parse');
7613
- }
7614
-
7615
- format = fecha.masks[format] || format;
7616
-
7617
- // Avoid regular expression denial of service, fail early for really long strings
7618
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
7619
- if (dateStr.length > 1000) {
7620
- return null;
7621
- }
7622
-
7623
- var dateInfo = {};
7624
- var parseInfo = [];
7625
- var literals = [];
7626
- format = format.replace(literal, function ($0, $1) {
7627
- literals.push($1);
7628
- return '@@@';
7629
- });
7630
- var newFormat = regexEscape(format).replace(token, function ($0) {
7631
- if (parseFlags[$0]) {
7632
- var info = parseFlags[$0];
7633
- parseInfo.push(info[1]);
7634
- return '(' + info[0] + ')';
7635
- }
7636
-
7637
- return $0;
7638
- });
7639
- newFormat = newFormat.replace(/@@@/g, function () {
7640
- return literals.shift();
7641
- });
7642
- var matches = dateStr.match(new RegExp(newFormat, 'i'));
7643
- if (!matches) {
7644
- return null;
7645
- }
7646
-
7647
- for (var i = 1; i < matches.length; i++) {
7648
- parseInfo[i - 1](dateInfo, matches[i]);
7649
- }
7650
-
7651
- var today = new Date();
7652
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
7653
- dateInfo.hour = +dateInfo.hour + 12;
7654
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
7655
- dateInfo.hour = 0;
7656
- }
7657
-
7658
- var date = void 0;
7659
- if (dateInfo.timezoneOffset != null) {
7660
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
7661
- 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));
7662
- } else {
7663
- 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);
7664
- }
7665
- return date;
7666
- };
7667
-
7668
- // 导出fecha对象
7669
-
7670
-
7671
- // 以下是从date-util.js合并的函数
7672
- var newArray = function newArray(start, end) {
7673
- var result = [];
7674
- for (var i = start; i <= end; i++) {
7675
- result.push(i);
7676
- }
7677
- return result;
7678
- };
7679
-
7680
- var getSettings = function getSettings() {
7681
- return {
7682
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
7683
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
7684
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
7685
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
7686
- amPm: ['上午', '下午']
7687
- };
7688
- };
7689
-
7690
- var toDate = function toDate(date) {
7691
- return isDate(date) ? new Date(date) : null;
7692
- };
7693
-
7694
- var isDate = function isDate(date) {
7695
- if (date === null || date === undefined) return false;
7696
- if (isNaN(new Date(date).getTime())) return false;
7697
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
7698
- return true;
7699
- };
7700
-
7701
- var isDateObject = function isDateObject(val) {
7702
- return val instanceof Date;
7703
- };
7704
-
7705
- var formatDate = function formatDate(date) {
7706
- var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
7707
-
7708
- // 处理多种输入类型
7709
- if (!date) return '';
7710
-
7711
- // 如果是时间戳,转成日期对象
7712
- if (typeof date === 'number') {
7713
- date = new Date(date);
7714
- }
7715
- // 如果是字符串,转成日期对象
7716
- if (typeof date === 'string') {
7717
- date = new Date(date);
7718
- }
7719
-
7720
- // 调用toDate进一步验证和转换
7721
- date = toDate(date);
7722
- if (!date) return '';
7723
-
7724
- // 兼容大写和小写的格式标记
7725
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
7726
- var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
7727
-
7728
- // 使用fecha库进行格式化,支持中文配置
7729
- var str = fecha.format(date, lowercaseFormat, getSettings());
7730
- return str;
7731
- };
7732
-
7733
- var parseDate = function parseDate(string, format) {
7734
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
7735
- };
7736
-
7737
- var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
7738
- if (month === 3 || month === 5 || month === 8 || month === 10) {
7739
- return 30;
7740
- }
7741
-
7742
- if (month === 1) {
7743
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
7744
- return 29;
7745
- } else {
7746
- return 28;
7747
- }
7748
- }
7749
-
7750
- return 31;
7751
- };
7752
-
7753
- var getDayCountOfYear = function getDayCountOfYear(year) {
7754
- var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
7755
- return isLeapYear ? 366 : 365;
7756
- };
7757
-
7758
- var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
7759
- var temp = new Date(date.getTime());
7760
- temp.setDate(1);
7761
- return temp.getDay();
7762
- };
7763
-
7764
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
7765
- // {prev, next} Date should work for Daylight Saving Time
7766
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
7767
- var prevDate = function prevDate(date) {
7768
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7769
-
7770
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
7771
- };
7772
-
7773
- var nextDate = function nextDate(date) {
7774
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7775
-
7776
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
7777
- };
7778
-
7779
- var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
7780
- var result = new Date(year, month, 1);
7781
- var day = result.getDay();
7782
-
7783
- if (day === 0) {
7784
- return prevDate(result, 7);
7785
- } else {
7786
- return prevDate(result, day);
7787
- }
7788
- };
7789
-
7790
- var getWeekNumber = function getWeekNumber(date) {
7791
- // 支持多种输入类型
7792
- if (!date || !isDate(date)) {
7793
- date = new Date();
7794
- }
7795
- if (typeof date === 'string') {
7796
- date = new Date(date);
7797
- }
7798
-
7799
- // 验证日期有效性
7800
- if (!isDate(date)) return null;
7801
-
7802
- var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
7803
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
7804
- // 将星期日的星期数设为7
7805
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
7806
- // 获取当年的第一天
7807
- var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
7808
- // 计算到最近的星期四的完整周数
7809
- var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
7810
- // 返回周数
7811
- return weekNo;
7812
- };
7813
-
7814
- var getRangeHours = function getRangeHours(ranges) {
7815
- var hours = [];
7816
- var disabledHours = [];
7817
-
7818
- (ranges || []).forEach(function (range) {
7819
- var value = range.map(function (date) {
7820
- return date.getHours();
7821
- });
7822
-
7823
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
7824
- });
7825
-
7826
- if (disabledHours.length) {
7827
- for (var i = 0; i < 24; i++) {
7828
- hours[i] = disabledHours.indexOf(i) === -1;
7829
- }
7830
- } else {
7831
- for (var _i = 0; _i < 24; _i++) {
7832
- hours[_i] = false;
7833
- }
7834
- }
7835
-
7836
- return hours;
7837
- };
7838
-
7839
- var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
7840
- if (amount <= 0) return [];
7841
- var temp = new Date(date.getTime());
7842
- temp.setDate(0);
7843
- var lastDay = temp.getDate();
7844
- return range(amount).map(function (_, index) {
7845
- return lastDay - (amount - index - 1);
7846
- });
7847
- };
7848
-
7849
- var getMonthDays = function getMonthDays(date) {
7850
- var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
7851
- var days = temp.getDate();
7852
- return range(days).map(function (_, index) {
7853
- return index + 1;
7854
- });
7855
- };
7856
-
7857
- function setRangeData(arr, start, end, value) {
7858
- for (var i = start; i < end; i++) {
7859
- arr[i] = value;
7860
- }
7861
- }
7862
-
7863
- var getRangeMinutes = function getRangeMinutes(ranges, hour) {
7864
- var minutes = new Array(60);
7865
-
7866
- if (ranges.length > 0) {
7867
- ranges.forEach(function (range) {
7868
- var start = range[0];
7869
- var end = range[1];
7870
- var startHour = start.getHours();
7871
- var startMinute = start.getMinutes();
7872
- var endHour = end.getHours();
7873
- var endMinute = end.getMinutes();
7874
- if (startHour === hour && endHour !== hour) {
7875
- setRangeData(minutes, startMinute, 60, true);
7876
- } else if (startHour === hour && endHour === hour) {
7877
- setRangeData(minutes, startMinute, endMinute + 1, true);
7878
- } else if (startHour !== hour && endHour === hour) {
7879
- setRangeData(minutes, 0, endMinute + 1, true);
7880
- } else if (startHour < hour && endHour > hour) {
7881
- setRangeData(minutes, 0, 60, true);
7882
- }
7883
- });
7884
- } else {
7885
- setRangeData(minutes, 0, 60, true);
7886
- }
7887
- return minutes;
7888
- };
7889
-
7890
- var range = function range(n) {
7891
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
7892
- return Array.apply(null, { length: n }).map(function (_, n) {
7893
- return n;
7894
- });
7895
- };
7896
-
7897
- var modifyDate = function modifyDate(date, y, m, d) {
7898
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
7899
- };
7900
-
7901
- var modifyTime = function modifyTime(date, h, m, s) {
7902
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
7903
- };
7904
-
7905
- var modifyWithTimeString = function modifyWithTimeString(date, time) {
7906
- if (date == null || !time) {
7907
- return date;
7908
- }
7909
- time = parseDate(time, 'HH:mm:ss');
7910
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
7911
- };
7912
-
7913
- var clearTime = function clearTime(date) {
7914
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
7915
- };
7916
-
7917
- var clearMilliseconds = function clearMilliseconds(date) {
7918
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
7919
- };
7920
-
7921
- var limitTimeRange = function limitTimeRange(date, ranges) {
7922
- var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
7923
-
7924
- // TODO: refactory a more elegant solution
7925
- if (ranges.length === 0) return date;
7926
- var normalizeDate = function normalizeDate(date) {
7927
- return fecha.parse(fecha.format(date, format), format);
7928
- };
7929
- var ndate = normalizeDate(date);
7930
- var nranges = ranges.map(function (range) {
7931
- return range.map(normalizeDate);
7932
- });
7933
- if (nranges.some(function (nrange) {
7934
- return ndate >= nrange[0] && ndate <= nrange[1];
7935
- })) return date;
7936
-
7937
- var minDate = nranges[0][0];
7938
- var maxDate = nranges[0][0];
7939
-
7940
- nranges.forEach(function (nrange) {
7941
- minDate = new Date(Math.min(nrange[0], minDate));
7942
- maxDate = new Date(Math.max(nrange[1], minDate));
7943
- });
7944
-
7945
- var ret = ndate < minDate ? minDate : maxDate;
7946
- // preserve Year/Month/Date
7947
- return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
7948
- };
7949
-
7950
- var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
7951
- var limitedDate = limitTimeRange(date, selectableRange, format);
7952
- return limitedDate.getTime() === date.getTime();
7953
- };
7954
-
7955
- var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
7956
- // clamp date to the number of days in `year`, `month`
7957
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
7958
- var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
7959
- return modifyDate(date, year, month, monthDate);
7960
- };
7961
-
7962
- var prevMonth = function prevMonth(date) {
7963
- var year = date.getFullYear();
7964
- var month = date.getMonth();
7965
- return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
7966
- };
7967
-
7968
- var nextMonth = function nextMonth(date) {
7969
- var year = date.getFullYear();
7970
- var month = date.getMonth();
7971
- return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
7972
- };
7973
-
7974
- var prevYear = function prevYear(date) {
7975
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7976
-
7977
- var year = date.getFullYear();
7978
- var month = date.getMonth();
7979
- return changeYearMonthAndClampDate(date, year - amount, month);
7980
- };
7981
-
7982
- var nextYear = function nextYear(date) {
7983
- var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7984
-
7985
- var year = date.getFullYear();
7986
- var month = date.getMonth();
7987
- return changeYearMonthAndClampDate(date, year + amount, month);
7988
- };
7989
-
7990
- var extractDateFormat = function extractDateFormat(format) {
7991
- return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
7992
- };
7993
-
7994
- var extractTimeFormat = function extractTimeFormat(format) {
7995
- return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
7996
- };
7997
-
7998
- var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
7999
- return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
8000
- };
8001
-
7650
+ */
7651
+ fecha.parse = function (dateStr, format) {
7652
+ if (typeof format !== 'string') {
7653
+ throw new Error('Invalid format in fecha.parse');
7654
+ }
7655
+
7656
+ format = fecha.masks[format] || format;
7657
+
7658
+ // Avoid regular expression denial of service, fail early for really long strings
7659
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
7660
+ if (dateStr.length > 1000) {
7661
+ return null;
7662
+ }
7663
+
7664
+ const dateInfo = {};
7665
+ const parseInfo = [];
7666
+ const literals = [];
7667
+ format = format.replace(literal, function($0, $1) {
7668
+ literals.push($1);
7669
+ return '@@@';
7670
+ });
7671
+ let newFormat = regexEscape(format).replace(token, function ($0) {
7672
+ if (parseFlags[$0]) {
7673
+ const info = parseFlags[$0];
7674
+ parseInfo.push(info[1]);
7675
+ return '(' + info[0] + ')';
7676
+ }
7677
+
7678
+ return $0;
7679
+ });
7680
+ newFormat = newFormat.replace(/@@@/g, function() {
7681
+ return literals.shift();
7682
+ });
7683
+ const matches = dateStr.match(new RegExp(newFormat, 'i'));
7684
+ if (!matches) {
7685
+ return null;
7686
+ }
7687
+
7688
+ for (let i = 1; i < matches.length; i++) {
7689
+ parseInfo[i - 1](dateInfo, matches[i]);
7690
+ }
7691
+
7692
+ const today = new Date();
7693
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
7694
+ dateInfo.hour = +dateInfo.hour + 12;
7695
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
7696
+ dateInfo.hour = 0;
7697
+ }
7698
+
7699
+ let date;
7700
+ if (dateInfo.timezoneOffset != null) {
7701
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
7702
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
7703
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
7704
+ } else {
7705
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
7706
+ dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
7707
+ }
7708
+ return date;
7709
+ };
7710
+
7711
+ // 导出fecha对象
7712
+
7713
+
7714
+ // 以下是从date-util.js合并的函数
7715
+ const newArray = function(start, end) {
7716
+ let result = [];
7717
+ for (let i = start; i <= end; i++) {
7718
+ result.push(i);
7719
+ }
7720
+ return result;
7721
+ };
7722
+
7723
+ const getSettings = () => {
7724
+ return {
7725
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
7726
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
7727
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
7728
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
7729
+ amPm: ['上午', '下午']
7730
+ };
7731
+ };
7732
+
7733
+ const toDate = function(date) {
7734
+ return isDate(date) ? new Date(date) : null;
7735
+ };
7736
+
7737
+ const isDate = function(date) {
7738
+ if (date === null || date === undefined) return false;
7739
+ if (isNaN(new Date(date).getTime())) return false;
7740
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
7741
+ return true;
7742
+ };
7743
+
7744
+ const isDateObject = function(val) {
7745
+ return val instanceof Date;
7746
+ };
7747
+
7748
+ const formatDate = function (date, format = 'yyyy-MM-dd') {
7749
+ // 处理多种输入类型
7750
+ if (!date) return '';
7751
+
7752
+ // 如果是时间戳,转成日期对象
7753
+ if (typeof date === 'number') {
7754
+ date = new Date(date);
7755
+ }
7756
+ // 如果是字符串,转成日期对象
7757
+ if (typeof date === 'string') {
7758
+ date = new Date(date);
7759
+ }
7760
+
7761
+ // 调用toDate进一步验证和转换
7762
+ date = toDate(date);
7763
+ if (!date) return '';
7764
+
7765
+ // 兼容大写和小写的格式标记
7766
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
7767
+ const lowercaseFormat = format
7768
+ .replace(/YYYY/g, 'yyyy')
7769
+ .replace(/D/g, 'd')
7770
+
7771
+ // 使用fecha库进行格式化,支持中文配置
7772
+ const str = fecha.format(date, lowercaseFormat, getSettings());
7773
+ return str;
7774
+ };
7775
+
7776
+ const parseDate = function(string, format) {
7777
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
7778
+ };
7779
+
7780
+ const getDayCountOfMonth = function(year, month) {
7781
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
7782
+ return 30;
7783
+ }
7784
+
7785
+ if (month === 1) {
7786
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
7787
+ return 29;
7788
+ } else {
7789
+ return 28;
7790
+ }
7791
+ }
7792
+
7793
+ return 31;
7794
+ };
7795
+
7796
+ const getDayCountOfYear = function(year) {
7797
+ const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
7798
+ return isLeapYear ? 366 : 365;
7799
+ };
7800
+
7801
+ const getFirstDayOfMonth = function(date) {
7802
+ const temp = new Date(date.getTime());
7803
+ temp.setDate(1);
7804
+ return temp.getDay();
7805
+ };
7806
+
7807
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
7808
+ // {prev, next} Date should work for Daylight Saving Time
7809
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
7810
+ const prevDate = function(date, amount = 1) {
7811
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
7812
+ };
7813
+
7814
+ const nextDate = function(date, amount = 1) {
7815
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
7816
+ };
7817
+
7818
+ const getStartDateOfMonth = function(year, month) {
7819
+ const result = new Date(year, month, 1);
7820
+ const day = result.getDay();
7821
+
7822
+ if (day === 0) {
7823
+ return prevDate(result, 7);
7824
+ } else {
7825
+ return prevDate(result, day);
7826
+ }
7827
+ };
7828
+
7829
+ const getWeekNumber = function(date) {
7830
+ // 支持多种输入类型
7831
+ if (!date||!isDate(date)) {
7832
+ date = new Date();
7833
+ }
7834
+ if (typeof date === 'string') {
7835
+ date = new Date(date);
7836
+ }
7837
+
7838
+ // 验证日期有效性
7839
+ if (!isDate(date)) return null;
7840
+
7841
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
7842
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
7843
+ // 将星期日的星期数设为7
7844
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
7845
+ // 获取当年的第一天
7846
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
7847
+ // 计算到最近的星期四的完整周数
7848
+ const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
7849
+ // 返回周数
7850
+ return weekNo;
7851
+ };
7852
+
7853
+ const getRangeHours = function(ranges) {
7854
+ const hours = [];
7855
+ let disabledHours = [];
7856
+
7857
+ (ranges || []).forEach(range => {
7858
+ const value = range.map(date => date.getHours());
7859
+
7860
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
7861
+ });
7862
+
7863
+ if (disabledHours.length) {
7864
+ for (let i = 0; i < 24; i++) {
7865
+ hours[i] = disabledHours.indexOf(i) === -1;
7866
+ }
7867
+ } else {
7868
+ for (let i = 0; i < 24; i++) {
7869
+ hours[i] = false;
7870
+ }
7871
+ }
7872
+
7873
+ return hours;
7874
+ };
7875
+
7876
+ const getPrevMonthLastDays = (date, amount) => {
7877
+ if (amount <= 0) return [];
7878
+ const temp = new Date(date.getTime());
7879
+ temp.setDate(0);
7880
+ const lastDay = temp.getDate();
7881
+ return range(amount).map((_, index) => lastDay - (amount - index - 1));
7882
+ };
7883
+
7884
+ const getMonthDays = (date) => {
7885
+ const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
7886
+ const days = temp.getDate();
7887
+ return range(days).map((_, index) => index + 1);
7888
+ };
7889
+
7890
+ function setRangeData(arr, start, end, value) {
7891
+ for (let i = start; i < end; i++) {
7892
+ arr[i] = value;
7893
+ }
7894
+ }
7895
+
7896
+ const getRangeMinutes = function(ranges, hour) {
7897
+ const minutes = new Array(60);
7898
+
7899
+ if (ranges.length > 0) {
7900
+ ranges.forEach(range => {
7901
+ const start = range[0];
7902
+ const end = range[1];
7903
+ const startHour = start.getHours();
7904
+ const startMinute = start.getMinutes();
7905
+ const endHour = end.getHours();
7906
+ const endMinute = end.getMinutes();
7907
+ if (startHour === hour && endHour !== hour) {
7908
+ setRangeData(minutes, startMinute, 60, true);
7909
+ } else if (startHour === hour && endHour === hour) {
7910
+ setRangeData(minutes, startMinute, endMinute + 1, true);
7911
+ } else if (startHour !== hour && endHour === hour) {
7912
+ setRangeData(minutes, 0, endMinute + 1, true);
7913
+ } else if (startHour < hour && endHour > hour) {
7914
+ setRangeData(minutes, 0, 60, true);
7915
+ }
7916
+ });
7917
+ } else {
7918
+ setRangeData(minutes, 0, 60, true);
7919
+ }
7920
+ return minutes;
7921
+ };
7922
+
7923
+ const range = function(n) {
7924
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
7925
+ return Array.apply(null, {length: n}).map((_, n) => n);
7926
+ };
7927
+
7928
+ const modifyDate = function(date, y, m, d) {
7929
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
7930
+ };
7931
+
7932
+ const modifyTime = function(date, h, m, s) {
7933
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
7934
+ };
7935
+
7936
+ const modifyWithTimeString = (date, time) => {
7937
+ if (date == null || !time) {
7938
+ return date;
7939
+ }
7940
+ time = parseDate(time, 'HH:mm:ss');
7941
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
7942
+ };
7943
+
7944
+ const clearTime = function(date) {
7945
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
7946
+ };
7947
+
7948
+ const clearMilliseconds = function(date) {
7949
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
7950
+ };
7951
+
7952
+ const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
7953
+ // TODO: refactory a more elegant solution
7954
+ if (ranges.length === 0) return date;
7955
+ const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
7956
+ const ndate = normalizeDate(date);
7957
+ const nranges = ranges.map(range => range.map(normalizeDate));
7958
+ if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
7959
+
7960
+ let minDate = nranges[0][0];
7961
+ let maxDate = nranges[0][0];
7962
+
7963
+ nranges.forEach(nrange => {
7964
+ minDate = new Date(Math.min(nrange[0], minDate));
7965
+ maxDate = new Date(Math.max(nrange[1], minDate));
7966
+ });
7967
+
7968
+ const ret = ndate < minDate ? minDate : maxDate;
7969
+ // preserve Year/Month/Date
7970
+ return modifyDate(
7971
+ ret,
7972
+ date.getFullYear(),
7973
+ date.getMonth(),
7974
+ date.getDate()
7975
+ );
7976
+ };
7977
+
7978
+ const timeWithinRange = function(date, selectableRange, format) {
7979
+ const limitedDate = limitTimeRange(date, selectableRange, format);
7980
+ return limitedDate.getTime() === date.getTime();
7981
+ };
7982
+
7983
+ const changeYearMonthAndClampDate = function(date, year, month) {
7984
+ // clamp date to the number of days in `year`, `month`
7985
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
7986
+ const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
7987
+ return modifyDate(date, year, month, monthDate);
7988
+ };
7989
+
7990
+ const prevMonth = function(date) {
7991
+ const year = date.getFullYear();
7992
+ const month = date.getMonth();
7993
+ return month === 0
7994
+ ? changeYearMonthAndClampDate(date, year - 1, 11)
7995
+ : changeYearMonthAndClampDate(date, year, month - 1);
7996
+ };
7997
+
7998
+ const nextMonth = function(date) {
7999
+ const year = date.getFullYear();
8000
+ const month = date.getMonth();
8001
+ return month === 11
8002
+ ? changeYearMonthAndClampDate(date, year + 1, 0)
8003
+ : changeYearMonthAndClampDate(date, year, month + 1);
8004
+ };
8005
+
8006
+ const prevYear = function(date, amount = 1) {
8007
+ const year = date.getFullYear();
8008
+ const month = date.getMonth();
8009
+ return changeYearMonthAndClampDate(date, year - amount, month);
8010
+ };
8011
+
8012
+ const nextYear = function(date, amount = 1) {
8013
+ const year = date.getFullYear();
8014
+ const month = date.getMonth();
8015
+ return changeYearMonthAndClampDate(date, year + amount, month);
8016
+ };
8017
+
8018
+ const extractDateFormat = function(format) {
8019
+ return format
8020
+ .replace(/\W?m{1,2}|\W?ZZ/g, '')
8021
+ .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
8022
+ .trim();
8023
+ };
8024
+
8025
+ const extractTimeFormat = function(format) {
8026
+ return format
8027
+ .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
8028
+ .trim();
8029
+ };
8030
+
8031
+ const validateRangeInOneMonth = function(start, end) {
8032
+ return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
8033
+ };
8034
+
8002
8035
  /**
8003
8036
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
8004
8037
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
8005
8038
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
8006
8039
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
8007
8040
  * @returns {number} 工作日数量
8008
- */
8009
- var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
8010
- var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
8011
-
8012
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
8013
- throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
8014
- }
8015
-
8016
- var startDateObj = new Date(start_date);
8017
- var endDateObj = new Date(end_date);
8018
-
8019
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
8020
- throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
8021
- }
8022
-
8023
- if (startDateObj > endDateObj) {
8024
- throw new Error('Start date should be earlier than or equal to end date.');
8025
- }
8026
-
8027
- var workdays = 0;
8028
-
8029
- // Iterate through each day in the date range
8030
-
8031
- var _loop = function _loop(currentDate) {
8032
- // Check if the current day is a weekend (Saturday or Sunday)
8033
- var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
8034
-
8035
- // Check if the current day is a holiday
8036
- var isHoliday = holidays.some(function (holiday) {
8037
- var holidayDate = new Date(holiday);
8038
- return currentDate.toDateString() === holidayDate.toDateString();
8039
- });
8040
-
8041
- // If it's a workday (not a weekend or holiday), increment the workdays count
8042
- if (!isWeekend && !isHoliday) {
8043
- workdays++;
8044
- }
8045
- };
8046
-
8047
- for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
8048
- _loop(currentDate);
8049
- }
8050
-
8051
- return workdays;
8052
- };
8053
-
8041
+ */
8042
+ const calculateNetworkDays = function (start_date, end_date, holidays = []) {
8043
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
8044
+ throw new Error(
8045
+ "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
8046
+ );
8047
+ }
8048
+
8049
+ const startDateObj = new Date(start_date);
8050
+ const endDateObj = new Date(end_date);
8051
+
8052
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
8053
+ throw new Error(
8054
+ "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
8055
+ );
8056
+ }
8057
+
8058
+ if (startDateObj > endDateObj) {
8059
+ throw new Error('Start date should be earlier than or equal to end date.');
8060
+ }
8061
+
8062
+ let workdays = 0;
8063
+
8064
+ // Iterate through each day in the date range
8065
+ for (
8066
+ let currentDate = new Date(startDateObj);
8067
+ currentDate <= endDateObj;
8068
+ currentDate.setDate(currentDate.getDate() + 1)
8069
+ ) {
8070
+ // Check if the current day is a weekend (Saturday or Sunday)
8071
+ const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
8072
+
8073
+ // Check if the current day is a holiday
8074
+ const isHoliday = holidays.some((holiday) => {
8075
+ const holidayDate = new Date(holiday);
8076
+ return currentDate.toDateString() === holidayDate.toDateString();
8077
+ });
8078
+
8079
+ // If it's a workday (not a weekend or holiday), increment the workdays count
8080
+ if (!isWeekend && !isHoliday) {
8081
+ workdays++;
8082
+ }
8083
+ }
8084
+
8085
+ return workdays;
8086
+ };
8087
+
8054
8088
  /**
8055
8089
  * 日期加减天数
8056
8090
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
8057
8091
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
8058
8092
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
8059
- */
8060
- var dateAddDays = function dateAddDays(start_date, days) {
8061
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
8062
- 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.");
8063
- }
8064
-
8065
- var startDateObj = new Date(start_date);
8066
- if (isNaN(startDateObj.getTime())) {
8067
- throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
8068
- }
8069
-
8070
- var resultDateObj = new Date(startDateObj);
8071
- resultDateObj.setDate(resultDateObj.getDate() + days);
8072
-
8073
- var resultYear = resultDateObj.getFullYear();
8074
- var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
8075
- var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
8076
-
8077
- return resultYear + '-' + resultMonth + '-' + resultDay;
8078
- };
8079
-
8093
+ */
8094
+ const dateAddDays = function (start_date, days) {
8095
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
8096
+ throw new Error(
8097
+ "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
8098
+ );
8099
+ }
8100
+
8101
+ const startDateObj = new Date(start_date);
8102
+ if (isNaN(startDateObj.getTime())) {
8103
+ throw new Error(
8104
+ "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
8105
+ );
8106
+ }
8107
+
8108
+ const resultDateObj = new Date(startDateObj);
8109
+ resultDateObj.setDate(resultDateObj.getDate() + days);
8110
+
8111
+ const resultYear = resultDateObj.getFullYear();
8112
+ const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
8113
+ const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
8114
+
8115
+ return `${resultYear}-${resultMonth}-${resultDay}`;
8116
+ };
8117
+
8080
8118
  /**
8081
8119
  * 计算两个日期之间的差值
8082
8120
  * @date 2023年12月14日
@@ -8084,180 +8122,182 @@ var dateAddDays = function dateAddDays(start_date, days) {
8084
8122
  * @param {String} end_date - 结束日期字符串
8085
8123
  * @param {String} unit - 单位:year/month/day
8086
8124
  * @returns {Number} 差值
8087
- */
8088
- var dateDiff = function dateDiff(start_date, end_date) {
8089
- var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
8090
-
8091
- // Assuming date strings are in "YYYY-MM-DD" format
8092
- var startDate = new Date(start_date);
8093
- var endDate = new Date(end_date);
8094
-
8095
- // If the date is invalid, return 0
8096
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
8097
- return 0;
8098
- }
8099
-
8100
- if (unit === 'year') {
8101
- return endDate.getFullYear() - startDate.getFullYear();
8102
- } else if (unit === 'month') {
8103
- return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
8104
- } else {
8105
- // Default to day
8106
- var timeDifference = endDate - startDate;
8107
- // Calculate days (86400000 milliseconds per day)
8108
- return Math.floor(timeDifference / 86400000);
8109
- }
8110
- };
8111
-
8125
+ */
8126
+ const dateDiff = function (start_date, end_date, unit = 'day') {
8127
+ // Assuming date strings are in "YYYY-MM-DD" format
8128
+ var startDate = new Date(start_date);
8129
+ var endDate = new Date(end_date);
8130
+
8131
+ // If the date is invalid, return 0
8132
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
8133
+ return 0;
8134
+ }
8135
+
8136
+ if (unit === 'year') {
8137
+ return endDate.getFullYear() - startDate.getFullYear();
8138
+ } else if (unit === 'month') {
8139
+ return (
8140
+ (endDate.getFullYear() - startDate.getFullYear()) * 12 +
8141
+ (endDate.getMonth() - startDate.getMonth())
8142
+ );
8143
+ } else {
8144
+ // Default to day
8145
+ var timeDifference = endDate - startDate;
8146
+ // Calculate days (86400000 milliseconds per day)
8147
+ return Math.floor(timeDifference / 86400000);
8148
+ }
8149
+ };
8150
+
8112
8151
  /**
8113
8152
  * 获取月份中的日期
8114
8153
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
8115
8154
  * @returns {number} 月份中的日期(1-31)
8116
- */
8117
- var dayOfMonth = function dayOfMonth(date) {
8118
- if (typeof date !== 'string') {
8119
- throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
8120
- }
8121
-
8122
- var dateObj = new Date(date);
8123
- if (isNaN(dateObj.getTime())) {
8124
- throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
8125
- }
8126
-
8127
- return dateObj.getDate();
8128
- };
8129
-
8155
+ */
8156
+ const dayOfMonth = function (date) {
8157
+ if (typeof date !== 'string') {
8158
+ throw new Error(
8159
+ "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
8160
+ );
8161
+ }
8162
+
8163
+ const dateObj = new Date(date);
8164
+ if (isNaN(dateObj.getTime())) {
8165
+ throw new Error(
8166
+ "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
8167
+ );
8168
+ }
8169
+
8170
+ return dateObj.getDate();
8171
+ };
8172
+
8130
8173
  /**
8131
8174
  * 获取当前日期
8132
8175
  * @date 2022年5月7日
8133
8176
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
8134
8177
  * @returns {string} 当前日期的格式化字符串
8135
- */
8136
- var getCurrentDate = function getCurrentDate() {
8137
- var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
8138
-
8139
- return formatDate(new Date(), format);
8140
- };
8141
-
8178
+ */
8179
+ const getCurrentDate = function (format = 'YYYY-MM-DD') {
8180
+ return formatDate(new Date(), format);
8181
+ };
8182
+
8142
8183
  /**
8143
8184
  * 获取当前日期时间
8144
8185
  * @date 2022年5月7日
8145
8186
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
8146
8187
  * @returns {string} 当前日期时间的格式化字符串
8147
- */
8148
- var getCurrentDateTime = function getCurrentDateTime() {
8149
- var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
8150
-
8151
- return formatDate(new Date(), format);
8152
- };
8153
-
8188
+ */
8189
+ const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
8190
+ return formatDate(new Date(), format);
8191
+ };
8192
+
8154
8193
  /**
8155
8194
  * 获取小时
8156
8195
  * @date 2022年5月7日
8157
8196
  * @param {Date|string} [date] - 日期对象或日期字符串
8158
8197
  * @returns {number} 小时数(0-23)
8159
- */
8160
- var getHour = function getHour(date) {
8161
- if (!date) {
8162
- return new Date().getHours();
8163
- }
8164
- if (typeof date === 'string') {
8165
- date = new Date(date);
8166
- }
8167
- return date.getHours();
8168
- };
8169
-
8198
+ */
8199
+ const getHour = function (date) {
8200
+ if (!date) {
8201
+ return new Date().getHours();
8202
+ }
8203
+ if (typeof date === 'string') {
8204
+ date = new Date(date);
8205
+ }
8206
+ return date.getHours();
8207
+ };
8208
+
8170
8209
  /**
8171
8210
  * 获取分钟
8172
8211
  * @date 2022年5月7日
8173
8212
  * @param {Date|string} [date] - 日期对象或日期字符串
8174
8213
  * @returns {number} 分钟数(0-59)
8175
- */
8176
- var getMinute = function getMinute(date) {
8177
- if (!date) {
8178
- return new Date().getMinutes();
8179
- }
8180
- if (typeof date === 'string') {
8181
- date = new Date(date);
8182
- }
8183
- return date.getMinutes();
8184
- };
8185
-
8214
+ */
8215
+ const getMinute = function (date) {
8216
+ if (!date) {
8217
+ return new Date().getMinutes();
8218
+ }
8219
+ if (typeof date === 'string') {
8220
+ date = new Date(date);
8221
+ }
8222
+ return date.getMinutes();
8223
+ };
8224
+
8186
8225
  /**
8187
8226
  * 获取月份
8188
8227
  * @date 2022年5月7日
8189
8228
  * @param {Date|string} [date] - 日期对象或日期字符串
8190
8229
  * @returns {number} 月份数(1-12)
8191
- */
8192
- var getMonth = function getMonth(date) {
8193
- if (!date) {
8194
- return new Date().getMonth() + 1;
8195
- }
8196
- if (typeof date === 'string') {
8197
- date = new Date(date);
8198
- }
8199
- return date.getMonth() + 1;
8200
- };
8201
-
8230
+ */
8231
+ const getMonth = function (date) {
8232
+ if (!date) {
8233
+ return new Date().getMonth() + 1;
8234
+ }
8235
+ if (typeof date === 'string') {
8236
+ date = new Date(date);
8237
+ }
8238
+ return date.getMonth() + 1;
8239
+ };
8240
+
8202
8241
  /**
8203
8242
  * 获取秒
8204
8243
  * @date 2022年5月7日
8205
8244
  * @param {Date|string} [date] - 日期对象或日期字符串
8206
8245
  * @returns {number} 秒数(0-59)
8207
- */
8208
- var getSecond = function getSecond(date) {
8209
- if (!date) {
8210
- return new Date().getSeconds();
8211
- }
8212
- if (typeof date === 'string') {
8213
- date = new Date(date);
8214
- }
8215
- return date.getSeconds();
8216
- };
8217
-
8246
+ */
8247
+ const getSecond = function (date) {
8248
+ if (!date) {
8249
+ return new Date().getSeconds();
8250
+ }
8251
+ if (typeof date === 'string') {
8252
+ date = new Date(date);
8253
+ }
8254
+ return date.getSeconds();
8255
+ };
8256
+
8218
8257
  /**
8219
8258
  * 获取星期几
8220
8259
  * @date 2022年5月7日
8221
8260
  * @param {Date|string} [date] - 日期对象或日期字符串
8222
8261
  * @returns {number} 星期几(0-6,0表示星期日)
8223
- */
8224
- var getWeekday = function getWeekday(date) {
8225
- if (!date) {
8226
- return new Date().getDay();
8227
- }
8228
- if (typeof date === 'string') {
8229
- date = new Date(date);
8230
- }
8231
- return date.getDay();
8232
- };
8233
-
8262
+ */
8263
+ const getWeekday = function (date) {
8264
+ if (!date) {
8265
+ return new Date().getDay();
8266
+ }
8267
+ if (typeof date === 'string') {
8268
+ date = new Date(date);
8269
+ }
8270
+ return date.getDay();
8271
+ };
8272
+
8273
+
8234
8274
  /**
8235
8275
  * @desc 获取上午/下午/晚上
8236
8276
  * @author huangbo
8237
8277
  * @date 2022年5月7日
8238
8278
  * @param {String} [time] - 时间
8239
- **/
8240
- var timeCycle = function timeCycle(time) {
8241
- var hour = 0;
8242
- if (!time) {
8243
- hour = new Date().getHours();
8244
- } else if (typeof time === 'string') {
8245
- // 从时间字符串中提取小时
8246
- var match = time.match(/^(\d{1,2})/);
8247
- if (match) {
8248
- hour = parseInt(match[1], 10);
8249
- }
8250
- } else if (typeof time === 'number') {
8251
- hour = time;
8252
- }
8253
- // 判断时间段
8254
- if (hour >= 5 && hour < 12) {
8255
- return '上午';
8256
- } else if (hour >= 12 && hour < 18) {
8257
- return '下午';
8258
- } else {
8259
- return '晚上';
8260
- }
8279
+ **/
8280
+ const timeCycle = function (time) {
8281
+ let hour = 0;
8282
+ if (!time) {
8283
+ hour = new Date().getHours();
8284
+ } else if (typeof time === 'string') {
8285
+ // 从时间字符串中提取小时
8286
+ const match = time.match(/^(\d{1,2})/);
8287
+ if (match) {
8288
+ hour = parseInt(match[1], 10);
8289
+ }
8290
+ } else if (typeof time === 'number') {
8291
+ hour = time;
8292
+ }
8293
+ // 判断时间段
8294
+ if (hour >= 5 && hour < 12) {
8295
+ return '上午';
8296
+ } else if (hour >= 12 && hour < 18) {
8297
+ return '下午';
8298
+ } else {
8299
+ return '晚上';
8300
+ }
8261
8301
  };
8262
8302
 
8263
8303
  /***/ }),