Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Itinerary
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
20
Issues
20
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PIM
Itinerary
Commits
43b95df6
Commit
43b95df6
authored
Jan 05, 2019
by
Volker Krause
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse Hafas past-midnight time format correctly
parent
410335fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
20 deletions
+46
-20
autotests/hafasparsertest.cpp
autotests/hafasparsertest.cpp
+21
-0
src/publictransport/backends/hafasmgateparser.cpp
src/publictransport/backends/hafasmgateparser.cpp
+23
-20
src/publictransport/backends/hafasmgateparser.h
src/publictransport/backends/hafasmgateparser.h
+2
-0
No files found.
autotests/hafasparsertest.cpp
View file @
43b95df6
...
...
@@ -22,6 +22,8 @@
#include <QTest>
#include <QTimeZone>
#define s(x) QStringLiteral(x)
using
namespace
KPublicTransport
;
class
HafasParserTest
:
public
QObject
...
...
@@ -49,6 +51,25 @@ private Q_SLOTS:
QCOMPARE
(
p
.
error
(),
Reply
::
NotFoundError
);
QVERIFY
(
!
p
.
errorMessage
().
isEmpty
());
}
void
parseDateTime_data
()
{
QTest
::
addColumn
<
QString
>
(
"date"
);
QTest
::
addColumn
<
QString
>
(
"time"
);
QTest
::
addColumn
<
QDateTime
>
(
"dt"
);
QTest
::
newRow
(
"empty"
)
<<
QString
()
<<
QString
()
<<
QDateTime
();
QTest
::
newRow
(
"same day"
)
<<
s
(
"20190105"
)
<<
s
(
"142100"
)
<<
QDateTime
({
2019
,
1
,
5
},
{
14
,
21
});
QTest
::
newRow
(
"next day"
)
<<
s
(
"20190105"
)
<<
s
(
"01142100"
)
<<
QDateTime
({
2019
,
1
,
6
},
{
14
,
21
});
}
void
parseDateTime
()
{
QFETCH
(
QString
,
date
);
QFETCH
(
QString
,
time
);
QFETCH
(
QDateTime
,
dt
);
QCOMPARE
(
HafasMgateParser
::
parseDateTime
(
date
,
time
),
dt
);
}
};
QTEST_GUILESS_MAIN
(
HafasParserTest
)
...
...
src/publictransport/backends/hafasmgateparser.cpp
View file @
43b95df6
...
...
@@ -135,16 +135,10 @@ std::vector<Departure> HafasMgateParser::parseStationBoardResponse(const QJsonOb
dep
.
setRoute
(
route
);
const
auto
dateStr
=
jnyObj
.
value
(
QLatin1String
(
"date"
)).
toString
();
dep
.
setScheduledDepartureTime
(
QDateTime
::
fromString
(
dateStr
+
stbStop
.
value
(
QLatin1String
(
"dTimeS"
)).
toString
(),
QLatin1String
(
"yyyyMMddhhmmss"
)));
const
auto
dTimeR
=
stbStop
.
value
(
QLatin1String
(
"dTimeR"
)).
toString
();
if
(
!
dTimeR
.
isEmpty
())
{
dep
.
setExpectedDepartureTime
(
QDateTime
::
fromString
(
dateStr
+
dTimeR
,
QLatin1String
(
"yyyyMMddhhmmss"
)));
}
dep
.
setScheduledArrivalTime
(
QDateTime
::
fromString
(
dateStr
+
stbStop
.
value
(
QLatin1String
(
"aTimeS"
)).
toString
(),
QLatin1String
(
"yyyyMMddhhmmss"
)));
const
auto
aTimeR
=
stbStop
.
value
(
QLatin1String
(
"aTimeR"
)).
toString
();
if
(
!
aTimeR
.
isEmpty
())
{
dep
.
setExpectedArrivalTime
(
QDateTime
::
fromString
(
dateStr
+
aTimeR
,
QLatin1String
(
"yyyyMMddhhmmss"
)));
}
dep
.
setScheduledDepartureTime
(
parseDateTime
(
dateStr
,
stbStop
.
value
(
QLatin1String
(
"dTimeS"
)).
toString
()));
dep
.
setExpectedDepartureTime
(
parseDateTime
(
dateStr
,
stbStop
.
value
(
QLatin1String
(
"dTimeR"
)).
toString
()));
dep
.
setScheduledArrivalTime
(
parseDateTime
(
dateStr
,
stbStop
.
value
(
QLatin1String
(
"aTimeS"
)).
toString
()));
dep
.
setExpectedArrivalTime
(
parseDateTime
(
dateStr
,
stbStop
.
value
(
QLatin1String
(
"aTimeR"
)).
toString
()));
dep
.
setScheduledPlatform
(
stbStop
.
value
(
QLatin1String
(
"dPlatfS"
)).
toString
());
dep
.
setExpectedPlatform
(
stbStop
.
value
(
QLatin1String
(
"dPlatfR"
)).
toString
());
...
...
@@ -271,11 +265,8 @@ std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj) c
JourneySection
section
;
const
auto
dep
=
secObj
.
value
(
QLatin1String
(
"dep"
)).
toObject
();
section
.
setScheduledDepartureTime
(
QDateTime
::
fromString
(
dateStr
+
dep
.
value
(
QLatin1String
(
"dTimeS"
)).
toString
(),
QLatin1String
(
"yyyyMMddhhmmss"
)));
const
auto
dTimeR
=
dep
.
value
(
QLatin1String
(
"dTimeR"
)).
toString
();
if
(
!
dTimeR
.
isEmpty
())
{
section
.
setExpectedDepartureTime
(
QDateTime
::
fromString
(
dateStr
+
dTimeR
,
QLatin1String
(
"yyyyMMddhhmmss"
)));
}
section
.
setScheduledDepartureTime
(
parseDateTime
(
dateStr
,
dep
.
value
(
QLatin1String
(
"dTimeS"
)).
toString
()));
section
.
setExpectedDepartureTime
(
parseDateTime
(
dateStr
,
dep
.
value
(
QLatin1String
(
"dTimeR"
)).
toString
()));
auto
locIdx
=
dep
.
value
(
QLatin1String
(
"locX"
)).
toInt
();
if
((
unsigned
int
)
locIdx
<
locs
.
size
())
{
section
.
setFrom
(
locs
[
locIdx
]);
...
...
@@ -284,11 +275,8 @@ std::vector<Journey> HafasMgateParser::parseTripSearch(const QJsonObject &obj) c
section
.
setExpectedDeparturePlatform
(
dep
.
value
(
QLatin1String
(
"dPlatfR"
)).
toString
());
const
auto
arr
=
secObj
.
value
(
QLatin1String
(
"arr"
)).
toObject
();
section
.
setScheduledArrivalTime
(
QDateTime
::
fromString
(
dateStr
+
arr
.
value
(
QLatin1String
(
"aTimeS"
)).
toString
(),
QLatin1String
(
"yyyyMMddhhmmss"
)));
const
auto
aTimeR
=
dep
.
value
(
QLatin1String
(
"aTimeR"
)).
toString
();
if
(
!
aTimeR
.
isEmpty
())
{
section
.
setExpectedArrivalTime
(
QDateTime
::
fromString
(
dateStr
+
aTimeR
,
QLatin1String
(
"yyyyMMddhhmmss"
)));
}
section
.
setScheduledArrivalTime
(
parseDateTime
(
dateStr
,
arr
.
value
(
QLatin1String
(
"aTimeS"
)).
toString
()));
section
.
setExpectedArrivalTime
(
parseDateTime
(
dateStr
,
arr
.
value
(
QLatin1String
(
"aTimeR"
)).
toString
()));
locIdx
=
arr
.
value
(
QLatin1String
(
"locX"
)).
toInt
();
if
((
unsigned
int
)
locIdx
<
locs
.
size
())
{
section
.
setTo
(
locs
[
locIdx
]);
...
...
@@ -332,3 +320,18 @@ QString HafasMgateParser::errorMessage() const
{
return
m_errorMsg
;
}
QDateTime
HafasMgateParser
::
parseDateTime
(
const
QString
&
date
,
const
QString
&
time
)
{
if
(
date
.
isEmpty
()
||
time
.
isEmpty
())
{
return
{};
}
int
dayOffset
=
0
;
if
(
time
.
size
()
>
6
)
{
dayOffset
=
time
.
leftRef
(
time
.
size
()
-
6
).
toInt
();
}
const
auto
dt
=
QDateTime
::
fromString
(
date
+
time
.
rightRef
(
6
),
QLatin1String
(
"yyyyMMddhhmmss"
));
return
dt
.
addDays
(
dayOffset
);
}
src/publictransport/backends/hafasmgateparser.h
View file @
43b95df6
...
...
@@ -55,6 +55,8 @@ public:
Reply
::
Error
error
()
const
;
QString
errorMessage
()
const
;
static
QDateTime
parseDateTime
(
const
QString
&
date
,
const
QString
&
time
);
private:
Q_DISABLE_COPY
(
HafasMgateParser
)
std
::
vector
<
Departure
>
parseStationBoardResponse
(
const
QJsonObject
&
obj
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment