blob: 45ee5db059c9aeec221b90627b3da6d50e9df015 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package Travel::Routing::DE::HAFAS::Utils;
# vim:foldmethod=marker
use strict;
use warnings;
use 5.014;
use parent 'Exporter';
our @EXPORT = qw(handle_day_change);
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{} );
}
my $ts = $opt{strp_obj}->parse_datetime("${datestr}T${timestr}");
if ($offset_days) {
$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;
}
1;
__END__
=head1 NAME
Travel::Routing::DE::HAFAS::Utils - Internal Travel::Routing::DE::HAFAS utilities
=head1 SYNOPSIS
None.
=head1 VERSION
version 0.06
=head1 METHODS
This methods are not meant to be called externally.
=over
=item handle_day_change(I<%opt>)
Use B<strp_obj> to parse HAFAS-provided B<date> and B<time> and handle a day
change (encoded by prefixing B<time> with two additional digits) if necessary.
Returns a DateTime(3pm) object.
=back
=head1 DIAGNOSTICS
None.
=head1 DEPENDENCIES
None.
=head1 AUTHOR
Copyright (C) 2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
=head1 LICENSE
This program is licensed under the same terms as Perl itself.
|