Created
December 23, 2022 11:49
-
-
Save abigmiu/072e8392f22f1c1cc51ede7cbeb04fb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function timeStampTo13(value: number) { | |
if (`${value}`.length === 10) { | |
return value * 1000; | |
} | |
return value; | |
} | |
export function timeStampTo10(value: number) { | |
if (`${value}`.length === 13) { | |
return Math.floor(value / 1000); | |
} | |
return value; | |
} | |
export function transformTimeStampData<T extends Record<string, any>, K extends keyof T>( | |
data: Array<T> | T, | |
keys: Array<K>, | |
isToServer = true, | |
) { | |
const ary = Array.isArray(data) ? data : [data]; | |
ary.forEach((item) => { | |
keys.forEach((key) => { | |
if (isToServer) { | |
(item[key] as number) = timeStampTo10(item[key] as number); | |
} else { | |
(item[key] as number) = timeStampTo13(item[key] as number); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment