summaryrefslogtreecommitdiff
path: root/libsowatch/weathernotification.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsowatch/weathernotification.cpp')
-rw-r--r--libsowatch/weathernotification.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/libsowatch/weathernotification.cpp b/libsowatch/weathernotification.cpp
index fa82f3d..ddfd60b 100644
--- a/libsowatch/weathernotification.cpp
+++ b/libsowatch/weathernotification.cpp
@@ -6,3 +6,24 @@ WeatherNotification::WeatherNotification(QObject *parent) :
Notification(parent)
{
}
+
+qreal WeatherNotification::convertTemperature(qreal temp, Unit from, Unit to)
+{
+ if (from == to) {
+ return temp;
+ } else if (from == Celsius && to == Fahrenheit) {
+ return temp * (9.0f/5.0f) + 32.0f;
+ } else if (from == Fahrenheit && to == Celsius) {
+ return (temp - 32.0f) * (5.0f/9.0f);
+ }
+}
+
+
+int WeatherNotification::convertTemperature(int temp, Unit from, Unit to)
+{
+ if (from == to) {
+ return temp;
+ } else {
+ return qRound(convertTemperature(static_cast<qreal>(temp), from, to));
+ }
+}