diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-21 00:11:28 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-21 00:11:43 -0500 |
commit | 68f17c89705ac3b4e6c685807d8e799684e2b136 (patch) | |
tree | 62b48418bb952884edf97dcaee11831648de9bc8 /watch-library | |
parent | 3efdcd78a1fd470ca47fdd30c3251170d2f4f03b (diff) | |
download | Sensor-Watch-68f17c89705ac3b4e6c685807d8e799684e2b136.tar.gz Sensor-Watch-68f17c89705ac3b4e6c685807d8e799684e2b136.tar.bz2 Sensor-Watch-68f17c89705ac3b4e6c685807d8e799684e2b136.zip |
movement: add time zone conversion in sunrise/sunset face
Diffstat (limited to 'watch-library')
-rw-r--r-- | watch-library/watch/watch_utility.c | 5 | ||||
-rw-r--r-- | watch-library/watch/watch_utility.h | 11 |
2 files changed, 16 insertions, 0 deletions
diff --git a/watch-library/watch/watch_utility.c b/watch-library/watch/watch_utility.c index 02dbfb25..835076d9 100644 --- a/watch-library/watch/watch_utility.c +++ b/watch-library/watch/watch_utility.c @@ -146,6 +146,11 @@ watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint3 return retval; } +watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset) { + uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, origin_utc_offset); + return watch_utility_date_time_from_unix_time(timestamp, destination_utc_offset); +} + float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance) { float reading = (float)value; diff --git a/watch-library/watch/watch_utility.h b/watch-library/watch/watch_utility.h index 0a8f2b13..66af6ed5 100644 --- a/watch-library/watch/watch_utility.h +++ b/watch-library/watch/watch_utility.h @@ -70,6 +70,17 @@ uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, uint32_ */ watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint32_t utc_offset); +/** @brief Converts a time from a given time zone to another time zone. + * @param date_time The watch_date_time that you wish to convert + * @param origin_utc_offset The number of seconds from UTC in the origin time zone + * @param destination_utc_offset The number of seconds from UTC in the destination time zone + * @return A watch_date_time for the given UNIX timestamp and UTC offset, or if outside the range that + * watch_date_time can represent, a watch_date_time with all fields set to 0. + * @note Adapted from MIT-licensed code from musl, Copyright © 2005-2014 Rich Felker, et al.: + * https://github.com/esmil/musl/blob/1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6/src/time/__secs_to_tm.c + */ +watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset); + /** @brief Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit. * @param value The raw analog reading from the thermistor pin (0-65535) * @param highside True if the thermistor is connected to VCC and the series resistor is connected |