Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / docs-shared / lib / convertTimestampToMilliseconds.ts
blob9e8ae203926ec58f399850b5c4460ca5949d979c
1 const MicrosecondsInAMillisecond = 1000
2 const MillisecondsInASecond = 1000
4 enum TimestampDigits {
5   Seconds = 10,
6   Milliseconds = 13,
7   Microseconds = 16,
10 export function convertTimestampToMilliseconds(timestamp: number): number {
11   const digits = String(timestamp).length
12   switch (digits) {
13     case TimestampDigits.Seconds:
14       return timestamp * MillisecondsInASecond
15     case TimestampDigits.Milliseconds:
16       return timestamp
17     case TimestampDigits.Microseconds:
18       return Math.floor(timestamp / MicrosecondsInAMillisecond)
20     default:
21       throw Error(`Unhandled timestamp precision: ${timestamp}`)
22   }