[mythtv] [PATCH] mythfilldatabase: add support for minutes in
TimeOffset
Stefan Frank
sfr+lists at 6913304088794.gnuu.de
Sun Aug 10 00:18:37 EDT 2003
Here's the first result of my efforts learning C++.
As $subject says, this makes mythtv usage easier in some parts of the world.
It also fixes a bug where invalid timestamps would be changed to
00000000000000 + TimeOffset
Now they are left as is.
If noone objects or finds bugs (it works for me) i'd like it applied to CVS.
Bye, Stefan
--
"I have to convince you, or at least snow you ..."
-- Prof. Romas Aleliunas, CS 435
-------------- next part --------------
--- mythtv/setup/backendsettings.cpp 2003-08-03 17:06:20.000000000 +0200
+++ mythtv-local/setup/backendsettings.cpp 2003-08-09 17:50:18.000000000 +0200
@@ -244,29 +244,52 @@
setLabel("Time offset for XMLTV listings");
addSelection("None", "");
addSelection("Auto");
+ addSelection("+0030");
addSelection("+0100");
+ addSelection("+0130");
addSelection("+0200");
+ addSelection("+0230");
addSelection("+0300");
+ addSelection("+0330");
addSelection("+0400");
+ addSelection("+0430");
addSelection("+0500");
+ addSelection("+0530");
addSelection("+0600");
+ addSelection("+0630");
addSelection("+0700");
+ addSelection("+0730");
addSelection("+0800");
+ addSelection("+0830");
addSelection("+0900");
+ addSelection("+0930");
addSelection("+1000");
+ addSelection("+1030");
addSelection("+1100");
+ addSelection("+1130");
addSelection("+1200");
addSelection("-1100");
+ addSelection("-1030");
addSelection("-1000");
+ addSelection("-0930");
addSelection("-0900");
+ addSelection("-0830");
addSelection("-0800");
+ addSelection("-0730");
addSelection("-0700");
+ addSelection("-0630");
addSelection("-0600");
+ addSelection("-0530");
addSelection("-0500");
+ addSelection("-0430");
addSelection("-0400");
+ addSelection("-0330");
addSelection("-0300");
+ addSelection("-0230");
addSelection("-0200");
+ addSelection("-0130");
addSelection("-0100");
+ addSelection("-0030");
setHelpText("If your local timezone does not match the timezone "
"returned by XMLTV, use this setting to have "
"mythfilldatabase adjust the program start and end times."
--- mythtv/programs/mythfilldatabase/filldata.cpp 2003-08-03 17:06:19.000000000 +0200
+++ mythtv-local/programs/mythfilldatabase/filldata.cpp 2003-08-09 18:15:33.000000000 +0200
@@ -265,29 +265,64 @@
return chaninfo;
}
+int TimezoneToInt (QString timezone)
+{
+ // we signal an error by setting it invalid (> 720min = 12hr)
+ int result = 721;
+
+ if (timezone.length() == 5)
+ {
+ bool ok;
+
+ result = timezone.mid(1,2).toInt(&ok, 10);
+
+ if (!ok)
+ result = 721;
+ else
+ {
+ result *= 60;
+
+ int min = timezone.right(2).toInt(&ok, 10);
+
+ if (!ok)
+ result = 721;
+ else
+ {
+ result += min;
+ if (timezone.left(1) == "-")
+ result *= -1;
+ }
+ }
+ }
+
+ return result;
+
+}
+
void addTimeOffset(QString ×tr, int localTimezoneOffset)
{
- if (timestr.isEmpty() || localTimezoneOffset < -12 ||
- localTimezoneOffset > 12)
+ if (timestr.isEmpty() || abs(localTimezoneOffset) > 720)
return;
- bool ok;
-
QStringList split = QStringList::split(" ", timestr);
QString ts = split[0];
int ts_offset = localTimezoneOffset;
if (split.size() > 1)
{
QString tmp = split[1];
- ts_offset = tmp.stripWhiteSpace().left(3).toInt(&ok, 10);
- if (!ok)
- ts_offset = localTimezoneOffset;
+ tmp.stripWhiteSpace();
+
+ ts_offset = TimezoneToInt(tmp);
+ if (abs(ts_offset) > 720)
+ ts_offset = localTimezoneOffset;
}
- if (ts_offset != localTimezoneOffset)
+ int diff = localTimezoneOffset - ts_offset;
+ int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
+
+ if (diff != 0)
{
- int diff = localTimezoneOffset - ts_offset;
- int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
+ bool ok;
if (ts.length() == 14)
{
@@ -309,12 +344,16 @@
}
else
{
- cerr << "Unknown timestamp format: " << ts << endl;
+ diff = 0;
+ cerr << "Ignoring unknown timestamp format: " << ts << endl;
}
-
- QDateTime dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec));
- dt = dt.addSecs(diff * 60 * 60);
- timestr = dt.toString("yyyyMMddhhmmss");
+ }
+
+ if (diff != 0)
+ {
+ QDateTime dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec));
+ dt = dt.addSecs(diff * 60 );
+ timestr = dt.toString("yyyyMMddhhmmss");
}
}
@@ -501,26 +540,21 @@
// now we calculate the localTimezoneOffset, so that we can fix
// the programdata if needed
QString config_offset = gContext->GetSetting("TimeOffset", "None");
- int localTimezoneOffset = 13;
+ // we disable this feature by setting it invalid (> 720min = 12hr)
+ int localTimezoneOffset = 721;
- if (config_offset == "None")
- {
- // we disable this feature by setting it invalid
- localTimezoneOffset = 13;
- }
- else if (config_offset == "Auto")
+ if (config_offset == "Auto")
{
time_t now = time(NULL);
struct tm local_tm;
localtime_r(&now, &local_tm);
- localTimezoneOffset = local_tm.tm_gmtoff / 3600;
+ localTimezoneOffset = local_tm.tm_gmtoff / 60;
}
- else
+ else if (config_offset != "None")
{
- bool ok;
- localTimezoneOffset = config_offset.left(3).toInt(&ok, 10);
- if (!ok)
- localTimezoneOffset = 13;
+ localTimezoneOffset = TimezoneToInt(config_offset);
+ if (abs(localTimezoneOffset) > 720)
+ cerr << "Ignoring invalid TimeOffset " << config_offset << endl;
}
QDomElement docElem = doc.documentElement();
More information about the mythtv-dev
mailing list