X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ftime%2Ftimezone.cpp;fp=source%2Ftime%2Ftimezone.cpp;h=fd2487b6475600412ca42700aa59cf36d58b7299;hp=0000000000000000000000000000000000000000;hb=3fd9d04e84cdd72aabe8f9878f9e8ff006275bb6;hpb=cd89068b8ebafdc0f888c1aa21498bb93b55d814 diff --git a/source/time/timezone.cpp b/source/time/timezone.cpp new file mode 100644 index 0000000..fd2487b --- /dev/null +++ b/source/time/timezone.cpp @@ -0,0 +1,80 @@ +/* $Id$ + +This file is part of libmspcore +Copyright © 2008 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#include +#include +#include +#include "timezone.h" +#include "units.h" + +using namespace std; + +namespace { + +using Msp::Time::TimeZone; + +TimeZone get_local_timezone() +{ +#ifdef WIN32 + TIME_ZONE_INFORMATION tzinfo; + DWORD dst=GetTimeZoneInformation(&tzinfo); + if(dst==TIME_ZONE_ID_INVALID) + throw SystemError("Failed to get time zone information", GetLastError()); + + 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); +#else + tzset(); + return TimeZone(timezone/60); +#endif +} + +} + +namespace Msp { +namespace Time { + +TimeZone::TimeZone(): + name("UTC") +{ } + +TimeZone::TimeZone(int minutes_west): + offset(minutes_west*min) +{ + if(minutes_west) + { + ostringstream ss; + ss.fill('0'); + int m=abs(minutes_west); + ss<<"UTC"<<(minutes_west<0 ? '-' : '+')<