]> 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 56fcf8f588a389325a1fda85cec2577b82b1c54d..76c3fb242463fe3f5f504c37e3f0a95a616d223c 100644 (file)
@@ -1,107 +1,9 @@
 #include <cstdlib>
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <fcntl.h>
-#endif
-#include <msp/core/systemerror.h>
 #include <msp/strings/format.h>
-#include "timestamp.h"
 #include "timezone.h"
-#include "units.h"
-#include "utils.h"
 
 using namespace std;
 
-namespace {
-
-using Msp::Time::TimeZone;
-
-#ifndef WIN32
-long get_long(char *&ptr)
-{
-       long result = 0;
-       for(unsigned i=0; i<4; ++i)
-               result = (result<<8)+static_cast<unsigned char >(*ptr++);
-       return result;
-}
-#endif
-
-TimeZone get_local_timezone()
-{
-#ifdef WIN32
-       TIME_ZONE_INFORMATION tzinfo;
-       DWORD dst = GetTimeZoneInformation(&tzinfo);
-       if(dst==TIME_ZONE_ID_INVALID)
-               throw Msp::system_error("GetTimeZoneInformation");
-
-       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
-       int fd = open("/etc/localtime", O_RDONLY);
-       if(fd!=-1)
-       {
-               char hdr[44];
-               int len = read(fd, hdr, sizeof(hdr));
-               long gmtoff = -1;
-               string name;
-               if(len==44 && hdr[0]=='T' && hdr[1]=='Z' && hdr[2]=='i' && hdr[3]=='f')
-               {
-                       char *ptr = hdr+20;
-                       long isgmtcnt = get_long(ptr);
-                       long isstdcnt = get_long(ptr);
-                       long leapcnt = get_long(ptr);
-                       long timecnt = get_long(ptr);
-                       long typecnt = get_long(ptr);
-                       long charcnt = get_long(ptr);
-                       int size = timecnt*5+typecnt*6+isgmtcnt+isstdcnt+leapcnt*8+charcnt;
-                       char buf[size];
-                       len = read(fd, buf, size);
-                       if(len==size)
-                       {
-                               ptr = buf;
-                               int index = -1;
-                               time_t cur_time = Msp::Time::now().to_unixtime();
-                               for(int i=0; i<timecnt; ++i)
-                                       if(get_long(ptr)<=cur_time)
-                                               index = i;
-
-                               if(index>0)
-                                       index = ptr[index];
-                               ptr += timecnt;
-
-                               int abbrind = 0;
-                               for(int i=0; i<typecnt; ++i)
-                               {
-                                       if((index>=0 && i==index) || (index<0 && !ptr[4] && gmtoff==-1))
-                                       {
-                                               gmtoff = get_long(ptr);
-                                               ++ptr;
-                                               abbrind = *ptr++;
-                                       }
-                                       else
-                                               ptr += 6;
-                               }
-
-                               name = ptr+abbrind;
-                       }
-               }
-               close(fd);
-
-               if(gmtoff!=-1)
-                       return TimeZone(gmtoff/60, name);
-       }
-       return TimeZone();
-#endif
-}
-
-}
-
 namespace Msp {
 namespace Time {
 
@@ -136,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;
 }