mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
extend RelativeTime function
This commit is contained in:
@@ -224,8 +224,35 @@ func RelativeTime(date time.Time) string {
|
||||
return fmt.Sprintf("%d days ago", days)
|
||||
}
|
||||
|
||||
// Older than a week
|
||||
return date.Format("2 January 2006 3:04 PM")
|
||||
// Within last month
|
||||
if duration < 31*24*time.Hour {
|
||||
weeks := int(duration.Hours() / (24 * 7))
|
||||
if weeks == 1 {
|
||||
return "1 week ago"
|
||||
}
|
||||
return fmt.Sprintf("%d weeks ago", weeks)
|
||||
}
|
||||
|
||||
// Check months difference
|
||||
months := int(now.Month() - date.Month())
|
||||
yearDiff := now.Year() - date.Year()
|
||||
if yearDiff > 0 {
|
||||
months += yearDiff * 12
|
||||
}
|
||||
|
||||
if months < 12 {
|
||||
if months == 1 {
|
||||
return "1 month ago"
|
||||
}
|
||||
return fmt.Sprintf("%d months ago", months)
|
||||
}
|
||||
|
||||
// Years
|
||||
years := yearDiff
|
||||
if years == 1 {
|
||||
return "1 year ago"
|
||||
}
|
||||
return fmt.Sprintf("%d years ago", years)
|
||||
}
|
||||
|
||||
// CreatePaginator generates pagination data based on the current page and maximum number of pages.
|
||||
|
||||
Reference in New Issue
Block a user