aboutsummaryrefslogtreecommitdiffhomepage
path: root/template
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-03-01 21:24:58 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-03-01 21:43:04 -0800
commit0c7039de0e22587913e23988a4e2d6c06fd3bb34 (patch)
tree62a9372254418f7f87bd422583bb2fce903df939 /template
parentf110384f113002ad022c677ea138a0f77fad4a62 (diff)
Entries date should contains user timezone (API)
Diffstat (limited to 'template')
-rw-r--r--template/elapsed.go18
1 files changed, 4 insertions, 14 deletions
diff --git a/template/elapsed.go b/template/elapsed.go
index 273771d..5c5d98c 100644
--- a/template/elapsed.go
+++ b/template/elapsed.go
@@ -9,6 +9,7 @@ import (
"time"
"github.com/miniflux/miniflux/locale"
+ "github.com/miniflux/miniflux/timezone"
)
// Texts to be translated if necessary.
@@ -28,24 +29,13 @@ var (
// ElapsedTime returns in a human readable format the elapsed time
// since the given datetime.
-func elapsedTime(language *locale.Language, timezone string, t time.Time) string {
+func elapsedTime(language *locale.Language, tz string, t time.Time) string {
if t.IsZero() {
return language.Get(NotYet)
}
- 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)
- }
-
+ now := timezone.Now(tz)
+ t = timezone.Convert(tz, t)
if now.Before(t) {
return language.Get(NotYet)
}