X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ftime%2Ftimezone.cpp;h=a2cd7a3f772743c7fe9ac06fde3042fd6ab28d98;hp=a96e1b51be34ef6672239c358210d4b766d212d5;hb=699670a264c7fc5a0b05c2d258a7552f5c594bd1;hpb=c8c97ab483cfbf1bb3d0788cf729be92091ba2fc diff --git a/source/time/timezone.cpp b/source/time/timezone.cpp index a96e1b5..a2cd7a3 100644 --- a/source/time/timezone.cpp +++ b/source/time/timezone.cpp @@ -1,19 +1,12 @@ -/* $Id$ - -This file is part of libmspcore -Copyright © 2008-2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include -#include -#include #ifdef WIN32 #include #else +#include #include #endif -#include "../core/except.h" +#include +#include #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)); @@ -68,7 +61,7 @@ TimeZone get_local_timezone() long typecnt = get_long(ptr); long charcnt = get_long(ptr); int size = timecnt*5+typecnt*6+isgmtcnt+isstdcnt+leapcnt*8+charcnt; - char buf[size]; + char *buf = new char[size]; len = read(fd, buf, size); if(len==size) { @@ -98,6 +91,7 @@ TimeZone get_local_timezone() name = ptr+abbrind; } + delete[] buf; } close(fd); @@ -122,12 +116,10 @@ TimeZone::TimeZone(int minutes): { if(minutes) { - ostringstream ss; - ss.fill('0'); int m = abs(minutes); - ss<<"UTC"<<(minutes<0 ? '-' : '+')<