Skip to content
GitLab
Explore
Sign in
derf
Travel-Routing-DE-HAFAS
Compare revisions
e6480f632d07b30f4f3ee538731f157c922a16b2 to b7af35c24679ff46c92e96078d2e4d1930cb8b15
Commits on Source (2)
Convert non-local timestamps to local time zone
· f40128de
Birte Kristina Friesel
authored
Apr 02, 2024
f40128de
Section: add TRSF type (unspecified local transit)
· b7af35c2
Birte Kristina Friesel
authored
Apr 02, 2024
b7af35c2
Hide whitespace changes
Inline
Side-by-side
bin/hafas
View file @
b7af35c2
...
...
@@ -434,6 +434,14 @@ for my $res ( $hafas->connections ) {
$sec
->
duration
->
in_units
('
minutes
')
==
1
?
q{}
:
'
s
'
);
}
elsif
(
$sec
->
type
eq
'
TRSF
'
)
{
printf
(
"
${output_bold}
Transfer %.1fkm
${output_reset}
with local transit (approx. %d minute%s)
",
$sec
->
distance
/
1000
,
$sec
->
duration
->
in_units
('
minutes
'),
$sec
->
duration
->
in_units
('
minutes
')
==
1
?
q{}
:
'
s
'
);
}
else
{
printf
("
\n
???
\n
");
}
...
...
lib/Travel/Routing/DE/HAFAS/Connection.pm
View file @
b7af35c2
...
...
@@ -62,20 +62,30 @@ sub new {
);
# dProgType/aProgType: CORRECTED oder PROGNOSED
my
$sched_dep
=
$connection
->
{
dep
}{
dTimeS
};
my
$rt_dep
=
$connection
->
{
dep
}{
dTimeR
};
my
$sched_arr
=
$connection
->
{
arr
}{
aTimeS
};
my
$rt_arr
=
$connection
->
{
arr
}{
aTimeR
};
for
my
$ts
(
$sched_dep
,
$rt_dep
,
$sched_arr
,
$rt_arr
)
{
if
(
$ts
)
{
$ts
=
handle_day_change
(
date
=>
$date
,
time
=>
$ts
,
strp_obj
=>
$strptime
,
);
}
}
my
$sched_dep
=
handle_day_change
(
date
=>
$date
,
time
=>
$connection
->
{
dep
}{
dTimeS
},
offset
=>
$connection
->
{
dep
}{
dTZOffset
},
strp_obj
=>
$strptime
,
);
my
$rt_dep
=
handle_day_change
(
date
=>
$date
,
time
=>
$connection
->
{
dep
}{
dTimeR
},
offset
=>
$connection
->
{
dep
}{
dTZOffset
},
strp_obj
=>
$strptime
,
);
my
$sched_arr
=
handle_day_change
(
date
=>
$date
,
time
=>
$connection
->
{
arr
}{
aTimeS
},
offset
=>
$connection
->
{
arr
}{
aTZOffset
},
strp_obj
=>
$strptime
,
);
my
$rt_arr
=
handle_day_change
(
date
=>
$date
,
time
=>
$connection
->
{
arr
}{
aTimeR
},
offset
=>
$connection
->
{
arr
}{
aTZOffset
},
strp_obj
=>
$strptime
,
);
my
@sections
;
for
my
$sec
(
@secL
)
{
...
...
lib/Travel/Routing/DE/HAFAS/Connection/Section.pm
View file @
b7af35c2
...
...
@@ -58,20 +58,30 @@ sub new {
time_zone
=>
'
Europe/Berlin
'
);
my
$sched_dep
=
$sec
->
{
dep
}{
dTimeS
};
my
$rt_dep
=
$sec
->
{
dep
}{
dTimeR
};
my
$sched_arr
=
$sec
->
{
arr
}{
aTimeS
};
my
$rt_arr
=
$sec
->
{
arr
}{
aTimeR
};
for
my
$ts
(
$sched_dep
,
$rt_dep
,
$sched_arr
,
$rt_arr
)
{
if
(
$ts
)
{
$ts
=
handle_day_change
(
date
=>
$date
,
time
=>
$ts
,
strp_obj
=>
$strptime
,
);
}
}
my
$sched_dep
=
handle_day_change
(
date
=>
$date
,
time
=>
$sec
->
{
dep
}{
dTimeS
},
offset
=>
$sec
->
{
dep
}{
dTZOffset
},
strp_obj
=>
$strptime
,
);
my
$rt_dep
=
handle_day_change
(
date
=>
$date
,
time
=>
$sec
->
{
dep
}{
dTimeR
},
offset
=>
$sec
->
{
dep
}{
dTZOffset
},
strp_obj
=>
$strptime
,
);
my
$sched_arr
=
handle_day_change
(
date
=>
$date
,
time
=>
$sec
->
{
arr
}{
aTimeS
},
offset
=>
$sec
->
{
arr
}{
aTZOffset
},
strp_obj
=>
$strptime
,
);
my
$rt_arr
=
handle_day_change
(
date
=>
$date
,
time
=>
$sec
->
{
arr
}{
aTimeR
},
offset
=>
$sec
->
{
arr
}{
aTZOffset
},
strp_obj
=>
$strptime
,
);
my
$tco
=
{};
for
my
$tco_id
(
@
{
$sec
->
{
jny
}{
dTrnCmpSX
}{
tcocX
}
//
[]
}
)
{
...
...
@@ -116,7 +126,7 @@ sub new {
hafas
=>
$hafas
,
);
}
elsif
(
$sec
->
{
type
}
eq
'
WALK
'
)
{
elsif
(
$sec
->
{
type
}
eq
'
TRSF
'
or
$sec
->
{
type
}
eq
'
WALK
'
)
{
$ref
->
{
distance
}
=
$sec
->
{
gis
}{
dist
};
my
$duration
=
$sec
->
{
gis
}{
durS
};
$ref
->
{
duration
}
=
DateTime::
Duration
->
new
(
...
...
@@ -260,15 +270,15 @@ Travel::Status::DE::HAFAS::Location(3pm) object describing the departure stop.
=item $section->dep_platform
=item $section->distance (WALK)
=item $section->distance (
TRSF,
WALK)
W
alking distance in meters. Does not take vertical elevation
changes into
account.
Transfer or w
alking distance in meters. Does not take vertical elevation
changes into
account.
=item $section->duration (WALK)
=item $section->duration (
TRSF,
WALK)
DateTime::Duration(3pm) oobject holding the
walking duration.
Typically assumes a slow pace.
DateTime::Duration(3pm) oobject holding the
estimated transfer or walk
duration.
Typically assumes a slow pace.
=item $section->journey (JNY)
...
...
@@ -318,7 +328,8 @@ Undef for the first journey in a connection.
=item $section->type
Type of this section as exposeed by the HAFAS backend.
Known types: B<JNY> (a public transit journey) and B<WALK> (walking).
Known types: B<JNY> (a public transit journey), B<TRSF> (unspecified local
transit), and B<WALK> (walking).
=back
...
...
lib/Travel/Routing/DE/HAFAS/Utils.pm
View file @
b7af35c2
...
...
@@ -13,8 +13,13 @@ sub handle_day_change {
my
(
%opt
)
=
@_
;
my
$datestr
=
$opt
{
date
};
my
$timestr
=
$opt
{
time
};
my
$tz_offset
=
$opt
{
offset
};
my
$offset_days
=
0
;
if
(
not
defined
$timestr
)
{
return
;
}
# timestr may include a day offset, resulting in DDHHMMSS
if
(
length
(
$timestr
)
==
8
)
{
$offset_days
=
substr
(
$timestr
,
0
,
2
,
q{}
);
...
...
@@ -26,6 +31,11 @@ sub handle_day_change {
$ts
->
add
(
days
=>
$offset_days
);
}
if
(
defined
$tz_offset
and
$tz_offset
!=
$ts
->
offset
/
60
)
{
my
$ts_offset
=
$tz_offset
-
$ts
->
offset
/
60
;
$ts
->
subtract
(
minutes
=>
$ts_offset
);
}
return
$ts
;
}
...
...