2023-08-03 07:53:58 +00:00
|
|
|
/**
|
|
|
|
* Asserts that a case in a switch statement is unreachable.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // Exhaustively checks `user.role` type ("admin" | "user") and will not compile
|
|
|
|
* // if a new role is added without adding a case to the switch statement.
|
|
|
|
* switch (user.role) {
|
|
|
|
* case "admin":
|
|
|
|
* break;
|
|
|
|
* case "user":
|
|
|
|
* break;
|
|
|
|
* default:
|
|
|
|
* assertUnreachable(user.role);
|
|
|
|
* }
|
|
|
|
*/
|
2023-09-16 03:24:51 +00:00
|
|
|
import { DateRange } from 'react-day-picker'
|
|
|
|
|
2023-08-03 07:53:58 +00:00
|
|
|
export function assertUnreachable(value: never): never {
|
2023-08-30 07:49:18 +00:00
|
|
|
throw new Error(`Unreachable case: ${value}`)
|
2023-08-03 07:53:58 +00:00
|
|
|
}
|
2023-08-16 11:22:22 +00:00
|
|
|
|
|
|
|
export const convertSecondsToTimerFormat = (seconds: number) => {
|
2023-08-30 07:49:18 +00:00
|
|
|
const minutes = Math.floor(seconds / 60)
|
|
|
|
const remainingSeconds = seconds % 60
|
|
|
|
return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`
|
|
|
|
}
|
|
|
|
|
2023-09-15 15:33:27 +00:00
|
|
|
export const formatNumberWithComa = (n: number): string => {
|
2023-09-15 15:18:53 +00:00
|
|
|
return n.toFixed(3).replace(/\./g, ',')
|
2023-08-30 07:49:18 +00:00
|
|
|
}
|
2023-09-16 03:24:51 +00:00
|
|
|
|
|
|
|
export const getMonthIndicesFromRange = (range: DateRange) => {
|
|
|
|
if (!range.from || !range.to) return [0, 11]
|
|
|
|
|
|
|
|
return [range.from.getMonth(), range.to.getMonth()]
|
|
|
|
}
|