Sunrise and sunset events
[wakeup.git] / src / sunrise.cpp
index 65b943f..1a64abe 100644 (file)
@@ -4,9 +4,11 @@
 #include <date.h>
 #include <iostream>
 
+#include "location.h"
+
 // Calculate the time of sunrise in timezone UTC.
 
-hour calculate_sunrise(double latitude, double longitude, date when)
+hour Location::calculate_sunrise(date when)
 {
    float Declanation;
    float solaroffset;
@@ -39,7 +41,7 @@ hour calculate_sunrise(double latitude, double longitude, date when)
 
 // Calculate the time of sunset in timezone UTC.
 
-hour calculate_sunset(double latitude, double longitude, date when)
+hour Location::calculate_sunset(date when)
 {
    float Declanation;
    float solaroffset;
@@ -70,3 +72,27 @@ hour calculate_sunset(double latitude, double longitude, date when)
 
 }
 
+UTC Location::utc_to_localtime(date when, hour utc_time)
+{
+   struct tm tp_utc;
+   time_t    utc_t;
+   struct tm *local_tm;
+
+
+   tp_utc.tm_year = when.Year() - 1900;
+   tp_utc.tm_mon  = when.Month() - 1;
+   tp_utc.tm_mday = when.Day();
+   tp_utc.tm_hour = utc_time.Hour();
+   tp_utc.tm_min  = utc_time.Minute();
+   tp_utc.tm_sec  = utc_time.Second();
+   tp_utc.tm_isdst = -1;
+
+   utc_t = timegm(&tp_utc);
+
+   local_tm = localtime(&utc_t);
+   UTC local_time(mktime(local_tm));
+
+   return local_time;
+
+}
+