Ticket #9676: mythsecsto.3.patch

File mythsecsto.3.patch, 1.7 KB (added by mythtv@…, 15 years ago)

calc_utc_offset relied on the bug the patch fixes. Update it to match

  • 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;