From ad513a20e939691828ba415c9a565e8ff3daa95f Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 9 Mar 2016 19:53:30 -0500 Subject: #2302 Replace time.Time with Unix Timestamp (int64) --- models/login.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'models/login.go') diff --git a/models/login.go b/models/login.go index cbad646d1e..6ed4fefbdf 100644 --- a/models/login.go +++ b/models/login.go @@ -101,8 +101,20 @@ type LoginSource struct { Name string `xorm:"UNIQUE"` IsActived bool `xorm:"NOT NULL DEFAULT false"` Cfg core.Conversion `xorm:"TEXT"` - Created time.Time `xorm:"CREATED"` - Updated time.Time `xorm:"UPDATED"` + + Created time.Time `xorm:"-"` + CreatedUnix int64 + Updated time.Time `xorm:"-"` + UpdatedUnix int64 +} + +func (s *LoginSource) BeforeInsert() { + s.CreatedUnix = time.Now().UTC().Unix() + s.UpdatedUnix = s.CreatedUnix +} + +func (s *LoginSource) BeforeUpdate() { + s.UpdatedUnix = time.Now().UTC().Unix() } // Cell2Int64 converts a xorm.Cell type to int64, @@ -132,6 +144,15 @@ func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) { } } +func (s *LoginSource) AfterSet(colName string, _ xorm.Cell) { + switch colName { + case "created_unix": + s.Created = time.Unix(s.CreatedUnix, 0).Local() + case "updated_unix": + s.Updated = time.Unix(s.UpdatedUnix, 0).Local() + } +} + func (source *LoginSource) TypeName() string { return LoginNames[source.Type] } -- cgit v1.2.3