File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,17 @@ export function parseTime(time, cFormat) {
1717 if ( typeof time === 'object' ) {
1818 date = time
1919 } else {
20- if ( ( typeof time === 'string' ) && ( / ^ [ 0 - 9 ] + $ / . test ( time ) ) ) {
21- time = parseInt ( time )
20+ if ( ( typeof time === 'string' ) ) {
21+ if ( ( / ^ [ 0 - 9 ] + $ / . test ( time ) ) ) {
22+ // support "1548221490638"
23+ time = parseInt ( time )
24+ } else {
25+ // support safari
26+ // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
27+ time = time . replace ( new RegExp ( / - / gm) , '/' )
28+ }
2229 }
30+
2331 if ( ( typeof time === 'number' ) && ( time . toString ( ) . length === 10 ) ) {
2432 time = time * 1000
2533 }
Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ describe('Utils:parseTime', () => {
44 it ( 'timestamp' , ( ) => {
55 expect ( parseTime ( d ) ) . toBe ( '2018-07-13 17:54:01' )
66 } )
7+
8+ it ( 'timestamp string' , ( ) => {
9+ expect ( parseTime ( ( d + '' ) ) ) . toBe ( '2018-07-13 17:54:01' )
10+ } )
11+
712 it ( 'ten digits timestamp' , ( ) => {
813 expect ( parseTime ( ( d / 1000 ) . toFixed ( 0 ) ) ) . toBe ( '2018-07-13 17:54:01' )
914 } )
You can’t perform that action at this time.
0 commit comments