From fab063018041c3343d73a630af09b3cc939fd09e Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 20 Feb 2020 03:06:24 -0500 Subject: [PATCH] time.Unix still requires normalization to UTC --- irc/accounts.go | 2 +- irc/channelreg.go | 2 +- irc/misc_test.go | 10 +++++----- irc/mysql/history.go | 2 +- irc/utils/args.go | 2 +- irc/znc.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/irc/accounts.go b/irc/accounts.go index 8536b31a..cf62b235 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -560,7 +560,7 @@ func (am *AccountManager) loadLastSignoff(account string) (lastSignoff time.Time }) lsNum, err := strconv.ParseInt(lsText, 10, 64) if err != nil { - return time.Unix(0, lsNum) + return time.Unix(0, lsNum).UTC() } return } diff --git a/irc/channelreg.go b/irc/channelreg.go index eb3733c9..984bd9fd 100644 --- a/irc/channelreg.go +++ b/irc/channelreg.go @@ -271,7 +271,7 @@ func (reg *ChannelRegistry) deleteChannel(tx *buntdb.Tx, key string, info Regist if err == nil { regTime, _ := tx.Get(fmt.Sprintf(keyChannelRegTime, key)) regTimeInt, _ := strconv.ParseInt(regTime, 10, 64) - registeredAt := time.Unix(regTimeInt, 0) + registeredAt := time.Unix(regTimeInt, 0).UTC() founder, _ := tx.Get(fmt.Sprintf(keyChannelFounder, key)) // to see if we're deleting the right channel, confirm the founder and the registration time diff --git a/irc/misc_test.go b/irc/misc_test.go index 73806ff6..904832f1 100644 --- a/irc/misc_test.go +++ b/irc/misc_test.go @@ -9,9 +9,9 @@ import ( ) func TestZncTimestampParser(t *testing.T) { - assertEqual(zncWireTimeToTime("1558338348.988"), time.Unix(1558338348, 988000000), t) - assertEqual(zncWireTimeToTime("1558338348.9"), time.Unix(1558338348, 900000000), t) - assertEqual(zncWireTimeToTime("1558338348"), time.Unix(1558338348, 0), t) - assertEqual(zncWireTimeToTime(".988"), time.Unix(0, 988000000), t) - assertEqual(zncWireTimeToTime("garbage"), time.Unix(0, 0), t) + assertEqual(zncWireTimeToTime("1558338348.988"), time.Unix(1558338348, 988000000).UTC(), t) + assertEqual(zncWireTimeToTime("1558338348.9"), time.Unix(1558338348, 900000000).UTC(), t) + assertEqual(zncWireTimeToTime("1558338348"), time.Unix(1558338348, 0).UTC(), t) + assertEqual(zncWireTimeToTime(".988"), time.Unix(0, 988000000).UTC(), t) + assertEqual(zncWireTimeToTime("garbage"), time.Unix(0, 0).UTC(), t) } diff --git a/irc/mysql/history.go b/irc/mysql/history.go index e9ad5b0e..cd4c660d 100644 --- a/irc/mysql/history.go +++ b/irc/mysql/history.go @@ -405,7 +405,7 @@ func (mysql *MySQL) msgidToTime(msgid string) (result time.Time, err error) { if mysql.logError("could not resolve msgid to time", err) { return } - result = time.Unix(0, nanotime) + result = time.Unix(0, nanotime).UTC() return } diff --git a/irc/utils/args.go b/irc/utils/args.go index 127785e4..c33cd566 100644 --- a/irc/utils/args.go +++ b/irc/utils/args.go @@ -80,5 +80,5 @@ func (err *IncompatibleSchemaError) Error() string { } func NanoToTimestamp(nanotime int64) string { - return time.Unix(0, nanotime).Format(IRCv3TimestampFormat) + return time.Unix(0, nanotime).UTC().Format(IRCv3TimestampFormat) } diff --git a/irc/znc.go b/irc/znc.go index aedfa3a4..cd3ff783 100644 --- a/irc/znc.go +++ b/irc/znc.go @@ -45,7 +45,7 @@ func zncWireTimeToTime(str string) (result time.Time) { } seconds, _ := strconv.ParseInt(secondsPortion, 10, 64) fraction, _ := strconv.ParseFloat(fracPortion, 64) - return time.Unix(seconds, int64(fraction*1000000000)) + return time.Unix(seconds, int64(fraction*1000000000)).UTC() } type zncPlaybackTimes struct {