mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-14 18:05:55 +08:00
[offers][fix] fix date display for single value (#481)
This commit is contained in:
@ -9,19 +9,23 @@ export function timeSinceNow(date: Date | number | string) {
|
||||
let interval = seconds / 31536000;
|
||||
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} years`;
|
||||
const time: number = Math.floor(interval);
|
||||
return time === 1 ? `${time} year` : `${time} years`;
|
||||
}
|
||||
interval = seconds / 2592000;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} months`;
|
||||
const time: number = Math.floor(interval);
|
||||
return time === 1 ? `${time} month` : `${time} months`;
|
||||
}
|
||||
interval = seconds / 86400;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} days`;
|
||||
const time: number = Math.floor(interval);
|
||||
return time === 1 ? `${time} day` : `${time} days`;
|
||||
}
|
||||
interval = seconds / 3600;
|
||||
if (interval > 1) {
|
||||
return `${Math.floor(interval)} hours`;
|
||||
const time: number = Math.floor(interval);
|
||||
return time === 1 ? `${time} hour` : `${time} hours`;
|
||||
}
|
||||
interval = seconds / 60;
|
||||
if (interval > 1) {
|
||||
|
Reference in New Issue
Block a user