perf: refine
This commit is contained in:
parent
d54cd25de2
commit
81fefb313d
|
@ -17,11 +17,17 @@ export function parseTime(time, cFormat) {
|
||||||
if (typeof time === 'object') {
|
if (typeof time === 'object') {
|
||||||
date = time
|
date = time
|
||||||
} else {
|
} else {
|
||||||
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
|
if ((typeof time === 'string')) {
|
||||||
time = parseInt(time)
|
if ((/^[0-9]+$/.test(time))) {
|
||||||
} else if (typeof time === 'string') {
|
// support "1548221490638"
|
||||||
time = time.replace(new RegExp(/-/gm), '/');
|
time = parseInt(time)
|
||||||
|
} else {
|
||||||
|
// support safari
|
||||||
|
// https://stackoverflow.com/questions/4310953/invalid-date-in-safari
|
||||||
|
time = time.replace(new RegExp(/-/gm), '/')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((typeof time === 'number') && (time.toString().length === 10)) {
|
if ((typeof time === 'number') && (time.toString().length === 10)) {
|
||||||
time = time * 1000
|
time = time * 1000
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,11 @@ describe('Utils:parseTime', () => {
|
||||||
it('timestamp', () => {
|
it('timestamp', () => {
|
||||||
expect(parseTime(d)).toBe('2018-07-13 17:54:01')
|
expect(parseTime(d)).toBe('2018-07-13 17:54:01')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('timestamp string', () => {
|
||||||
|
expect(parseTime((d + ''))).toBe('2018-07-13 17:54:01')
|
||||||
|
})
|
||||||
|
|
||||||
it('ten digits timestamp', () => {
|
it('ten digits timestamp', () => {
|
||||||
expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
|
expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue