Minor updates for versions 0.2.1 and 0.2.2. See changelog file.
[movie-schedule] / src / searchclients / movieschedulesearchclient.cpp
index cb2ac42..7041c5e 100644 (file)
@@ -90,7 +90,7 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply)
     QString theater_name;
     QString theater_address;
     QString theater_phone;
-    QList<QTime> schedule;
+    QList<QString> schedule;
     QRegExp time_pattern("\\d+:\\d+([aApP][mM])*");
     while (!xml.atEnd()) {
         QXmlStreamReader::TokenType token = xml.readNext();
@@ -164,8 +164,14 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply)
                             if (!theater_phone.isEmpty()) {
                                 cinema->SetTelephone(theater_phone);
                             }
-                            Q_FOREACH(const QTime time, schedule) {
-                                _cinema_schedule->AddSchedule(cinema, movie, time, _date);
+                            QList<QTime> schedule_times = TimesFromString(schedule);
+                            Q_FOREACH(const QTime time, schedule_times) {
+                                if (time.hour() < 3) {
+                                    // interpret very early times as shifted by 1 day (seems to be a Google logic)
+                                    _cinema_schedule->AddSchedule(cinema, movie, time, _date.addDays(1));
+                                } else {
+                                    _cinema_schedule->AddSchedule(cinema, movie, time, _date);
+                                }
                             }
                         }
                     }
@@ -185,11 +191,8 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply)
                 while ((i = time_pattern.indexIn(t, i)) != -1) {
                     int length = time_pattern.matchedLength();
                     //std::cout << "time " << qPrintable(t.mid(i, length)) << std::endl;
-                    QTime time = TimeUtils::FromTimeString(t.mid(i, length));
-                    if (time.isValid()) {
-                        schedule.append(time);
-                    } else {
-                        std::cout << "ERROR: time " << qPrintable(t.mid(i, length)) << " is invalid." << std::endl;
+                    if (length > 0) {
+                        schedule.append(t.mid(i, length));
                     }
                     i += length;
                     found = true;