From e853910af21a3191c20b932f48ca64c6f655da41 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Tue, 4 Jan 2011 06:18:51 +0000 Subject: [PATCH] So I'm not sure if this ever worked right or if time is just measured differently in Germany, but NetworkTime was always setting my time 6 hours ahead, no matter what time zone or whether I stored the time in local time or GMT. Upon looking closer and doing some Googling I determined that the constant Axel used for the number of seconds between 1900 and 2000 was off by 6 hours, and that combined with the odd kUTCtoGMT constant resulted in the 6 hour difference. By just replacing the system_time_difference() function with a correct constant for the number of seconds between 1900 and 1970 and getting rid of kUTCtoGMT it now works for me (and at least one other person on #haiku-dev, thanks kallisti5!) For those wondering NTP time is measured from 1900 hence the need for this conversion. I will now look into integrating this with the Time preflet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40103 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/networktime/ntp.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/apps/networktime/ntp.cpp b/src/apps/networktime/ntp.cpp index 2dc5a8775b..992c9e28e1 100644 --- a/src/apps/networktime/ntp.cpp +++ b/src/apps/networktime/ntp.cpp @@ -93,28 +93,13 @@ enum ntp_modes { }; -const uint32 kUTCtoGMT = 12 * 60 * 60; - - -uint32 -seconds_system_difference(void) -{ - const uint32 kYear2000 = 3155713200UL; - // that many seconds from year 1900 to 2000. - - struct tm tm; - memset(&tm, 0, sizeof(struct tm)); - tm.tm_mday = 1; - tm.tm_year = 100; - - return kYear2000 - mktime(&tm); -} +const uint32 kSecondsBetween1900And1970 = 2208988800UL; uint32 seconds_since_1900(void) { - return seconds_system_difference() + real_time_clock(); + return kSecondsBetween1900And1970 + real_time_clock(); } @@ -207,7 +192,7 @@ ntp_update_time(const char *hostname, Monitor *monitor) return B_BAD_VALUE; } - time_t now = message.transmit_timestamp.Integer() - seconds_system_difference() + kUTCtoGMT; + time_t now = message.transmit_timestamp.Integer() - kSecondsBetween1900And1970; if (monitor) { char buffer[64];