3 This file is part of libmspcore
4 Copyright © 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
16 #include <msp/core/except.h>
24 using Msp::Time::TimeZone;
26 TimeZone get_local_timezone()
29 TIME_ZONE_INFORMATION tzinfo;
30 DWORD dst=GetTimeZoneInformation(&tzinfo);
31 if(dst==TIME_ZONE_ID_INVALID)
32 throw Msp::SystemError("Failed to get time zone information", GetLastError());
34 int offset=tzinfo.Bias;
35 if(dst==TIME_ZONE_ID_STANDARD)
36 offset+=tzinfo.StandardBias;
37 else if(dst==TIME_ZONE_ID_DAYLIGHT)
38 offset+=tzinfo.DaylightBias;
40 return TimeZone(offset);
43 return TimeZone(timezone/60);
56 TimeZone::TimeZone(int minutes_west):
57 offset(minutes_west*min)
63 int m=abs(minutes_west);
64 ss<<"UTC"<<(minutes_west<0 ? '-' : '+')<<m/60;
66 ss<<':'<<setw(2)<<m%60;
72 const TimeZone &TimeZone::utc()
74 static TimeZone tz(0);
78 const TimeZone &TimeZone::local()
80 static TimeZone tz=get_local_timezone();