mirror of
https://github.com/supabase/supabase.git
synced 2026-05-12 04:16:08 +08:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import dayjs from 'dayjs'
|
|
import utc from 'dayjs/plugin/utc'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { formatTimestamp } from './Reports.utils'
|
|
|
|
dayjs.extend(utc)
|
|
|
|
describe('formatTimestamp', () => {
|
|
it('formats milliseconds timestamp correctly', () => {
|
|
const timestamp = 1640995200000 // 2022-01-01 00:00:00 UTC in milliseconds
|
|
const result = formatTimestamp(timestamp, { returnUtc: true })
|
|
expect(result).toBe('Jan 1, 12:00am')
|
|
})
|
|
|
|
it('formats microseconds timestamp correctly', () => {
|
|
const timestamp = 1640995200000000 // 2022-01-01 00:00:00 UTC in microseconds
|
|
const result = formatTimestamp(timestamp, { returnUtc: true })
|
|
expect(result).toBe('Jan 1, 12:00am')
|
|
})
|
|
|
|
it('formats seconds timestamp correctly', () => {
|
|
const timestamp = 1640995200 // 2022-01-01 00:00:00 UTC in seconds
|
|
const result = formatTimestamp(timestamp, { returnUtc: true })
|
|
expect(result).toBe('Jan 1, 12:00am')
|
|
})
|
|
|
|
it('handles string timestamp input', () => {
|
|
const timestamp = '1640995200000'
|
|
const result = formatTimestamp(timestamp, { returnUtc: true })
|
|
expect(result).toBe('Jan 1, 12:00am')
|
|
})
|
|
|
|
it('handles invalid string timestamp', () => {
|
|
const timestamp = 'invalid-timestamp'
|
|
const result = formatTimestamp(timestamp, { returnUtc: true })
|
|
expect(result).toBe('Invalid Date')
|
|
})
|
|
|
|
it('handles zero timestamp', () => {
|
|
const timestamp = 0
|
|
const result = formatTimestamp(timestamp, { returnUtc: true })
|
|
expect(result).toBe('Jan 1, 12:00am')
|
|
})
|
|
})
|