Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(timeutil): remove unreachable panic() call #455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions internals/timeutil/human.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ func delta(then, now time.Time) int {
func humanTimeSince(then, now time.Time, cutoffDays int) string {
d := delta(then, now)
switch {
case d < -cutoffDays || d > cutoffDays:
return then.Format("2006-01-02")
case d < -1:
case d < -1 && d >= -cutoffDays:
return fmt.Sprintf(then.Format("%d days ago, at 15:04 MST"), -d)
case d == -1:
return then.Format("yesterday at 15:04 MST")
case d == 0:
return then.Format("today at 15:04 MST")
case d == 1:
return then.Format("tomorrow at 15:04 MST")
case d > 1:
case d > 1 && d <= cutoffDays:
return fmt.Sprintf(then.Format("in %d days, at 15:04 MST"), d)
default:
// the following message is brought to you by Joel Armando, the self-described awesome and sexy mathematician.
panic("you have broken the law of trichotomy! ℤ is no longer totally ordered! chaos ensues!")
return then.Format("2006-01-02")
}
}
Loading