@fe-free/tool 1.0.3 → 1.1.2
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.
- package/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/src/date.ts +31 -0
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/date.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { isNumber, isString } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
const maxDateSeconds = Math.abs(+dayjs().add(100, 'year') / 1000);
|
|
5
|
+
|
|
6
|
+
function getDayjs(text: string | number) {
|
|
7
|
+
// 字符串时间戳
|
|
8
|
+
if (isString(text) && /^\d+$/.test(text as string)) {
|
|
9
|
+
const timestamp = parseInt(text as string);
|
|
10
|
+
|
|
11
|
+
// 自动判断 s ms
|
|
12
|
+
if (timestamp > maxDateSeconds) {
|
|
13
|
+
return dayjs(timestamp);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return dayjs(timestamp * 1000);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (isNumber(text)) {
|
|
20
|
+
if (text > maxDateSeconds) {
|
|
21
|
+
return dayjs(text);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return dayjs(text * 1000);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 其他都可以 dayjs
|
|
28
|
+
return dayjs(text);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { getDayjs };
|
package/src/index.ts
CHANGED