summaryrefslogtreecommitdiff
path: root/lib/Travel/Routing/DE/HAFAS/Utils.pm
blob: 4b5bdb7c6a2b7c01908a06c3764a29e5a2c5e637 (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
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 $offset_days = 0;

	# 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 );
	}

	return $ts;
}

1;