X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ftime%2Ftimezone.cpp;h=9c146249208da8206ae6c1c937526afcde56fe21;hp=43d6d101c723ab760dcaae20db659a3f09dfa451;hb=d5dd704b2576f878809e87dbb8ff8591b9bdbce4;hpb=47a232c3c19e718a30281d3ada8acc1b6212ea8c diff --git a/source/time/timezone.cpp b/source/time/timezone.cpp index 43d6d10..9c14624 100644 --- a/source/time/timezone.cpp +++ b/source/time/timezone.cpp @@ -28,9 +28,9 @@ using Msp::Time::TimeZone; #ifndef WIN32 long get_long(char *&ptr) { - long result=0; + long result = 0; for(unsigned i=0; i<4; ++i) - result=(result<<8)+static_cast(*ptr++); + result = (result<<8)+static_cast(*ptr++); return result; } #endif @@ -39,64 +39,64 @@ TimeZone get_local_timezone() { #ifdef WIN32 TIME_ZONE_INFORMATION tzinfo; - DWORD dst=GetTimeZoneInformation(&tzinfo); + DWORD dst = GetTimeZoneInformation(&tzinfo); if(dst==TIME_ZONE_ID_INVALID) throw Msp::SystemError("Failed to get time zone information", GetLastError()); - int offset=tzinfo.Bias; + int offset = tzinfo.Bias; if(dst==TIME_ZONE_ID_STANDARD) - offset+=tzinfo.StandardBias; + offset += tzinfo.StandardBias; else if(dst==TIME_ZONE_ID_DAYLIGHT) - offset+=tzinfo.DaylightBias; + offset += tzinfo.DaylightBias; return TimeZone(offset); #else - int fd=open("/etc/localtime", O_RDONLY); + int fd = open("/etc/localtime", O_RDONLY); if(fd>=-1) { char hdr[44]; - int len=read(fd, hdr, sizeof(hdr)); - long gmtoff=-1; + 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 *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); + len = read(fd, buf, size); if(len==size) { - ptr=buf; - int index=-1; - time_t cur_time=Msp::Time::now().to_unixtime(); + ptr = buf; + int index = -1; + time_t cur_time = Msp::Time::now().to_unixtime(); for(int i=0; i0) - index=ptr[index]; - ptr+=timecnt; + index = ptr[index]; + ptr += timecnt; - int abbrind=0; + int abbrind = 0; for(int i=0; i=0 && i==index) || (index<0 && !ptr[4] && gmtoff==-1)) { - gmtoff=get_long(ptr); + gmtoff = get_long(ptr); ++ptr; - abbrind=*ptr++; + abbrind = *ptr++; } else - ptr+=6; + ptr += 6; } - name=ptr+abbrind; + name = ptr+abbrind; } } close(fd); @@ -124,13 +124,13 @@ TimeZone::TimeZone(int minutes_west): { ostringstream ss; ss.fill('0'); - int m=abs(minutes_west); + int m = abs(minutes_west); ss<<"UTC"<<(minutes_west<0 ? '-' : '+')<