yet another 18B20 Temperature sensor. variable number of sensors working in parasite mode, serial 16x2 display with diagnostic output and post to a rest web service

Dependencies:   EthernetInterface HTTPClient NTPClient mbed-rtos mbed

Revision:
1:9e88b2508768
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/local_time.cpp	Thu Jan 03 18:50:43 2013 +0000
@@ -0,0 +1,32 @@
+#include "local_time.h"
+
+LocalTime::LocalTime() {}
+
+struct tm *LocalTime::tm() {
+    time_t seconds = time(NULL);
+    
+    struct tm *t = localtime(&seconds);
+    if (seconds > last_sunday(t->tm_year, 3) && seconds < last_sunday(t->tm_year, 10)) {
+        seconds += 7200;
+    } else {
+        seconds += 3600;
+    }
+
+    return localtime(&seconds);
+}
+
+time_t LocalTime::last_sunday(int year, int month) {
+    struct tm t1;
+    
+    t1.tm_sec = 0;   t1.tm_min = 0;     t1.tm_hour = month == 10 ? 3 : 2;
+    t1.tm_mday = 31; t1.tm_mon = month; t1.tm_year = year;
+    
+    // convert to seconds since epoch
+    time_t seconds = mktime(&t1);
+    
+    // convert back to tm because we need to know the week day
+    struct tm *t2 = localtime(&seconds);
+    
+    // subtract weekday to get back last sunday of month requested
+    return seconds - 86400 * t2->tm_wday;
+}
\ No newline at end of file