]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/timezone.cpp
Add missing headers
[libs/core.git] / source / time / timezone.cpp
index a96e1b51be34ef6672239c358210d4b766d212d5..a755954b43628c9f66fb407f46b527fb7a54314f 100644 (file)
@@ -1,19 +1,12 @@
-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2008-2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <cstdlib>
-#include <sstream>
-#include <iomanip>
 #ifdef WIN32
 #include <windows.h>
 #else
+#include <unistd.h>
 #include <fcntl.h>
 #endif
-#include "../core/except.h"
+#include <msp/strings/format.h>
+#include <msp/core/systemerror.h>
 #include "timestamp.h"
 #include "timezone.h"
 #include "units.h"
@@ -41,7 +34,7 @@ TimeZone get_local_timezone()
        TIME_ZONE_INFORMATION tzinfo;
        DWORD dst = GetTimeZoneInformation(&tzinfo);
        if(dst==TIME_ZONE_ID_INVALID)
-               throw Msp::SystemError("Failed to get time zone information", GetLastError());
+               throw Msp::system_error("GetTimeZoneInformation");
 
        int offset = tzinfo.Bias;
        if(dst==TIME_ZONE_ID_STANDARD)
@@ -52,7 +45,7 @@ TimeZone get_local_timezone()
        return TimeZone(offset);
 #else
        int fd = open("/etc/localtime", O_RDONLY);
-       if(fd>=-1)
+       if(fd!=-1)
        {
                char hdr[44];
                int len = read(fd, hdr, sizeof(hdr));
@@ -122,12 +115,10 @@ TimeZone::TimeZone(int minutes):
 {
        if(minutes)
        {
-               ostringstream ss;
-               ss.fill('0');
                int m = abs(minutes);
-               ss<<"UTC"<<(minutes<0 ? '-' : '+')<<m/60;
+               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";