summaryrefslogtreecommitdiffstats
path: root/watch-library
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2021-11-25 10:06:49 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2021-11-25 10:36:01 -0500
commit5c3967aea28dff5a2731a28862c5cae3b995f875 (patch)
treee4ff92e50234f3adf300f66722bd9ac8bd360599 /watch-library
parent4a71def034590236b8a3527960cb2331876529a5 (diff)
downloadSensor-Watch-5c3967aea28dff5a2731a28862c5cae3b995f875.tar.gz
Sensor-Watch-5c3967aea28dff5a2731a28862c5cae3b995f875.tar.bz2
Sensor-Watch-5c3967aea28dff5a2731a28862c5cae3b995f875.zip
movement: implement time zone setting
Diffstat (limited to 'watch-library')
-rw-r--r--watch-library/watch/watch_utility.c6
-rw-r--r--watch-library/watch/watch_utility.h1
2 files changed, 6 insertions, 1 deletions
diff --git a/watch-library/watch/watch_utility.c b/watch-library/watch/watch_utility.c
index df808404..82ea5a6b 100644
--- a/watch-library/watch/watch_utility.c
+++ b/watch-library/watch/watch_utility.c
@@ -51,6 +51,7 @@ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_
334 // December
};
+ printf("input: %d/%d/%d %d:%02d:%02d offset by %ld\n", year, month, day, hour, minute, second, utc_offset);
uint32_t year_adj = year + 4800;
uint32_t febs = year_adj - (month <= 2 ? 1 : 0); /* Februaries since base. */
@@ -59,9 +60,12 @@ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_
days -= 2472692; /* Adjust to Unix epoch. */
uint32_t timestamp = days * 86400;
- timestamp += (hour + utc_offset) * 3600;
+ timestamp += hour * 3600;
timestamp += minute * 60;
timestamp += second;
+ printf("timestamp was %ld.\ntimezone is %ld.\n", timestamp, utc_offset);
+ timestamp -= utc_offset;
+ printf("timestamp now %ld.\n\n", timestamp);
return timestamp;
}
diff --git a/watch-library/watch/watch_utility.h b/watch-library/watch/watch_utility.h
index a6035dc3..5374fb1c 100644
--- a/watch-library/watch/watch_utility.h
+++ b/watch-library/watch/watch_utility.h
@@ -46,6 +46,7 @@ const char * watch_utility_get_weekday(watch_date_time date_time);
* @param hour The hour of the date you wish to convert.
* @param minute The minute of the date you wish to convert.
* @param second The second of the date you wish to convert.
+ * @param utc_offset The number of seconds that date_time is offset from UTC, or 0 if the time is UTC.
* @return A UNIX timestamp for the given date/time and UTC offset.
* @note Implemented by Wesley Ellis (tahnok) and based on BSD-licensed code by Josh Haberman:
* https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html