Explorar o código

perf[utils]: refine parseTime function

Pan %!s(int64=6) %!d(string=hai) anos
pai
achega
1204075849
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      src/utils/index.js

+ 6 - 1
src/utils/index.js

@@ -11,7 +11,12 @@ export function parseTime(time, cFormat) {
11 11
   if (typeof time === 'object') {
12 12
     date = time
13 13
   } else {
14
-    if (('' + time).length === 10) time = parseInt(time) * 1000
14
+    if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
15
+      time = parseInt(time)
16
+    }
17
+    if ((typeof time === 'number') && (time.toString().length === 10)) {
18
+      time = time * 1000
19
+    }
15 20
     date = new Date(time)
16 21
   }
17 22
   const formatObj = {