Changeset 7ba0378


Ignore:
Timestamp:
09/13/17 23:28:44 (5 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master
Children:
d03ca41
Parents:
f0f9fdc
git-author:
Philipp Spitzer <philipp@…> (09/13/17 23:20:23)
git-committer:
Philipp Spitzer <philipp@…> (09/13/17 23:28:44)
Message:

Import schedules with dates attached to events correctly.

Location:
src/sql
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sql/schedulexmlparser.cpp

    rf0f9fdc r7ba0378  
    2121#include <QDomDocument>
    2222#include <QHash>
     23#include <QTime>
    2324
    2425#include "schedulexmlparser.h"
     
    5152    {
    5253        QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
     54        QTime conference_day_change;
    5355        if (!conferenceElement.isNull())
    5456        {
     
    6870            conferenceId = conference["id"].toInt();
    6971            conference_title = conference["title"];
     72            conference_day_change = QTime(0, 0).addSecs(conference["day_change"].toInt());
    7073        }
    7174
     
    109112                        event["id"] = eventElement.attribute("id");;
    110113                        event["conference_id"] = QString::number(conferenceId, 10);
    111                         event["start"] = eventElement.firstChildElement("start").text(); // time eg. 10:00
    112                         event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07
     114                        QTime event_start = QTime::fromString(eventElement.firstChildElement("start").text(), sqlEngine->TIME_FORMAT);
     115                        event["start"] = event_start.toString(sqlEngine->TIME_FORMAT); // time eg. 10:00
     116                        QDate event_date;
     117                        QDomElement eventDateElement = eventElement.firstChildElement("date");
     118                        if (!eventDateElement.isNull()) {
     119                            QString date_str = eventDateElement.text(); // date eg. 2009-02-07T10:00:00+00:00
     120                            event_date = QDate::fromString(date_str.left(sqlEngine->DATE_FORMAT.size()), sqlEngine->DATE_FORMAT);
     121                        } else {
     122                            event_date = QDate::fromString(dayElement.attribute("date"),sqlEngine->DATE_FORMAT); // date eg. 2009-02-07
     123                            if (event_start < conference_day_change) event_date = event_date.addDays(1);
     124                        }
     125                        event["date"] = event_date.toString(sqlEngine->DATE_FORMAT); // date eg. 2009-02-07
    113126                        event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30
    114127                        event["room_name"] = eventElement.firstChildElement("room").text(); // string eg. "Janson"
  • src/sql/sqlengine.cpp

    rf0f9fdc r7ba0378  
    3838#include <QDebug>
    3939
    40 const QString DATE_FORMAT ("yyyy-MM-dd");
    41 const QString TIME_FORMAT ("hh:mm");
    42 
    4340SqlEngine::SqlEngine(QObject *aParent): QObject(aParent) {
    4441#if QT_VERSION >= 0x050000
     
    193190    QDate startDate = QDate::fromString(aEvent["date"], DATE_FORMAT);
    194191    QTime startTime = QTime::fromString(aEvent["start"], TIME_FORMAT);
    195     // consider day_change (note that if day_change is e.g. at 04:00 AM, an event starting at 02:00 AM has the previous date in the XML file)
    196     if (startTime < conference.dayChangeTime()) startDate = startDate.addDays(1);
    197192    QDateTime startDateTime;
    198193    startDateTime.setTimeSpec(Qt::UTC);
  • src/sql/sqlengine.h

    rf0f9fdc r7ba0378  
    2929    Q_OBJECT
    3030    public:
     31        const QString DATE_FORMAT = "yyyy-MM-dd";
     32        const QString TIME_FORMAT = "hh:mm";
     33
    3134        QString dbFilename; ///< database filename including path
    3235        QSqlDatabase db; ///< this may be private one day...
Note: See TracChangeset for help on using the changeset viewer.