mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 18:00:20 -04:00
180ce515f6
* **Chores** * Updated internal module import paths across hook files to use standardized path aliases for improved code consistency and maintainability.
26 lines
670 B
TypeScript
26 lines
670 B
TypeScript
import { useMemo } from 'react'
|
|
|
|
import {
|
|
isUnixMicro,
|
|
unixMicroToIsoTimestamp,
|
|
} from '@/components/interfaces/Settings/Logs/Logs.utils'
|
|
|
|
/**
|
|
* Convenience hook for converting timeseries timestamp from unix microsecond to iso
|
|
*
|
|
* memoized
|
|
*/
|
|
const useTimeseriesUnixToIso = (data: any[], timestampKey: string) => {
|
|
return useMemo(() => {
|
|
// check if need to convert or not
|
|
if (data.length === 0) return data
|
|
if (!isUnixMicro(data[0][timestampKey])) return data
|
|
|
|
return data?.map((d) => {
|
|
d[timestampKey] = unixMicroToIsoTimestamp(d[timestampKey])
|
|
return d
|
|
})
|
|
}, [JSON.stringify(data)])
|
|
}
|
|
export default useTimeseriesUnixToIso
|