@fast-china/utils 1.0.35 → 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.
@@ -13301,65 +13301,42 @@ var FastUtils = (function(exports, vue) {
13301
13301
  if (typeof date2 === "string") {
13302
13302
  timestamp = new Date(date2).getTime();
13303
13303
  } else if (typeof date2 === "number") {
13304
- timestamp = date2;
13304
+ timestamp = date2.toString().length <= 10 ? date2 * 1e3 : date2;
13305
13305
  } else {
13306
13306
  timestamp = date2.getTime();
13307
13307
  }
13308
- if (timestamp < 1e12) {
13309
- timestamp *= 1e3;
13310
- }
13311
13308
  const minute = 1e3 * 60;
13312
13309
  const hour = minute * 60;
13313
13310
  const day = hour * 24;
13314
- const month = day * 30;
13315
13311
  const curTime = (/* @__PURE__ */ new Date()).getTime();
13316
13312
  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 `${Math.floor(monthC1 / 12)}年后`;
13330
- } else if (monthC1 >= 6) {
13331
- return "半年后";
13332
- } else if (monthC1 >= 1) {
13333
- return `${Math.floor(monthC1)}月后`;
13334
- } else if (weekC1 > 2) {
13335
- return "半月后";
13336
- } else if (weekC1 >= 1) {
13337
- return `${Math.floor(weekC1)}周后`;
13338
- } else if (dayC1 >= 1) {
13339
- return `${Math.floor(dayC1)}天后`;
13340
- } else if (hourC1 >= 1) {
13341
- return `${Math.floor(hourC1)}小时后`;
13342
- } else if (minC1 >= 1) {
13343
- return `${Math.floor(minC1)}分钟后`;
13344
- }
13345
- return "刚刚";
13346
- }
13347
- if (monthC > 12) {
13348
- return `${Math.floor(monthC / 12)}年前`;
13349
- } else if (monthC >= 6) {
13350
- return "半年前";
13351
- } else if (monthC >= 1) {
13352
- return `${Math.floor(monthC)}月前`;
13353
- } else if (weekC > 2) {
13354
- return "半月前";
13355
- } else if (weekC >= 1) {
13356
- return `${Math.floor(weekC)}周前`;
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}`;
13357
13334
  } else if (dayC >= 1) {
13358
- return `${Math.floor(dayC)}天前`;
13335
+ return `${Math.floor(dayC)}天${suffix}`;
13359
13336
  } else if (hourC >= 1) {
13360
- return `${Math.floor(hourC)}小时前`;
13337
+ return `${Math.floor(hourC)}小时${suffix}`;
13361
13338
  } else if (minC >= 1) {
13362
- return `${Math.floor(minC)}分钟前`;
13339
+ return `${Math.floor(minC)}分钟${suffix}`;
13363
13340
  }
13364
13341
  return "刚刚";
13365
13342
  },