]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/windows/timezone.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / time / windows / timezone.cpp
diff --git a/source/time/windows/timezone.cpp b/source/time/windows/timezone.cpp
new file mode 100644 (file)
index 0000000..570c679
--- /dev/null
@@ -0,0 +1,25 @@
+#include <windows.h>
+#include <msp/core/systemerror.h>
+#include "timezone.h"
+
+namespace Msp {
+namespace Time {
+
+TimeZone TimeZone::platform_get_local_timezone()
+{
+       TIME_ZONE_INFORMATION tzinfo;
+       DWORD dst = GetTimeZoneInformation(&tzinfo);
+       if(dst==TIME_ZONE_ID_INVALID)
+               throw Msp::system_error("GetTimeZoneInformation");
+
+       int offset = tzinfo.Bias;
+       if(dst==TIME_ZONE_ID_STANDARD)
+               offset += tzinfo.StandardBias;
+       else if(dst==TIME_ZONE_ID_DAYLIGHT)
+               offset += tzinfo.DaylightBias;
+
+       return TimeZone(offset);
+}
+
+} // namespace Time
+} // namespace Msp