Fix relativeTime API usage correctly
- Changed from incorrect f.relativeTime(number, unit, options) to correct f.relativeTime(date, now) - The function expects two Date objects, not a number and unit string - This properly eliminates the ENVIRONMENT_FALLBACK warning - Simplified the implementation to use next-intl's built-in formatting
This commit is contained in:
@@ -250,19 +250,17 @@ export default function PrayersPage() {
|
||||
|
||||
const formatTimestamp = (timestamp: Date) => {
|
||||
const currentTime = new Date()
|
||||
const diff = currentTime.getTime() - timestamp.getTime()
|
||||
const minutes = Math.floor(diff / (1000 * 60))
|
||||
const hours = Math.floor(minutes / 60)
|
||||
const days = Math.floor(hours / 24)
|
||||
|
||||
try {
|
||||
// Provide the 'now' parameter to avoid the warning
|
||||
if (days > 0) return f.relativeTime(-days, 'day', { now: currentTime })
|
||||
if (hours > 0) return f.relativeTime(-hours, 'hour', { now: currentTime })
|
||||
if (minutes > 0) return f.relativeTime(-minutes, 'minute', { now: currentTime })
|
||||
return f.relativeTime(0, 'second', { now: currentTime })
|
||||
// Use the correct API: relativeTime(date, now)
|
||||
return f.relativeTime(timestamp, currentTime)
|
||||
} catch (e) {
|
||||
// Fallback to simple formatting if relativeTime fails
|
||||
const diff = currentTime.getTime() - timestamp.getTime()
|
||||
const minutes = Math.floor(diff / (1000 * 60))
|
||||
const hours = Math.floor(minutes / 60)
|
||||
const days = Math.floor(hours / 24)
|
||||
|
||||
if (days > 0) return locale === 'ro' ? `acum ${days} ${days === 1 ? 'zi' : 'zile'}` : `${days} ${days === 1 ? 'day' : 'days'} ago`
|
||||
if (hours > 0) return locale === 'ro' ? `acum ${hours} ${hours === 1 ? 'oră' : 'ore'}` : `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`
|
||||
if (minutes > 0) return locale === 'ro' ? `acum ${minutes} ${minutes === 1 ? 'minut' : 'minute'}` : `${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`
|
||||
|
||||
Reference in New Issue
Block a user