@@ -50,7 +50,6 @@ Weather::Weather(Controllers::Settings& settingsController,
50
50
lastUpdated = lv_label_create (lv_scr_act (), nullptr );
51
51
lv_obj_set_style_local_text_color (lastUpdated, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
52
52
lv_label_set_text_fmt (lastUpdated, " " );
53
- lv_obj_align (lastUpdated, nullptr , LV_ALIGN_CENTER, -40 , -1 );
54
53
55
54
minTemperature = lv_label_create (lv_scr_act (), nullptr );
56
55
lv_obj_set_style_local_text_color (minTemperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
@@ -145,21 +144,33 @@ void Weather::Refresh() {
145
144
lv_label_set_text_fmt (minTemperature, " %d°" , minTemp);
146
145
lv_label_set_text_fmt (maxTemperature, " %d°" , maxTemp);
147
146
148
- int64_t secondsSinceEpoch = dateTimeController.CurrentDateTime ().time_since_epoch ().count () / 1000000000 ;
149
- int64_t secondsSinceWeatherUpdate = secondsSinceEpoch - optCurrentWeather->timestamp ;
150
- if (secondsSinceWeatherUpdate < 0 ) {
151
- lv_label_set_text_fmt (lastUpdated, " 0s ago" , secondsSinceWeatherUpdate);
152
- } else if (secondsSinceWeatherUpdate < 60 ) {
147
+ std::chrono::seconds secondsSinceEpoch =
148
+ std::chrono::duration_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime ().time_since_epoch ());
149
+ int32_t secondsSinceWeatherUpdate = secondsSinceEpoch.count () - optCurrentWeather->timestamp ;
150
+ int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60 ;
151
+ int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600 ;
152
+
153
+ lv_obj_align (lastUpdated, nullptr , LV_ALIGN_CENTER, -31 , -1 );
154
+ if ((secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60 ) ||
155
+ (minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60 ) || hoursSinceWeatherUpdate > 9 ) {
156
+ lv_obj_align (lastUpdated, nullptr , LV_ALIGN_CENTER, -41 , -1 );
157
+ }
158
+
159
+ if (hoursSinceWeatherUpdate > 0 ) {
160
+ lv_label_set_text_fmt (lastUpdated, " %dh ago" , hoursSinceWeatherUpdate);
161
+ } else if (minutesSinceWeatherUpdate > 0 ) {
162
+ lv_label_set_text_fmt (lastUpdated, " %dm ago" , minutesSinceWeatherUpdate);
163
+ } else if (secondsSinceWeatherUpdate > 30 ) {
153
164
lv_label_set_text_fmt (lastUpdated, " %ds ago" , secondsSinceWeatherUpdate);
154
- } else if (secondsSinceWeatherUpdate > 59 && secondsSinceWeatherUpdate < 3600 ) {
155
- lv_label_set_text_fmt (lastUpdated, " %dm ago" , secondsSinceWeatherUpdate / 60 );
156
- } else if (secondsSinceWeatherUpdate > 3599 ) {
157
- lv_label_set_text_fmt (lastUpdated, " %dh ago" , secondsSinceWeatherUpdate / 3600 );
165
+ } else if (secondsSinceWeatherUpdate < 31 ) {
166
+ lv_obj_align (lastUpdated, nullptr , LV_ALIGN_CENTER, -18 , -1 );
167
+ lv_label_set_text_fmt (lastUpdated, " Now" , secondsSinceWeatherUpdate);
158
168
}
159
169
} else {
160
170
lv_label_set_text (icon, " " );
161
171
lv_label_set_text (condition, " " );
162
172
lv_label_set_text (temperature, " ---" );
173
+ lv_label_set_text (lastUpdated, " " );
163
174
lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
164
175
lv_label_set_text (minTemperature, " " );
165
176
lv_label_set_text (maxTemperature, " " );
0 commit comments