lyb-js 1.6.18 → 1.6.19
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.
|
@@ -12,7 +12,9 @@ export declare class LibJsClassObservable<T extends Record<string, any>> {
|
|
|
12
12
|
* @param initialData 监听的数据
|
|
13
13
|
*/
|
|
14
14
|
constructor(initialData: T);
|
|
15
|
-
/** @description
|
|
15
|
+
/** @description 获取所有数据 */
|
|
16
|
+
getData(): T;
|
|
17
|
+
/** @description 获取值
|
|
16
18
|
* @param key 要获取的键
|
|
17
19
|
* @returns 对应的值
|
|
18
20
|
*/
|
|
@@ -13,7 +13,11 @@ export class LibJsClassObservable {
|
|
|
13
13
|
this.index = 0;
|
|
14
14
|
this.data = Object.assign({}, initialData);
|
|
15
15
|
}
|
|
16
|
-
/** @description
|
|
16
|
+
/** @description 获取所有数据 */
|
|
17
|
+
getData() {
|
|
18
|
+
return this.data;
|
|
19
|
+
}
|
|
20
|
+
/** @description 获取值
|
|
17
21
|
* @param key 要获取的键
|
|
18
22
|
* @returns 对应的值
|
|
19
23
|
*/
|
package/Time/LibJsTimeAgo.d.ts
CHANGED
package/Time/LibJsTimeAgo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @description
|
|
1
|
+
/** @description 时间差计算(支持未来时间:多久后)
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
3
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
|
|
4
4
|
*/
|
|
@@ -11,12 +11,13 @@ export const libJsTimeAgo = (timestamp) => {
|
|
|
11
11
|
{ unit: "小时", milliseconds: 60 * 60 * 1000 },
|
|
12
12
|
{ unit: "分钟", milliseconds: 60 * 1000 },
|
|
13
13
|
];
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
const diff = timestamp - now;
|
|
16
|
+
const absDiff = Math.abs(diff);
|
|
16
17
|
for (const { unit, milliseconds } of timeUnits) {
|
|
17
|
-
if (
|
|
18
|
-
const count = Math.floor(
|
|
19
|
-
return `${count} ${unit}前`;
|
|
18
|
+
if (absDiff >= milliseconds) {
|
|
19
|
+
const count = Math.floor(absDiff / milliseconds);
|
|
20
|
+
return diff > 0 ? `${count} ${unit}后` : `${count} ${unit}前`;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
return "刚刚";
|