A time interface class. This class replicates the normal time functions, but goes a couple of steps further. mbed library 82 and prior has a defective gmtime function. Also, this class enables access to setting the time, and adjusting the accuracy of the RTC.

Dependencies:   CalendarPage

Dependents:   CI-data-logger-server WattEye X10Svr SSDP_Server

Revision:
6:c79cfe750416
Parent:
4:9cae2da8215e
Child:
8:18489e877b0b
--- a/TimeInterface.h	Thu Aug 06 11:13:47 2015 +0000
+++ b/TimeInterface.h	Thu Nov 26 16:32:36 2015 +0000
@@ -4,7 +4,7 @@
 #include "mbed.h"
 #include <ctime>
 
-#include "NTPClient.h"  // ver 4 Donatien Garnier
+#include "NTPClient.h"  // ver 7 Wiredhome from ver 5 Donatien Garnier
 
 // Special Registers and their usage:
 // GPREG0: 32 bits
@@ -91,7 +91,7 @@
     /// to a provided buffer.
     ///
     /// This reads the real time clock and returns the current time, adjusted
-    /// for the local timezone.
+    /// for the local timezone and daylight savings time.
     ///
     /// @code
     /// time_t t_ref2, t_ref3;
@@ -149,7 +149,8 @@
     
     /// Convert the referenced time_t value to a tm structure in local format.
     ///
-    /// This method leverages the time zone offset applied with @see set_tzo().
+    /// This method leverages the time zone offset applied with @see set_tzo()
+    /// and the daylight savings time flag applied with @see set_dst().
     ///
     /// @note Watch out for race conditions as this returns a pointer to a
     ///     shared buffer.
@@ -218,8 +219,24 @@
     ///
     /// @param[in] dst is a boolean that should be set when dst is
     ///         the active mode.
+    /// @returns true, always.
     ///
-    void set_dst(bool dst);
+    bool set_dst(bool dst);
+    
+    /// Set the clock for auto-adjust local time based on 
+    /// changing to standard or daylight savings time.
+    ///
+    /// return values for localtime will then be adjusted not only
+    /// for the time zone offset, but for dst.
+    ///
+    /// @param[in] dstStart is a string of the form "mm/dd,hh:mm"
+    ///                     representing when DST starts.
+    /// @param[in] dstStop  is a string of the form "mm/dd,hh:mm"
+    ///                     representing when DST stops.
+    /// @returns true if the start and stop pair could be successfully
+    ///               parsed.
+    ///
+    bool set_dst(const char * dstStart, const char * dstStop);
     
     /// Get the current clock mode for daylight savings time.
     ///
@@ -295,6 +312,31 @@
 
     // ntp interface functions    
 private:
+    typedef struct {
+        uint8_t MM;
+        uint8_t DD;
+        uint8_t hh;
+        uint8_t mm;
+    } dst_event_t;
+    typedef struct {
+        dst_event_t dst_start;
+        dst_event_t dst_stop;
+    } dst_event_pair_t;
+
+    bool parseDSTstring(dst_event_t * result, const char * dstr);
+    
+    /// Performs a "simple" computation of two dates into minutes.
+    ///
+    /// Does not account for leap years or which month it is. Is
+    /// useful only for comparing which date/time came first, not for
+    /// computing the difference between them.
+    ///
+    /// @return "normalized" minutes since Jan 1 00:00.
+    ///
+    uint32_t minutesSinceJan(int mon, int day, int hr, int min);
+
+    dst_event_pair_t dst_pair;
+    bool dst;           // true in dst mode
     char result[30];    // holds the converted to text time string
     time_t tresult;     // holds the converted time structure.
     struct tm_ex tm_ext;