diff options
| author | John R. Lenton <jlenton@gmail.com> | 2018-03-01 13:38:45 +0000 |
|---|---|---|
| committer | John R. Lenton <jlenton@gmail.com> | 2018-03-01 16:31:35 +0000 |
| commit | 9f1c2bfeea3cdc3c9065d3e33b4f4012fb5f843b (patch) | |
| tree | 0c07aaf0632796b079acdf382e3c27396cfc77b3 /timeutil | |
| parent | f8be7bfedaacca8e3c93cdc559851915bc6ef86f (diff) | |
timeutil: use i18n.NG for plurals; reoder switch
Diffstat (limited to 'timeutil')
| -rw-r--r-- | timeutil/human.go | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/timeutil/human.go b/timeutil/human.go index c157cb1088..a09b467c83 100644 --- a/timeutil/human.go +++ b/timeutil/human.go @@ -39,18 +39,31 @@ func Human(then time.Time) string { return humanTimeSince(then.Local(), time.Now().Local()) } +func ngd(d int) uint32 { + const max = 1000000 + if d > max { + return uint32((d % max) + max) + } + return uint32(d) +} + func humanTimeSince(then, now time.Time) string { d := int(math.Floor(noon(then).Sub(noon(now)).Hours() / 24)) switch { - case d > 1: - return fmt.Sprintf(then.Format(i18n.G("in %d days, at 15:04 MST")), d) case d < -1: - return fmt.Sprintf(then.Format(i18n.G("%d days ago, at 15:04 MST")), -d) - case d == 1: - return then.Format(i18n.G("tomorrow at 15:04 MST")) + // TRANSLATORS: %d will be at least 2 + return fmt.Sprintf(then.Format(i18n.NG("", "%d days ago, at 15:04 MST", ngd(d))), -d) case d == -1: return then.Format(i18n.G("yesterday at 15:04 MST")) - default: + case d == 0: return then.Format(i18n.G("today at 15:04 MST")) + case d == 1: + return then.Format(i18n.G("tomorrow at 15:04 MST")) + case d > 1: + // TRANSLATORS: %d will be at least 2 + return fmt.Sprintf(then.Format(i18n.NG("", "in %d days, at 15:04 MST", ngd(d))), 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!") } } |
