Ticket #9676: eithelper.patch

File eithelper.patch, 2.8 KB (added by mythtv@…, 15 years ago)

Patch including a fix to EITHelper

  • mythtv/libs/libmyth/util.cpp

    diff --git a/mythtv/libs/libmyth/util.cpp b/mythtv/libs/libmyth/util.cpp
    index c5358b0..84fb8eb 100644
    a b QDateTime myth_dt_from_string(const QString &dtstr)  
    8484    return QDateTime::fromString(dtstr, Qt::ISODate);
    8585}
    8686
     87// Note: this function calculates the offset from UTC "right now". That offset
     88// may not be valid a moment later, since daylight savings time might start or
     89// end during that moment. Thus it's not valid to use this in calculations of
     90// future events, like program guide data
    8791int calc_utc_offset(void)
    8892{
     93
    8994    QDateTime loc = QDateTime::currentDateTime();
    90     QDateTime utc = QDateTime::currentDateTime().toUTC();
     95    QDateTime utc = loc; // make an exact copy so elapsed time doesn't factor in
     96    utc.setTimeSpec(Qt::UTC); // keeping same clock time, change only the time zone
    9197
    92     int utc_offset = MythSecsTo(utc, loc);
     98    int utc_offset = MythSecsTo(loc, utc);
    9399
    94100    // clamp to nearest minute if within 10 seconds
    95101    int off = utc_offset % 60;
    bool checkTimeZone(const QStringList &master_settings)  
    529535 */
    530536int MythSecsTo(const QDateTime &from, const QDateTime &to)
    531537{
    532    return (from.time().secsTo(to.time()) +
    533            from.date().daysTo(to.date()) * 60 * 60 * 24);
     538   return (from.secsTo(to));
    534539}
    535540
    536541/** \fn MythUTCToLocal(const QDateTime&)
    int MythSecsTo(const QDateTime &from, const QDateTime &to)  
    538543 */
    539544QDateTime MythUTCToLocal(const QDateTime &utc)
    540545{
    541     QDateTime local = QDateTime(QDate(1970, 1, 1));
     546    QDateTime local = QDateTime(QDate(1970, 1, 1),QTime(0,0,0),Qt::UTC);
    542547
    543548    int timesecs = MythSecsTo(local, utc);
    544549    QDateTime localdt;
  • mythtv/libs/libmythtv/eithelper.cpp

    diff --git a/mythtv/libs/libmythtv/eithelper.cpp b/mythtv/libs/libmythtv/eithelper.cpp
    index b3a9974..d672d7d 100644
    a b void EITHelper::CompleteEvent(uint atsc_major, uint atsc_minor,  
    620620        return;
    621621
    622622    QDateTime starttime;
    623     time_t off = secs_Between_1Jan1970_6Jan1980 + gps_offset + utc_offset;
     623    time_t off = secs_Between_1Jan1970_6Jan1980 + gps_offset;
    624624    time_t tmp = event.start_time + off;
    625625    tm result;
    626626
    void EITHelper::CompleteEvent(uint atsc_major, uint atsc_minor,  
    630630                                result.tm_mon + 1,
    631631                                result.tm_mday));
    632632        starttime.setTime(QTime(result.tm_hour, result.tm_min, result.tm_sec));
     633        starttime.setTimeSpec(Qt::UTC);
    633634    }
    634635    else
    635636    {
    636         starttime.setTime_t(tmp - utc_offset);
     637        starttime.setTime_t(tmp);
    637638    }
     639    starttime = MythUTCToLocal(starttime);
    638640
    639641    // fix starttime only if the duration is a multiple of a minute
    640642    if (!(event.length % 60))