Localised time display in 18-hours forecast.
From: Alec Leamas <leamas.alec%AT%gmail.com>
Format is governed by current locale settings, on many
(all?) platforms this is the LC_TIME environment variable.
---
install.sh | 2 +-
mythweather/weatherScreen.cpp | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/install.sh b/install.sh
index 5db2c41..86fbe0e 100755
a
|
b
|
|
1 | 1 | #!/bin/sh |
2 | 2 | set -x |
3 | | sudo cp libmythweather.so /usr/lib64/mythtv/plugins/libmythweather.so |
| 3 | sudo cp mythweather/libmythweather.so /usr/lib64/mythtv/plugins/libmythweather.so |
diff --git a/mythweather/weatherScreen.cpp b/mythweather/weatherScreen.cpp
index 63b297c..6df81a0 100644
a
|
b
|
using namespace std; |
9 | 9 | #include "weather.h" |
10 | 10 | #include "weatherScreen.h" |
11 | 11 | |
| 12 | /** Parse and format time according to current locale. */ |
| 13 | static QString formatTime(const QString& value) |
| 14 | { |
| 15 | struct tm tm; |
| 16 | char buff[128]; |
| 17 | QString datetime; |
| 18 | time_t now = time(NULL); |
| 19 | |
| 20 | localtime_r(&now, &tm); |
| 21 | strftime(buff, sizeof(buff), "%x", &tm); |
| 22 | datetime = QString(buff) + " " + value; |
| 23 | |
| 24 | const char* t = const_cast< char *>(datetime.toAscii().data()); |
| 25 | if (strptime( t, "%x%n%I %p", &tm) != NULL) |
| 26 | { |
| 27 | tm.tm_min = 0; |
| 28 | } |
| 29 | else if ((strptime( t, "%x%n%I:%M %p", &tm) == NULL) && |
| 30 | (strptime( t, "%x%n%H:%M", &tm) == NULL)) |
| 31 | { |
| 32 | return value; |
| 33 | } |
| 34 | |
| 35 | strftime( buff, sizeof(buff), "%X", &tm); |
| 36 | QString result(buff); |
| 37 | if (result.contains( QRegExp("[0-9]$"))) |
| 38 | strftime(buff, sizeof(buff), "%H:%M", &tm); |
| 39 | else |
| 40 | strftime(buff, sizeof(buff), "%l %p", &tm); |
| 41 | |
| 42 | return QString(buff); |
| 43 | } |
| 44 | |
12 | 45 | WeatherScreen *WeatherScreen::loadScreen(MythScreenStack *parent, |
13 | 46 | ScreenListInfo *screenDefn, int id) |
14 | 47 | { |
… |
… |
void WeatherScreen::prepareWidget(MythUIType *widget) |
155 | 188 | } |
156 | 189 | } |
157 | 190 | |
| 191 | |
| 192 | |
158 | 193 | QString WeatherScreen::formatDataItem(const QString &key, const QString &value) |
159 | 194 | { |
| 195 | if (key.startsWith("time-")) |
| 196 | return formatTime( value); |
| 197 | |
160 | 198 | if (key == "relative_humidity") |
161 | 199 | return value + " %"; |
162 | 200 | |