-
Notifications
You must be signed in to change notification settings - Fork 593
windows: fix filetime conversions and deprecate Nanoseconds #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
windows: fix filetime conversions and deprecate Nanoseconds #251
Conversation
This PR (HEAD: 5c27ec0) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/sys/+/682816. Important tips:
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Alex Brainman: Patch Set 1: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Filetime.Nanoseconds() has a major drawback: the returned int64 is too small to represent Filetime's zero value (January 1, 1601) in terms of nanoseconds since Epoch (00:00:00 UTC, January 1, 1970); MinInt64 only dates back to year 1677. This has real-life implications, e.g., some Windows sub systems (Perflib, to name one) create registry keys with the last write time property set to zero. In this case, ModTime() reports an underflow-affected value of 2185-07-22T00:34:33.709551+01:00. This commit deprecates Nanoseconds() in favor of the new Unix() that returns a well-known pair of seconds and nanoseconds thus is capable to cover the full range of Filetime values. ModTime() uses Unix() accordingly to produce correct time.Time values again. Additionally, ModTimeZero() provides a convenient way to check for a last write time value of zero in analogy to time.Time.IsZero(); no need to specify January 1, 1601 manually. Fixes golang/go#74335
5c27ec0
to
4bc759a
Compare
This PR (HEAD: 4bc759a) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/sys/+/682816. Important tips:
|
Message from Gregor Matura: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Alex Brainman: Patch Set 2: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Gregor Matura: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Gregor Matura: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Gregor Matura: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Gregor Matura: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Gregor Matura: Patch Set 4: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Message from Alex Brainman: Patch Set 5: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/682816. |
Filetime.Nanoseconds() has a major drawback: the returned int64 is too small to represent Filetime's zero value (January 1, 1601, [1]) in terms of nanoseconds since Epoch (00:00:00 UTC, January 1, 1970); MinInt64 [2] only dates back to year 1677.
This has real-life implications, e.g., some Windows sub systems (Perflib, to name one) create registry keys with the last write time property set to zero (see note below). In this case, ModTime() reports an underflow-affected value of 2185-07-22T00:34:33.709551+01:00.
This commit deprecates Nanoseconds() in favor of the new Unix() that returns a well-known pair of seconds and nanoseconds [3] thus is capable to cover the full range of Filetime values. ModTime() uses Unix() accordingly to produce correct time.Time values again. Additionally, ModTimeZero() provides a convenient way to check for a last write time value of zero in analogy to time.Time.IsZero() [4]; no need to specify January 1, 1601 manually.
A note on last write time values:
lastWriteTime
is not exposed in the UI (say,regedit
) or in PowerShell (Get-ItemProperty
), you need to queryRegQueryInfoKeyA
[5] explicitly in some way [6] or another [7]. The source of the latter is offline by now but can be found elsewhere [8] and provides a quick way to show the value.[1] https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime
[2] https://pkg.go.dev/math#pkg-constants
[3] https://pkg.go.dev/time#Unix
[4] https://pkg.go.dev/time#Time.IsZero
[5] https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryinfokeya?redirectedfrom=MSDN
[6] https://learn.microsoft.com/en-us/windows/win32/sysinfo/retrieving-the-last-write-time
[7] https://learn-powershell.net/2014/12/18/retrieving-a-registry-key-lastwritetime-using-powershell/
[8] https://github.com/wxrdnx/GetRegistryKeyLastWriteTimeAndClassName
Fixes golang/go#74335.