From aa86dd2d9cd15b2cccf0aa0285139aa56cd33f18 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 13 Jun 2014 20:12:32 +0200 Subject: Determine system timezone using DateTime::Timezone --- bin/icli | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'bin') diff --git a/bin/icli b/bin/icli index abcab3a..414c3de 100755 --- a/bin/icli +++ b/bin/icli @@ -12,6 +12,7 @@ use App::Icli::ConfigData; use Carp qw(croak); use DateTime; use DateTime::Format::Strptime; +use DateTime::TimeZone; use Getopt::Long qw/:config bundling/; use List::MoreUtils qw(any firstval); use POSIX qw(strftime); @@ -1044,12 +1045,14 @@ sub dispatch_command { sub action_on_host { my ($host) = @_; + my $tz = DateTime::TimeZone->new( name => 'local' ); + given ($action) { when ('downtime') { my ( $start, $end, $duration, $comment, @opts ) = @action_args; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S', - time_zone => 'Europe/Berlin', # TODO read from system + time_zone => $tz->name, ); my $dt_start = $strp->parse_datetime($start); @@ -1095,12 +1098,14 @@ sub action_on_service { return; } + my $tz = DateTime::TimeZone->new( name => 'local' ); + given ($action) { when ('downtime') { my ( $start, $end, $duration, $comment, @opts ) = @action_args; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S', - time_zone => 'Europe/Berlin', # TODO read from system + time_zone => $tz->name, ); my $dt_start = $strp->parse_datetime($start); @@ -1296,8 +1301,8 @@ Note: Acknowledgement of host problems is not yet supported. Schedule a non-triggered host or service (depending on the filter arguments) downtime. I and I are timestamps and must be formatted as -YYYY-MM-DDTHH:MM:SS, where the "T" is literal. At this moment, they are always -interpreted in the Europe/Berlin timezone, this will change in the future. +YYYY-MM-DDTHH:MM:SS, where the "T" is literal. The timestamp is assumed to +be in the same time zone as the system running icli. If I is 0 (zero), a fixed downtime between I and I is scheduled. Otherwise, a flexible downtime which will start between @@ -1539,16 +1544,14 @@ None. =item * DateTime::Format::Strptime +=item * DateTime::TimeZone + =item * Term::Size =back =head1 BUGS AND LIMITATIONS -When scheduling a downtime, the start and stop times are always interpreted -in the Europe/Berlin timezone. Also, the duration parameter is always -interpreted in hours. - It is probably not clear from the documentation when an action will operate on hosts and when on services. -- cgit v1.2.3