@daysnap/utils 0.0.75 → 0.0.77

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.
@@ -0,0 +1 @@
1
+ export declare function formatDateToZN(v: string | number): string;
@@ -0,0 +1,31 @@
1
+ import { formatDateStr, formatDate, isNumber } from './index';
2
+ export function formatDateToZN(v) {
3
+ const timestamp = isNumber(v) ? v : new Date(formatDateStr(v + '')).getTime();
4
+ const now = Date.now(); // 获取当前时间的时间戳
5
+ const diff = now - timestamp; // 计算时间差
6
+ // 计算分钟、小时、天、周等
7
+ const seconds = Math.floor(diff / 1000);
8
+ const minutes = Math.floor(diff / (1000 * 60));
9
+ const hours = Math.floor(minutes / 60);
10
+ const days = Math.floor(hours / 24);
11
+ const weeks = Math.floor(days / 7);
12
+ console.log(diff, seconds, minutes, hours, days, weeks);
13
+ // 判断时间间隔,并返回相应的表示方式
14
+ if (weeks >= 4) {
15
+ return formatDate(timestamp, 'yyyy-MM-dd hh:mm');
16
+ }
17
+ else if (days >= 7) {
18
+ return `${weeks}周前`;
19
+ }
20
+ else if (hours >= 24) {
21
+ return `${days}天前`;
22
+ }
23
+ else if (minutes >= 60) {
24
+ return `${hours}小时前`;
25
+ }
26
+ else if (seconds >= 60) {
27
+ return `${minutes}分钟前`;
28
+ }
29
+ else
30
+ return '刚刚';
31
+ }
package/es/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from './filterIdCard';
24
24
  export * from './filterName';
25
25
  export * from './filterPhone';
26
26
  export * from './filterString';
27
+ export * from './formartDateToZN';
27
28
  export * from './formatAmount';
28
29
  export * from './formatDate';
29
30
  export * from './formatDateStr';
package/es/index.js CHANGED
@@ -25,6 +25,7 @@ export * from './filterIdCard';
25
25
  export * from './filterName';
26
26
  export * from './filterPhone';
27
27
  export * from './filterString';
28
+ export * from './formartDateToZN';
28
29
  export * from './formatAmount';
29
30
  export * from './formatDate';
30
31
  export * from './formatDateStr';
@@ -0,0 +1 @@
1
+ export declare function formatDateToZN(v: string | number): string;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDateToZN = void 0;
4
+ const index_1 = require("./index");
5
+ function formatDateToZN(v) {
6
+ const timestamp = (0, index_1.isNumber)(v) ? v : new Date((0, index_1.formatDateStr)(v + '')).getTime();
7
+ const now = Date.now(); // 获取当前时间的时间戳
8
+ const diff = now - timestamp; // 计算时间差
9
+ // 计算分钟、小时、天、周等
10
+ const seconds = Math.floor(diff / 1000);
11
+ const minutes = Math.floor(diff / (1000 * 60));
12
+ const hours = Math.floor(minutes / 60);
13
+ const days = Math.floor(hours / 24);
14
+ const weeks = Math.floor(days / 7);
15
+ console.log(diff, seconds, minutes, hours, days, weeks);
16
+ // 判断时间间隔,并返回相应的表示方式
17
+ if (weeks >= 4) {
18
+ return (0, index_1.formatDate)(timestamp, 'yyyy-MM-dd hh:mm');
19
+ }
20
+ else if (days >= 7) {
21
+ return `${weeks}周前`;
22
+ }
23
+ else if (hours >= 24) {
24
+ return `${days}天前`;
25
+ }
26
+ else if (minutes >= 60) {
27
+ return `${hours}小时前`;
28
+ }
29
+ else if (seconds >= 60) {
30
+ return `${minutes}分钟前`;
31
+ }
32
+ else
33
+ return '刚刚';
34
+ }
35
+ exports.formatDateToZN = formatDateToZN;
package/lib/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from './filterIdCard';
24
24
  export * from './filterName';
25
25
  export * from './filterPhone';
26
26
  export * from './filterString';
27
+ export * from './formartDateToZN';
27
28
  export * from './formatAmount';
28
29
  export * from './formatDate';
29
30
  export * from './formatDateStr';
package/lib/index.js CHANGED
@@ -41,6 +41,7 @@ __exportStar(require("./filterIdCard"), exports);
41
41
  __exportStar(require("./filterName"), exports);
42
42
  __exportStar(require("./filterPhone"), exports);
43
43
  __exportStar(require("./filterString"), exports);
44
+ __exportStar(require("./formartDateToZN"), exports);
44
45
  __exportStar(require("./formatAmount"), exports);
45
46
  __exportStar(require("./formatDate"), exports);
46
47
  __exportStar(require("./formatDateStr"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",