mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Use shared ceiling time value for writefull paywall countdowns GitOrigin-RevId: de77dd274028db58d23044e8aaea9cf0ad570037
41 lines
807 B
TypeScript
41 lines
807 B
TypeScript
import { TFunction } from 'i18next'
|
|
|
|
export function secondsToHoursAndMinutes(seconds: number): {
|
|
hours: number
|
|
minutes: number
|
|
} {
|
|
// round up: the caller tells the user how long to wait, so never understate
|
|
const totalMinutes = Math.ceil(seconds / 60)
|
|
return {
|
|
hours: Math.floor(totalMinutes / 60),
|
|
minutes: totalMinutes % 60,
|
|
}
|
|
}
|
|
|
|
export function formatSecondsToHoursAndMinutes(
|
|
t: TFunction,
|
|
seconds: number
|
|
): string {
|
|
const { hours, minutes } = secondsToHoursAndMinutes(seconds)
|
|
|
|
const parts = []
|
|
|
|
if (hours > 0) {
|
|
parts.push(t('time_hour', { count: hours }))
|
|
}
|
|
|
|
if (hours > 0 && minutes > 0) {
|
|
parts.push(t('time_and'))
|
|
}
|
|
|
|
if (minutes > 0) {
|
|
parts.push(
|
|
t('time_minute', {
|
|
count: minutes,
|
|
})
|
|
)
|
|
}
|
|
|
|
return parts.join(' ')
|
|
}
|