qmwts 1.2.7 → 1.2.9

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  // https://juejin.cn/post/7098891689955164168
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  class LocalDate {
5
5
  constructor(date) {
6
6
  if (date instanceof Date)
package/dist/index.d.ts CHANGED
@@ -21,3 +21,4 @@ export { findTreeNodes } from './utils/array-utils2';
21
21
  export { prototype } from './utils/prototype-utils2';
22
22
  export { fileType } from './utils/file-utils2';
23
23
  export { clearValues } from './utils/object-utils2';
24
+ export { formatDateDiff, formatDateTime, parseDate } from './utils/date-utils';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clearValues = exports.fileType = exports.prototype = exports.findTreeNodes = exports.summation = exports.thousandths = exports.isNumber = exports.sha256Hex = exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.ParamBuilder = exports.PrototypeUtils = exports.ObjectUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.AxiosInstance = exports.FinanceUtils = exports.ArrayUtils = void 0;
3
+ exports.parseDate = exports.formatDateTime = exports.formatDateDiff = exports.clearValues = exports.fileType = exports.prototype = exports.findTreeNodes = exports.summation = exports.thousandths = exports.isNumber = exports.sha256Hex = exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.ParamBuilder = exports.PrototypeUtils = exports.ObjectUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.AxiosInstance = exports.FinanceUtils = exports.ArrayUtils = void 0;
4
4
  var array_utils_1 = require("./utils/array-utils");
5
5
  Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.default; } });
6
6
  var finance_utils_1 = require("./utils/finance-utils");
@@ -45,3 +45,7 @@ var file_utils2_1 = require("./utils/file-utils2");
45
45
  Object.defineProperty(exports, "fileType", { enumerable: true, get: function () { return file_utils2_1.fileType; } });
46
46
  var object_utils2_1 = require("./utils/object-utils2");
47
47
  Object.defineProperty(exports, "clearValues", { enumerable: true, get: function () { return object_utils2_1.clearValues; } });
48
+ var date_utils_1 = require("./utils/date-utils");
49
+ Object.defineProperty(exports, "formatDateDiff", { enumerable: true, get: function () { return date_utils_1.formatDateDiff; } });
50
+ Object.defineProperty(exports, "formatDateTime", { enumerable: true, get: function () { return date_utils_1.formatDateTime; } });
51
+ Object.defineProperty(exports, "parseDate", { enumerable: true, get: function () { return date_utils_1.parseDate; } });
@@ -0,0 +1,5 @@
1
+ import { DateTime } from 'luxon';
2
+ export declare const formatDateDiff: (date1: any, date2?: any) => string;
3
+ export declare const formatDateTime: (date: any) => string;
4
+ export declare const formatDate: (date: any) => string;
5
+ export declare const parseDate: (date: any) => DateTime | null;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDate = exports.formatDate = exports.formatDateTime = exports.formatDateDiff = void 0;
4
+ const luxon_1 = require("luxon");
5
+ const prototype_utils2_1 = require("./prototype-utils2");
6
+ const formatDateDiff = (date1, date2) => {
7
+ if (!date2)
8
+ date2 = luxon_1.DateTime.now().startOf('day');
9
+ date1 = (0, exports.parseDate)(date1);
10
+ if (!date1)
11
+ return '';
12
+ if (date1.diff(date2).as('days') > 0) // date1应该比date2小,如果不是则交换参数
13
+ [date1, date2] = [date2, date1]; // 交换参数
14
+ const { years, months, days } = date2.diff(date1, ['years', 'months', 'days']).toObject();
15
+ // 只收集不为 0 的部分
16
+ const parts = [];
17
+ if (years > 0)
18
+ parts.push(`${years}年`);
19
+ if (months > 0)
20
+ parts.push(`${months}个月`);
21
+ if (days > 0)
22
+ parts.push(`${days}天`);
23
+ // 拼接成最终字符串
24
+ return parts.join('');
25
+ };
26
+ exports.formatDateDiff = formatDateDiff;
27
+ const formatDateTime = (date) => {
28
+ date = (0, exports.parseDate)(date);
29
+ return date ? date.toFormat('yyyy-MM-dd HH:mm') : '';
30
+ };
31
+ exports.formatDateTime = formatDateTime;
32
+ const formatDate = (date) => {
33
+ date = (0, exports.parseDate)(date);
34
+ return date ? date.toFormat('yyyy-MM-dd') : '';
35
+ };
36
+ exports.formatDate = formatDate;
37
+ const parseDate = (date) => {
38
+ let luxonDate = void 0;
39
+ if (date instanceof luxon_1.DateTime)
40
+ luxonDate = date;
41
+ else if ((0, prototype_utils2_1.prototype)(date) === 'Number')
42
+ luxonDate = luxon_1.DateTime.fromMillis(date);
43
+ else if ((0, prototype_utils2_1.prototype)(date) === 'Date')
44
+ luxonDate = luxon_1.DateTime.fromJSDate(date);
45
+ else if ((0, prototype_utils2_1.prototype)(date) === 'String')
46
+ luxonDate = luxon_1.DateTime.fromISO(date);
47
+ if (luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.isValid)
48
+ return luxonDate;
49
+ return null;
50
+ };
51
+ exports.parseDate = parseDate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,6 +12,7 @@
12
12
  "license": "ISC",
13
13
  "devDependencies": {
14
14
  "@types/lodash-es": "^4.17.12",
15
+ "@types/luxon": "^3.7.1",
15
16
  "axios": "*",
16
17
  "typescript": "^5.9.2",
17
18
  "vitest": "^3.2.4"
@@ -21,7 +22,8 @@
21
22
  ],
22
23
  "dependencies": {
23
24
  "jszip": "^3.10.1",
24
- "lodash-es": "^4.17.22"
25
+ "lodash-es": "^4.17.22",
26
+ "luxon": "^3.7.2"
25
27
  },
26
28
  "peerDependencies": {
27
29
  "axios": "^1.12.2"