From 609c57332e73aa753d9c198cad3595cde501c1ff Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 4 Mar 2018 17:04:31 -0800 Subject: Show last login and session creation date in current timezone --- model/user.go | 16 ++++++++++++++++ model/user_session.go | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'model') diff --git a/model/user.go b/model/user.go index aa1156d..d2283f1 100644 --- a/model/user.go +++ b/model/user.go @@ -7,6 +7,8 @@ package model import ( "errors" "time" + + "github.com/miniflux/miniflux/timezone" ) // User represents a user in the system. @@ -99,5 +101,19 @@ func (u *User) Merge(override *User) { } } +// UseTimezone converts last login date to the given timezone. +func (u *User) UseTimezone(tz string) { + if u.LastLoginAt != nil { + *u.LastLoginAt = timezone.Convert(tz, *u.LastLoginAt) + } +} + // Users represents a list of users. type Users []*User + +// UseTimezone converts last login timestamp of all users to the given timezone. +func (u Users) UseTimezone(tz string) { + for _, user := range u { + user.UseTimezone(tz) + } +} diff --git a/model/user_session.go b/model/user_session.go index 7112159..51b2543 100644 --- a/model/user_session.go +++ b/model/user_session.go @@ -4,8 +4,12 @@ package model -import "time" -import "fmt" +import ( + "fmt" + "time" + + "github.com/miniflux/miniflux/timezone" +) // UserSession represents a user session in the system. type UserSession struct { @@ -17,9 +21,21 @@ type UserSession struct { IP string } -func (s *UserSession) String() string { - return fmt.Sprintf(`ID="%d", UserID="%d", IP="%s", Token="%s"`, s.ID, s.UserID, s.IP, s.Token) +func (u *UserSession) String() string { + return fmt.Sprintf(`ID="%d", UserID="%d", IP="%s", Token="%s"`, u.ID, u.UserID, u.IP, u.Token) +} + +// UseTimezone converts creation date to the given timezone. +func (u *UserSession) UseTimezone(tz string) { + u.CreatedAt = timezone.Convert(tz, u.CreatedAt) } // UserSessions represents a list of sessions. type UserSessions []*UserSession + +// UseTimezone converts creation date of all sessions to the given timezone. +func (u UserSessions) UseTimezone(tz string) { + for _, session := range u { + session.UseTimezone(tz) + } +} -- cgit v1.2.3