time.ts 502 B

1234567891011121314151617181920212223242526272829
  1. import { TFunction } from 'i18next'
  2. export function formatSecondsToHoursAndMinutes(
  3. t: TFunction,
  4. seconds: number
  5. ): string {
  6. const hrs = Math.floor(seconds / 3600)
  7. const mins = Math.floor((seconds % 3600) / 60)
  8. const parts = []
  9. if (hrs > 0) {
  10. parts.push(t('time_hour', { count: hrs }))
  11. }
  12. if (hrs > 0 && mins > 0) {
  13. parts.push(t('time_and'))
  14. }
  15. if (mins > 0) {
  16. parts.push(
  17. t('time_minute', {
  18. count: mins,
  19. })
  20. )
  21. }
  22. return parts.join(' ')
  23. }