fixed up handling of timestamps for database and profile display

This commit is contained in:
2025-10-13 15:54:04 -06:00
parent 55f5cc5eca
commit ed10c83b01
4 changed files with 18 additions and 7 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ site:
Text of this agreement is TBD.
database:
driver: "mysql"
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=Local"
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=UTC"
defaults:
language: "en-US"
timezone: "America/Denver"
+2 -2
View File
@@ -120,7 +120,7 @@ func (ci *ContactInfo) Save() (bool, error) {
_, err := amdb.NamedExec(`UPDATE contacts SET given_name = :given_name, family_name = :family_name, middle_init = :middle_init,
prefix = :prefix, suffix = :suffix, company = :company, addr1 = :addr1, addr2 = :addr2, locality = :locality, region = :region,
pcode = :pcode, country = :country, phone = :phone, fax = :fax, mobile = :mobile, email = :email, pvt_addr = :pvt_addr,
pvt_phone = :pvt_phone, pvt_fax = :pvt_fax, pvt_email = :pvt_email, photo_url = :photo_url, url = :url, lastupdate = UTC_TIMESTAMP()
pvt_phone = :pvt_phone, pvt_fax = :pvt_fax, pvt_email = :pvt_email, photo_url = :photo_url, url = :url, lastupdate = NOW()
WHERE contactid = :contactid`, ci)
if err != nil {
return false, err
@@ -132,7 +132,7 @@ func (ci *ContactInfo) Save() (bool, error) {
pvt_email, owner_uid, owner_commid, photo_url, url, lastupdate)
VALUES (:given_name, :family_name, :middle_init, :prefix, :suffix, :company, :addr1, :addr2, :locality,
:region, :pcode, :country, :phone, :fax, :mobile, :email, :pvt_addr, :pvt_phone, :pvt_fax, :pvt_email,
:owner_uid, :owner_commid, :photo_url, :url, UTC_TIMESTAMP())`, ci)
:owner_uid, :owner_commid, :photo_url, :url, NOW())`, ci)
if err != nil {
return false, err
}
+11 -1
View File
@@ -87,6 +87,16 @@ func (p *UserPrefs) MessagePrinter() *message.Printer {
return message.NewPrinter(*p.LanguageTag())
}
// Location returns the time.Location for these user prefs.
func (p *UserPrefs) Location() *time.Location {
rc, err := time.LoadLocation(p.TimeZoneID)
if err != nil {
log.Fatalf("BOGUS TIMEZONE TAG %s in user prefs for uid %d", p.TimeZoneID, p.Uid)
return time.Local
}
return rc
}
// User represents a user in the Amsterdam database.
type User struct {
Mutex sync.RWMutex
@@ -613,7 +623,7 @@ func AmCreateNewUser(username string, password string, reminder string, dob *tim
// Insert the user record.
_, err2 := amdb.Exec(`INSERT INTO users (username, passhash, verify_email, lockout, email_confnum,
base_lvl, created, lastaccess, passreminder, description, dob) VALUES (?, ?, 0, 0, ?, ?, UTC_TIMESTAMP(), UTC_TIMESTAMP(), ?, '', ?)`,
base_lvl, created, lastaccess, passreminder, description, dob) VALUES (?, ?, 0, 0, ?, ?, NOW(), NOW(), ?, '', ?)`,
username, hashPassword(password), util.GenerateRandomConfirmationNumber(), AmDefaultRole("Global.NewUser").Level(),
reminder, dob)
if err2 != nil {
+4 -3
View File
@@ -344,13 +344,14 @@ func ShowProfile(ctxt ui.AmContext) (string, any, error) {
ctxt.VarMap().Set("uid", user.Uid)
ctxt.VarMap().Set("username", user.Username)
ctxt.VarMap().Set("photoURL", userPhotoURL(ci))
tz := prefs.Location()
loc := prefs.Localizer()
ctxt.VarMap().Set("dateCreated", loc.Strftime("%x %X", user.Created))
ctxt.VarMap().Set("dateCreated", loc.Strftime("%x %X", user.Created.In(tz)))
if user.LastAccess != nil {
ctxt.VarMap().Set("dateLastLogin", loc.Strftime("%x %X", *user.LastAccess))
ctxt.VarMap().Set("dateLastLogin", loc.Strftime("%x %X", (*user.LastAccess).In(tz)))
}
if ci.LastUpdate != nil {
ctxt.VarMap().Set("dateLastUpdate", loc.Strftime("%x %X", *ci.LastUpdate))
ctxt.VarMap().Set("dateLastUpdate", loc.Strftime("%x %X", (*ci.LastUpdate).In(tz)))
}
var b strings.Builder
if ci.Prefix != nil && *ci.Prefix != "" {