]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/timezone.cpp
Move non-oneliner functions out of RefPtr class declaration
[libs/core.git] / source / time / timezone.cpp
index fd2487b6475600412ca42700aa59cf36d58b7299..76c3fb242463fe3f5f504c37e3f0a95a616d223c 100644 (file)
@@ -1,46 +1,9 @@
-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2008  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <cstdlib>
-#include <sstream>
-#include <iomanip>
-#include <time.h>
+#include <msp/strings/format.h>
 #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 {
 
@@ -48,22 +11,25 @@ TimeZone::TimeZone():
        name("UTC")
 { }
 
-TimeZone::TimeZone(int minutes_west):
-       offset(minutes_west*min)
+TimeZone::TimeZone(int minutes):
+       offset(minutes*min)
 {
-       if(minutes_west)
+       if(minutes)
        {
-               ostringstream ss;
-               ss.fill('0');
-               int m=abs(minutes_west);
-               ss<<"UTC"<<(minutes_west<0 ? '-' : '+')<<m/60;
+               int m = abs(minutes);
+               name = format("UTC%c%d", (minutes<0 ? '-' : '+'), m/60);
                if(m%60)
-                       ss<<':'<<setw(2)<<m%60;
+                       name += format(":%02d", m%60);
        }
        else
-               name="UTC";
+               name = "UTC";
 }
 
+TimeZone::TimeZone(int minutes, const string &n):
+       name(n),
+       offset(minutes*min)
+{ }
+
 const TimeZone &TimeZone::utc()
 {
        static TimeZone tz(0);
@@ -72,7 +38,7 @@ const TimeZone &TimeZone::utc()
 
 const TimeZone &TimeZone::local()
 {
-       static TimeZone tz=get_local_timezone();
+       static TimeZone tz = platform_get_local_timezone();
        return tz;
 }