[haiku-commits] r40103 - haiku/trunk/src/apps/networktime

  • From: leavengood@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 4 Jan 2011 07:18:51 +0100 (CET)

Author: leavengood
Date: 2011-01-04 07:18:51 +0100 (Tue, 04 Jan 2011)
New Revision: 40103
Changeset: http://dev.haiku-os.org/changeset/40103

Modified:
   haiku/trunk/src/apps/networktime/ntp.cpp
Log:
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.


Modified: haiku/trunk/src/apps/networktime/ntp.cpp
===================================================================
--- haiku/trunk/src/apps/networktime/ntp.cpp    2011-01-04 04:02:51 UTC (rev 
40102)
+++ haiku/trunk/src/apps/networktime/ntp.cpp    2011-01-04 06:18:51 UTC (rev 
40103)
@@ -93,28 +93,13 @@
 };
 
 
-const uint32 kUTCtoGMT = 12 * 60 * 60;
+const uint32 kSecondsBetween1900And1970 = 2208988800UL;
 
 
 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);
-}
-
-
-uint32
 seconds_since_1900(void)
 {
-       return seconds_system_difference() + real_time_clock();
+       return kSecondsBetween1900And1970 + real_time_clock();
 }
 
 
@@ -207,7 +192,7 @@
                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];


Other related posts: