Skip to content

Commit

Permalink
use Fahrplan.DateTime property and convert to local timezone when cre…
Browse files Browse the repository at this point in the history
…ating fuse mount, fixes #8
  • Loading branch information
a-tze committed Aug 5, 2020
1 parent 3261ad2 commit 78e4974
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
24 changes: 7 additions & 17 deletions lib/CRS/Fuse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use POSIX;
use DateTime;
use strict;
use CRS::Paths;
use DateTime::Format::Strptime;

sub new {
my $class = shift;
Expand All @@ -41,7 +42,7 @@ sub new {
return $self;
}

# start has syntax YYYY-MM-DD-hh:mm
# start has syntax YYYY-MM-DDThh:mm:ssZ (ISO)
# duration has syntax hh:mm
# paddings are given in seconds
# returns ($paddedstart, $paddedlength)
Expand All @@ -51,23 +52,12 @@ sub getPaddedTimes {
my ($start, $duration, $startpadding, $endpadding, undef) = @_;
print "getPaddedTimes ($start, $duration, $startpadding, $endpadding)\n" ;

my $startdatetime = undef;
if ($start =~ /(\d+)-(\d+)-(\d+)-(\d+)[\:-](\d+)/) {
$startdatetime = DateTime->new(
year => $1,
month => $2,
day => $3,
hour => $4,
minute => $5,
second => 0,
time_zone => 'Europe/Berlin',
);
} else {
print STDERR "start parameter has incorrect format!\n";
return undef;
}
my $dtformat = DateTime::Format::Strptime->new( pattern => '%FT%T%z');
my $startdatetime = $dtformat->parse_datetime($start);
my $local_tz = DateTime::TimeZone->new(name => 'local');
$startdatetime->set_time_zone($local_tz);
$startdatetime->add('seconds' => -$startpadding) if (defined($startpadding) and $startpadding =~ /^-?[0-9]+$/);
my $paddedstart = $startdatetime->ymd('.') . '-' . $startdatetime->hms('_');
my $paddedstart = $startdatetime->ymd('-') . '_' . $startdatetime->hms('-');

my $paddedlength = getPaddedDuration($duration, $startpadding, $endpadding);

Expand Down
11 changes: 4 additions & 7 deletions scripts/script-B-mount4cut.pl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ sub prepareTicket {
# fetch metadata

my $room = $props->{'Fahrplan.Room'};
my $startdate = $props->{'Fahrplan.Date'};
my $starttime = $props->{'Fahrplan.Start'};
my $startdatetime = $props->{'Fahrplan.DateTime'};
my $duration = $props->{'Fahrplan.Duration'};
my $replacement = $props->{'Record.SourceReplacement'};

Expand All @@ -85,24 +84,22 @@ sub prepareTicket {

# check minimal metadata

if (!defined($room) || !defined($startdate)
|| !defined($duration) || !defined($starttime)) {
if (!defined($room) || !defined($startdatetime) || !defined($duration)) {
print STDERR "NOT ENOUGH METADATA!\n";
$tracker->setTicketFailed($tid,
"Not enough metadata!\n".
"Make sure that the ticket has following attributes:\n".
"-Fahrplan.Room\n-Fahrplan.Date\n-Fahrplan.Duration\n-Fahrplan.Start");
"-Fahrplan.Room\n-Fahrplan.DateTime\n-Fahrplan.Duration");
die("NOT ENOUGH METADATA!\n");
}
my $startpadding = $props->{'Record.StartPadding'};
my $endpadding = $props->{'Record.EndPadding'};

# transformation of metadata

my $start = $startdate . '-' . $starttime; # put date and time together
$endpadding = 15 * 60 if (!defined($endpadding)); # default padding is 15 min.
$startpadding = 15 * 60 unless defined($startpadding); # default startpadding is 15 min.
my ($paddedstart, $paddedlength) = CRS::Fuse::getPaddedTimes($start, $duration, $startpadding, $endpadding);
my ($paddedstart, $paddedlength) = CRS::Fuse::getPaddedTimes($startdatetime, $duration, $startpadding, $endpadding);

# now try to create the mount

Expand Down

0 comments on commit 78e4974

Please sign in to comment.