Merge pull request #915 from frappe/mergify/bp/main/pr-913

fix: future date is not captured in pretty date (backport #913)
This commit is contained in:
Shariq Ansari 2025-06-09 16:52:51 +05:30 committed by GitHub
commit 74f305490c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -86,11 +86,32 @@ export function prettyDate(date, mini = false) {
let dayDiff = Math.floor(diff / 86400)
if (isNaN(dayDiff) || dayDiff < 0) return ''
if (isNaN(dayDiff)) return ''
if (mini) {
// Return short format of time difference
if (dayDiff == 0) {
if (dayDiff < 0) {
if (Math.abs(dayDiff) < 1) {
if (diff < 60) {
return __('now')
} else if (diff < 3600) {
return __('in {0} m', [Math.floor(diff / 60)])
} else if (diff < 86400) {
return __('in {0} h', [Math.floor(diff / 3600)])
}
}
if (Math.abs(dayDiff) == 1) {
return __('tomorrow')
} else if (Math.abs(dayDiff) < 7) {
return __('in {0} d', [Math.abs(dayDiff)])
} else if (Math.abs(dayDiff) < 31) {
return __('in {0} w', [Math.floor(Math.abs(dayDiff) / 7)])
} else if (Math.abs(dayDiff) < 365) {
return __('in {0} M', [Math.floor(Math.abs(dayDiff) / 30)])
} else {
return __('in {0} y', [Math.floor(Math.abs(dayDiff) / 365)])
}
} else if (dayDiff == 0) {
if (diff < 60) {
return __('now')
} else if (diff < 3600) {
@ -111,7 +132,34 @@ export function prettyDate(date, mini = false) {
}
} else {
// Return long format of time difference
if (dayDiff == 0) {
if (dayDiff < 0) {
if (Math.abs(dayDiff) < 1) {
if (diff < 60) {
return __('just now')
} else if (diff < 120) {
return __('in 1 minute')
} else if (diff < 3600) {
return __('in {0} minutes', [Math.floor(diff / 60)])
} else if (diff < 7200) {
return __('in 1 hour')
} else if (diff < 86400) {
return __('in {0} hours', [Math.floor(diff / 3600)])
}
}
if (Math.abs(dayDiff) == 1) {
return __('tomorrow')
} else if (Math.abs(dayDiff) < 7) {
return __('in {0} days', [Math.abs(dayDiff)])
} else if (Math.abs(dayDiff) < 31) {
return __('in {0} weeks', [Math.floor(Math.abs(dayDiff) / 7)])
} else if (Math.abs(dayDiff) < 365) {
return __('in {0} months', [Math.floor(Math.abs(dayDiff) / 30)])
} else if (Math.abs(dayDiff) < 730) {
return __('in 1 year')
} else {
return __('in {0} years', [Math.floor(Math.abs(dayDiff) / 365)])
}
} else if (dayDiff == 0) {
if (diff < 60) {
return __('just now')
} else if (diff < 120) {