Accessing Windows internal leap second information #1624
-
My original plan for
After adding, the registry value contains binary data "e507 0b00 1e00 1700 0000 0000", corresponding to 2021, 11, 30, 23, 0, 0. After removing, the registry value is empty, yet the "Runtime State" remembers the data. The first questions are, does this "Runtime State" matter? If/when a real leap second is added, are we sure it will be in this registry value?
c:\leapsec>type leapsec.cpp
#include "Windows.h"
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <vector>
struct LeapSecondInfo {
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t hour;
uint16_t negative;
uint16_t unknown;
};
static_assert(sizeof(LeapSecondInfo) == 12, "");
using namespace std;
int main()
{
constexpr auto reg_key_name = __TEXT("SYSTEM\\CurrentControlSet\\Control\\LeapSecondInformation");
constexpr auto reg_subkey_name = __TEXT("LeapSeconds");
HKEY leap_sec_key = 0;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_key_name, 0, KEY_READ, &leap_sec_key);
vector<LeapSecondInfo> leap_sec_info;
DWORD size = 0;
RegQueryValueEx(leap_sec_key, reg_subkey_name, nullptr, nullptr, nullptr, &size);
assert(size % 12 == 0);
leap_sec_info.resize(size / 12);
RegQueryValueEx(leap_sec_key, reg_subkey_name, nullptr, nullptr, reinterpret_cast<BYTE*>(leap_sec_info.data()), &size);
puts("Leap second list:");
for (const auto& ls : leap_sec_info) {
printf("%c%04d-%02d-%02dT%02d:59:59\n", ls.negative ? '-' : '+', ls.year, ls.month, ls.day, ls.hour);
}
return 0;
}
c:\leapsec>cl leapsec.cpp /EHsc advapi32.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29812 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
leapsec.cpp
Microsoft (R) Incremental Linker Version 14.28.29812.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:leapsec.exe
leapsec.obj
advapi32.lib
c:\leapsec>leapsec
Leap second list:
+2021-11-30T23:59:59
+2021-12-31T23:59:59
-2022-01-31T23:59:59
c:\leapsec>w32tm /leapseconds /getstatus /verbose
[Leap Seconds]
Enabled: 1 (Local)
Number of Leap Seconds (after June 2018): 3 (Local)
Leap Seconds List (Local):
+2021-11-30T23:59:59
+2021-12-31T23:59:59
-2022-01-31T23:59:59
c:\leapsec>
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Thanks for looking into this and creating this discussion for more...discussion 😝 I can go and look further into details around using the registry key, but I did find this article online which seems to indicate that we can't get past leap seconds from the registry key, only future ones (looking at the section "Previous Leap Seconds"). Similarly, in the code you provide above it doesn't look like any past leap seconds are reported - only future ones. Looking at time.zone.leap, we'll need to also be able to provide data about past leap seconds, so the registry key may not be a complete solution for us. Were you envisioning using the registry key to do automatic updates to the |
Beta Was this translation helpful? Give feedback.
-
@MattStephanson we've finally heard back from the team who implemented the Windows leap second registry!
They've pointed us to some code that |
Beta Was this translation helpful? Give feedback.
@MattStephanson we've finally heard back from the team who implemented the Windows leap second registry!
They've pointed us to some code that
w32tm
uses to deal with leap seconds that should be more robust in dealing with these ed…