summaryrefslogtreecommitdiffstats
path: root/watch-library/watch/watch_utility.h
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2021-11-25 11:10:06 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2021-11-25 11:10:06 -0500
commitac43c1ca48ba4e8d645f040d9930e761558fdad5 (patch)
tree197a6bb3adf359c55a5dfea618782c12edf054df /watch-library/watch/watch_utility.h
parentaac7a2a85474fe70c89723a1755a2d0e74bffbaf (diff)
downloadSensor-Watch-ac43c1ca48ba4e8d645f040d9930e761558fdad5.tar.gz
Sensor-Watch-ac43c1ca48ba4e8d645f040d9930e761558fdad5.tar.bz2
Sensor-Watch-ac43c1ca48ba4e8d645f040d9930e761558fdad5.zip
utilities: convert unix timestamp to watch_date_time
Diffstat (limited to 'watch-library/watch/watch_utility.h')
-rw-r--r--watch-library/watch/watch_utility.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/watch-library/watch/watch_utility.h b/watch-library/watch/watch_utility.h
index 5374fb1c..0a8f2b13 100644
--- a/watch-library/watch/watch_utility.h
+++ b/watch-library/watch/watch_utility.h
@@ -60,6 +60,16 @@ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_
*/
uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, uint32_t utc_offset);
+/** @brief Returns the UNIX time (seconds since 1970) for a given watch_date_time struct.
+ * @param timestamp The UNIX timestamp that you wish to convert.
+ * @param utc_offset The number of seconds that you wish date_time to be offset from UTC.
+ * @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_from_unix_time(uint32_t timestamp, uint32_t 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