@fast-china/utils 1.0.34 → 1.0.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.
@@ -13294,77 +13294,51 @@ var FastUtils = (function(exports, vue) {
13294
13294
  * 时间处理翻译
13295
13295
  */
13296
13296
  dateTimeFix(date2) {
13297
- if (date2 !== null && date2 !== void 0 && date2) {
13298
- if (typeof date2 === "string") {
13299
- date2 = new Date(date2);
13300
- }
13301
- let timestamp = date2.getTime();
13302
- if (timestamp.toString().length < 13) {
13303
- const arrTimestamp = timestamp.toString().split("");
13304
- for (let start = 0; start < 13; start++) {
13305
- if (!arrTimestamp[start]) {
13306
- arrTimestamp[start] = "0";
13307
- }
13308
- }
13309
- timestamp = parseInt(arrTimestamp.join(""));
13310
- }
13311
- const minute = 1e3 * 60;
13312
- const hour = minute * 60;
13313
- const day = hour * 24;
13314
- const month = day * 30;
13315
- const curTime = (/* @__PURE__ */ new Date()).getTime();
13316
- const diffValue = curTime - timestamp;
13317
- const monthC = diffValue / month;
13318
- const weekC = diffValue / (7 * day);
13319
- const dayC = diffValue / day;
13320
- const hourC = diffValue / hour;
13321
- const minC = diffValue / minute;
13322
- if (diffValue < 0) {
13323
- const monthC1 = Math.abs(monthC);
13324
- const weekC1 = Math.abs(weekC);
13325
- const dayC1 = Math.abs(dayC);
13326
- const hourC1 = Math.abs(hourC);
13327
- const minC1 = Math.abs(minC);
13328
- if (monthC1 > 12) {
13329
- return `${parseInt(`${monthC1 / 12}`)}年后`;
13330
- } else if (monthC1 >= 6) {
13331
- return "半年后";
13332
- } else if (monthC1 >= 1) {
13333
- return `${parseInt(`${monthC1}`)}月后`;
13334
- } else if (weekC1 > 2) {
13335
- return "半月后";
13336
- } else if (weekC1 >= 1) {
13337
- return `${parseInt(`${weekC1}`)}周后`;
13338
- } else if (dayC1 >= 1) {
13339
- return `${parseInt(`${dayC1}`)}天后`;
13340
- } else if (hourC1 >= 1) {
13341
- return `${parseInt(`${hourC1}`)}小时后`;
13342
- } else if (minC1 >= 1) {
13343
- return `${parseInt(`${minC1}`)}分钟后`;
13344
- }
13345
- return "刚刚";
13346
- }
13347
- if (monthC > 12) {
13348
- return `${parseInt(`${monthC / 12}`)}年前`;
13349
- } else if (monthC >= 6) {
13350
- return "半年前";
13351
- } else if (monthC >= 1) {
13352
- return `${parseInt(`${monthC}`)}月前`;
13353
- } else if (weekC > 2) {
13354
- return "半月前";
13355
- } else if (weekC >= 1) {
13356
- return `${parseInt(`${weekC}`)}周前`;
13357
- } else if (dayC >= 1) {
13358
- return `${parseInt(`${dayC}`)}天前`;
13359
- } else if (hourC >= 1) {
13360
- return `${parseInt(`${hourC}`)}小时前`;
13361
- } else if (minC >= 1) {
13362
- return `${parseInt(`${minC}`)}分钟前`;
13363
- }
13364
- return "刚刚";
13365
- } else {
13297
+ if (isNil(date2)) {
13366
13298
  return "";
13367
13299
  }
13300
+ let timestamp;
13301
+ if (typeof date2 === "string") {
13302
+ timestamp = new Date(date2).getTime();
13303
+ } else if (typeof date2 === "number") {
13304
+ timestamp = date2.toString().length <= 10 ? date2 * 1e3 : date2;
13305
+ } else {
13306
+ timestamp = date2.getTime();
13307
+ }
13308
+ const minute = 1e3 * 60;
13309
+ const hour = minute * 60;
13310
+ const day = hour * 24;
13311
+ const curTime = (/* @__PURE__ */ new Date()).getTime();
13312
+ const diffValue = curTime - timestamp;
13313
+ const minC = Math.abs(diffValue) / minute;
13314
+ const hourC = Math.abs(diffValue) / hour;
13315
+ const dayC = Math.abs(diffValue) / day;
13316
+ const curDate = new Date(curTime);
13317
+ const targetDate = new Date(timestamp);
13318
+ const yearDiff = curDate.getFullYear() - targetDate.getFullYear();
13319
+ const monthDiff = curDate.getMonth() - targetDate.getMonth();
13320
+ const totalMonthDiff = yearDiff * 12 + monthDiff;
13321
+ const suffix = diffValue < 0 ? "后" : "前";
13322
+ if (Math.abs(totalMonthDiff) >= 12) {
13323
+ const years = Math.floor(Math.abs(totalMonthDiff) / 12);
13324
+ return `${years}年${suffix}`;
13325
+ } else if (Math.abs(totalMonthDiff) >= 6) {
13326
+ return `半年${suffix}`;
13327
+ } else if (Math.abs(totalMonthDiff) >= 1) {
13328
+ return `${Math.abs(totalMonthDiff)}月${suffix}`;
13329
+ } else if (dayC >= 15) {
13330
+ return `半月${suffix}`;
13331
+ } else if (dayC >= 7) {
13332
+ const weeks = Math.floor(dayC / 7);
13333
+ return `${weeks}周${suffix}`;
13334
+ } else if (dayC >= 1) {
13335
+ return `${Math.floor(dayC)}天${suffix}`;
13336
+ } else if (hourC >= 1) {
13337
+ return `${Math.floor(hourC)}小时${suffix}`;
13338
+ } else if (minC >= 1) {
13339
+ return `${Math.floor(minC)}分钟${suffix}`;
13340
+ }
13341
+ return "刚刚";
13368
13342
  },
13369
13343
  /**
13370
13344
  * 获取默认时间