Andrew Boyson / clock

Dependents:   oldheating gps motorhome heating

Revision:
57:4daf2e423b27
Parent:
44:aa45226d118e
Child:
58:ad2bfd0345de
--- a/tm/tm.c	Thu Feb 21 15:45:43 2019 +0000
+++ b/tm/tm.c	Thu Feb 21 21:08:03 2019 +0000
@@ -1,8 +1,10 @@
-#include <time.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
+#include <time.h>
+
+#include "time64.h"
 
 #define STD_OFFSET 0
 #define DST_OFFSET 1
@@ -160,14 +162,14 @@
         ++*pMonth;
     }
 }
-static void timeToTm(time_t t, struct tm* ptm, bool local)
+static void timeToTm(time64 t, struct tm* ptm, bool local)
 {
-    //Extract the seconds, minutes, hours and days from the time_t t
-    div_t divres;
-    divres = div(          t, 60);    int seconds  = divres.rem;
-    divres = div(divres.quot, 60);    int minutes  = divres.rem;
-    divres = div(divres.quot, 24);    int hours    = divres.rem;
-                                      int daysLeft = divres.quot;
+    //Extract the seconds, minutes, hours and days from the time64 t
+    lldiv_t divres;
+    divres = lldiv(          t, 60);    int seconds  = divres.rem;
+    divres = lldiv(divres.quot, 60);    int minutes  = divres.rem;
+    divres = lldiv(divres.quot, 24);    int hours    = divres.rem;
+                                        int daysLeft = divres.quot;
     
     //Add a year at a time while there is more than a year of days left
     int year      = 70; //Unix epoch is 1970
@@ -215,17 +217,17 @@
 }
 
 
-void TmUtcFromTimeT(time_t time, struct tm* ptm)
+void TmUtcFromTimeT(time64 time, struct tm* ptm)
 {
     timeToTm(time, ptm, false);
 }
-void TmLocalFromTimeT(time_t time, struct tm* ptm)
+void TmLocalFromTimeT(time64 time, struct tm* ptm)
 {
     timeToTm(time, ptm, true);
 }
-time_t TmUtcToTimeT(struct tm* ptm)
+time64 TmUtcToTimeT(struct tm* ptm)
 {
-    time_t days = 0;
+    time64 days = 0;
     
     for (int y = 70; y < ptm->tm_year; y++) days += isLeapYear(y) ? 366 : 365;