mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-07 14:05:50 +00:00
Fix issue with very high integer value parsing, add unit tests
also add comment about urgent replication
This commit is contained in:
@@ -896,13 +896,13 @@ func win32timestampToTime(win32timestamp string) (time.Time, error) {
|
||||
const unixTimeBaseAsWin = 116_444_736_000_000_000 // The unix base time (January 1, 1970 UTC) as 100 ns since Win32 epoch (1601-01-01)
|
||||
const hundredNsToSecFactor = 10_000_000
|
||||
|
||||
win32Time, err := strconv.ParseUint(win32timestamp, 10, 64)
|
||||
win32Time, err := strconv.ParseInt(win32timestamp, 10, 64)
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("couldn't parse as timestamp")
|
||||
}
|
||||
|
||||
unixsec := int64(win32Time-unixTimeBaseAsWin) / hundredNsToSecFactor
|
||||
unixns := int64(win32Time%hundredNsToSecFactor) * 100
|
||||
unixsec := (win32Time - unixTimeBaseAsWin) / hundredNsToSecFactor
|
||||
unixns := (win32Time % hundredNsToSecFactor) * 100
|
||||
|
||||
convertedTime := time.Unix(unixsec, unixns).UTC()
|
||||
return convertedTime, nil
|
||||
|
||||
@@ -2085,6 +2085,16 @@ func TestWin32TimestampToTime(t *testing.T) {
|
||||
timestampString: "132540199410000001",
|
||||
wantTime: time.Date(2021, time.January, 2, 0, 12, 21, 100, time.UTC).UTC(),
|
||||
},
|
||||
{
|
||||
name: "max allowable value",
|
||||
timestampString: "9223372036854775807", // 2^63-1
|
||||
wantTime: time.Date(30828, time.September, 14, 2, 48, 5, 477580700, time.UTC).UTC(),
|
||||
},
|
||||
{
|
||||
name: "just past max allowable value",
|
||||
timestampString: "9223372036854775808", // 2^63
|
||||
wantErr: "couldn't parse as timestamp",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Reference in New Issue
Block a user