mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 13:29:27 +01:00
Merge pull request #1918 from slingamn/znc_exact
use exact integer parsing for znc.in/playback
This commit is contained in:
commit
1e7775f6de
@ -12,6 +12,11 @@ func TestZncTimestampParser(t *testing.T) {
|
|||||||
assertEqual(zncWireTimeToTime("1558338348.988"), time.Unix(1558338348, 988000000).UTC(), t)
|
assertEqual(zncWireTimeToTime("1558338348.988"), time.Unix(1558338348, 988000000).UTC(), t)
|
||||||
assertEqual(zncWireTimeToTime("1558338348.9"), time.Unix(1558338348, 900000000).UTC(), t)
|
assertEqual(zncWireTimeToTime("1558338348.9"), time.Unix(1558338348, 900000000).UTC(), t)
|
||||||
assertEqual(zncWireTimeToTime("1558338348"), time.Unix(1558338348, 0).UTC(), t)
|
assertEqual(zncWireTimeToTime("1558338348"), time.Unix(1558338348, 0).UTC(), t)
|
||||||
|
assertEqual(zncWireTimeToTime("1558338348.99999999999999999999999999999"), time.Unix(1558338348, 999999999).UTC(), t)
|
||||||
|
assertEqual(zncWireTimeToTime("1558338348.999999999111111111"), time.Unix(1558338348, 999999999).UTC(), t)
|
||||||
|
assertEqual(zncWireTimeToTime("1558338348.999999991111111111"), time.Unix(1558338348, 999999991).UTC(), t)
|
||||||
assertEqual(zncWireTimeToTime(".988"), time.Unix(0, 988000000).UTC(), t)
|
assertEqual(zncWireTimeToTime(".988"), time.Unix(0, 988000000).UTC(), t)
|
||||||
|
assertEqual(zncWireTimeToTime("0"), time.Unix(0, 0).UTC(), t)
|
||||||
assertEqual(zncWireTimeToTime("garbage"), time.Unix(0, 0).UTC(), t)
|
assertEqual(zncWireTimeToTime("garbage"), time.Unix(0, 0).UTC(), t)
|
||||||
|
assertEqual(zncWireTimeToTime(""), time.Unix(0, 0).UTC(), t)
|
||||||
}
|
}
|
||||||
|
13
irc/znc.go
13
irc/znc.go
@ -51,11 +51,18 @@ func zncWireTimeToTime(str string) (result time.Time) {
|
|||||||
secondsPortion = str
|
secondsPortion = str
|
||||||
} else {
|
} else {
|
||||||
secondsPortion = str[:dot]
|
secondsPortion = str[:dot]
|
||||||
fracPortion = str[dot:]
|
fracPortion = str[dot+1:]
|
||||||
}
|
}
|
||||||
seconds, _ := strconv.ParseInt(secondsPortion, 10, 64)
|
seconds, _ := strconv.ParseInt(secondsPortion, 10, 64)
|
||||||
fraction, _ := strconv.ParseFloat(fracPortion, 64)
|
// truncate to nanosecond resolution if necessary
|
||||||
return time.Unix(seconds, int64(fraction*1000000000)).UTC()
|
if len(fracPortion) > 9 {
|
||||||
|
fracPortion = fracPortion[:9]
|
||||||
|
}
|
||||||
|
fracSeconds, _ := strconv.ParseInt(fracPortion, 10, 64)
|
||||||
|
for i := 0; i < (9 - len(fracPortion)); i++ {
|
||||||
|
fracSeconds *= 10
|
||||||
|
}
|
||||||
|
return time.Unix(seconds, fracSeconds).UTC()
|
||||||
}
|
}
|
||||||
|
|
||||||
func timeToZncWireTime(t time.Time) (result string) {
|
func timeToZncWireTime(t time.Time) (result string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user