diff --git a/duration/duration.go b/duration/duration.go
index b31d1398..fe84026c 100644
--- a/duration/duration.go
+++ b/duration/duration.go
@@ -28,11 +28,29 @@ var (
// ElapsedTime returns in a human readable format the elapsed time
// since the given datetime.
-func ElapsedTime(translator *locale.Language, t time.Time) string {
- if t.IsZero() || time.Now().Before(t) {
+func ElapsedTime(translator *locale.Language, timezone string, t time.Time) string {
+ if t.IsZero() {
return translator.Get(NotYet)
}
- diff := time.Since(t)
+
+ var now time.Time
+ loc, err := time.LoadLocation(timezone)
+ if err != nil {
+ now = time.Now()
+ } else {
+ now = time.Now().In(loc)
+
+ // The provided date is already converted to the user timezone by Postgres,
+ // but the timezone information is not set in the time struct.
+ // We cannot use time.In() because the date will be converted a second time.
+ t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), loc)
+ }
+
+ if now.Before(t) {
+ return translator.Get(NotYet)
+ }
+
+ diff := now.Sub(t)
// Duration in seconds
s := diff.Seconds()
// Duration in days
diff --git a/duration/duration_test.go b/duration/duration_test.go
index c9a46633..d1aae217 100644
--- a/duration/duration_test.go
+++ b/duration/duration_test.go
@@ -31,8 +31,8 @@ func TestElapsedTime(t *testing.T) {
{time.Now().Add(-time.Hour * 24 * 365 * 3), fmt.Sprintf(Years, 3)},
}
for i, tt := range dt {
- if out := ElapsedTime(&locale.Language{}, tt.in); out != tt.out {
- t.Errorf("%d. content mismatch for %v:exp=%q got=%q", i, tt.in, tt.out, out)
+ if out := ElapsedTime(&locale.Language{}, "Local", tt.in); out != tt.out {
+ t.Errorf(`%d. content mismatch for "%v": expected=%q got=%q`, i, tt.in, tt.out, out)
}
}
}
diff --git a/template/common.go b/template/common.go
index 2d284071..61661e8d 100644
--- a/template/common.go
+++ b/template/common.go
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
-// 2018-01-31 21:53:31.216689995 -0800 PST m=+0.040862073
+// 2018-02-04 14:28:15.225458631 -0800 PST m=+0.036040293
package template
@@ -27,32 +27,32 @@ var templateCommonMap = map[string]string{