Ticket #8356: localtime.patch

File localtime.patch, 2.3 KB (added by Alec leamas <gmail: leamas.alec>, 14 years ago)
  • install.sh

    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  
    11#!/bin/sh
    22set -x
    3 sudo cp libmythweather.so /usr/lib64/mythtv/plugins/libmythweather.so
     3sudo cp mythweather/libmythweather.so /usr/lib64/mythtv/plugins/libmythweather.so
  • mythweather/weatherScreen.cpp

    diff --git a/mythweather/weatherScreen.cpp b/mythweather/weatherScreen.cpp
    index 63b297c..6df81a0 100644
    a b using namespace std; 
    99#include "weather.h"
    1010#include "weatherScreen.h"
    1111
     12/** Parse and format time according to current locale. */
     13static 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
    1245WeatherScreen *WeatherScreen::loadScreen(MythScreenStack *parent,
    1346                                         ScreenListInfo *screenDefn, int id)
    1447{
    void WeatherScreen::prepareWidget(MythUIType *widget) 
    155188    }
    156189}
    157190
     191
     192
    158193QString WeatherScreen::formatDataItem(const QString &key, const QString &value)
    159194{
     195    if (key.startsWith("time-"))
     196        return formatTime( value);
     197
    160198    if (key == "relative_humidity")
    161199        return value + " %";
    162200