]> granicus.if.org Git - pdns/commitdiff
do right timezones right
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 14 Aug 2013 23:41:21 +0000 (01:41 +0200)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Tue, 26 Nov 2013 11:26:32 +0000 (12:26 +0100)
pdns/rcpgenerator.cc
pdns/unix_utility.cc
pdns/utility.hh

index 55295dc6477a42eddff5ed5d308cfd0ea30be99c..bf377010cc59a4a42ce442f5a81b98b514690395 100644 (file)
@@ -451,7 +451,7 @@ void RecordTextWriter::xfrTime(const uint32_t& val)
   struct tm tm;
   time_t time=val; // Y2038 bug!
 #ifndef WIN32
-  gmtime_r(&time, &tm);
+  Utility::gmtime_r(&time, &tm);
 #else
   struct tm* tmptr;
   tmptr=gmtime(&time);
index 862e0587d853ff87c99536f703c870ee07979e8f..679132f4101437da6b0b8c47369f43183c5bb57a 100644 (file)
@@ -277,3 +277,28 @@ time_t Utility::timegm(struct tm *const t)
   return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
 }
 
+void Utility::gmtime_r(const time_t *timer, struct tm *tmbuf) {
+
+  int monthdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+  int days = *timer / 86400;
+  int leapdays = (days + 671) / 1461;
+  int leapydays = (days + 365) / 1461;
+
+  tmbuf->tm_hour = *timer / 3600 % 24;
+  tmbuf->tm_min = *timer / 60 % 60;
+  tmbuf->tm_sec = *timer % 60;
+
+  tmbuf->tm_year = (days - leapdays) / 365 + 70;
+  tmbuf->tm_yday = days - leapydays - (tmbuf->tm_year - 70) * 365 + 1;
+
+  tmbuf->tm_mon = 0;
+  tmbuf->tm_mday = tmbuf->tm_yday;
+  monthdays[1] += isleap(tmbuf->tm_year + 1900);
+  while (monthdays[tmbuf->tm_mon] < tmbuf->tm_mday) {
+    tmbuf->tm_mday -= monthdays[tmbuf->tm_mon];
+    tmbuf->tm_mon++;
+  }
+
+  tmbuf->tm_wday = (days + 4) % 7; // Day 0 is magic thursday ;)
+  tmbuf->tm_isdst = 0;
+}
index a517bf47324f7f8b89e6fedb4388adff76257950..eaa1846e7270522d2bf3d39b3dd11a03eb4b34b6 100644 (file)
@@ -208,7 +208,8 @@ public:
   static void usleep( unsigned long usec );
 
   static time_t timegm(struct tm *tm);
-  
+
+  static void gmtime_r(const time_t *timer, struct tm *tmbuf);
 };