From: Frank Brehm Date: Mon, 17 May 2010 20:43:07 +0000 (+0000) Subject: Zeitzonen-Objekte als Attribute dazu X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=60c374f8cc8c06a90c065f28eefce7ff0d4c1e1c;p=my-stuff%2Fperl.git Zeitzonen-Objekte als Attribute dazu git-svn-id: http://svn.brehm-online.com/svn/my-stuff/Perl@68 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/lib/FrBr/Common/MooseX/App.pm b/lib/FrBr/Common/MooseX/App.pm index c7fef5d..8905c18 100644 --- a/lib/FrBr/Common/MooseX/App.pm +++ b/lib/FrBr/Common/MooseX/App.pm @@ -31,6 +31,7 @@ use File::Basename; use FindBin; use Encode qw( decode_utf8 encode_utf8 ); use Data::Dump; +use DateTime; use Carp; @@ -254,6 +255,21 @@ sub log { return $_[0]->logger; } +#----------------------------------------- + +has 'local_timezone' => ( + is => 'ro', + isa => 'FrBr::Types::TimeZone', + traits => [ 'NoGetopt' ], + lazy => 1, + builder => '_build_local_timezone', + documentation => 'Die lokale Zeitzone als DateTime::TimeZone-Objekt.', +); + +sub _build_local_timezone { + return DateTime::TimeZone->new( name => 'local' ); +} + ############################################################################################# # Ändern der Eigenschaften einiger geerbter Attribute @@ -368,6 +384,16 @@ sub init_app { $self->debug( "Initialisierung beginnt ..." ) if $self->verbose >= 2; + if ( $self->verbose >= 2 ) { + + my $tmp; + + for my $f ( 'local_timezone' ) { + $tmp = $self->$f(); + } + + } + } #--------------------------------- diff --git a/lib/FrBr/Common/MooseX/Role/FtpClient.pm b/lib/FrBr/Common/MooseX/Role/FtpClient.pm index 426cdf7..d3d5470 100644 --- a/lib/FrBr/Common/MooseX/Role/FtpClient.pm +++ b/lib/FrBr/Common/MooseX/Role/FtpClient.pm @@ -94,7 +94,7 @@ my $month_map = { 'dec' => 12, }; -our $LocalTZ = DateTime::TimeZone->new( name => 'local' ); +#our $LocalTZ = DateTime::TimeZone->new( name => 'local' ); ############################################################################ @@ -463,6 +463,33 @@ sub _build_ftp_remote_dir { return dir->new( '/' ); } +#------------------------- + +=head2 ftp_remote_timezone + +Zeitzone auf dem FTP-Server + +=cut + +has 'ftp_remote_timezone' => ( + is => 'rw', + isa => 'FrBr::Types::TimeZone', + traits => [ 'Getopt' ], + coerce => 1, + lazy => 1, + required => 1, + builder => '_build_ftp_remote_timezone', + documentation => 'Die Zeitzine auf dem FTP-Server', + cmd_flag => 'ftp-remote-timezone', + cmd_aliases => [ 'remote-timezone' ], +); + +#------ + +sub _build_ftp_remote_timezone { + return DateTime::TimeZone->new( name => 'UTC' ); +} + ############################################################################ =head1 METHODS @@ -481,7 +508,7 @@ after 'evaluate_config' => sub { $self->debug( "Werte FTP-Konfigurationsdinge aus ..." ); return unless $self->config and keys %{ $self->config }; - my @ConfigKeys = qw( host user password blocksize port timeout passive hash_size local_dir remote_dir ); + my @ConfigKeys = qw( host user password blocksize port timeout passive hash_size local_dir remote_dir remote_timezone ); for my $key ( keys %{ $self->config } ) { @@ -541,7 +568,7 @@ after 'init_app' => sub { return if $self->app_initialized; $self->debug( "Initialisiere ..." ); - $self->debug( "Lokale Zeitzone: ", $LocalTZ ); + #$self->debug( "Lokale Zeitzone: ", $LocalTZ ); if ( $self->verbose >= 2 ) { @@ -549,7 +576,7 @@ after 'init_app' => sub { for my $f ( 'ftp_connected', 'ftp_auto_login', 'ftp_auto_init', 'ftp_host', 'ftp_user', 'ftp_password', 'ftp_blocksize', 'ftp_port', 'ftp_timeout', 'ftp_passive', 'ftp_hash_size', 'ftp_local_dir', - 'ftp_remote_dir', ) { + 'ftp_remote_dir', 'ftp_remote_timezone', ) { $tmp = $self->$f(); } @@ -869,15 +896,6 @@ sub dir_list { $entry->{'name'} = $name; -# my $file_dt = $Strp->parse_datetime($mtime_str); -# if ( $file_dt ) { -# $self->debug( sprintf( "Dateidatum von '%s': %s" ), $name, $file_dt->strftime('%Y-%m-%d %H:%M:%S') ) if $self->verbose >= 3; -# while ( DateTime->compare( $file_dt, $now ) > 0 ) { -# $file_dt->subtract( 'years' => 1 ); -# $self->debug( sprintf( "Dateidatum von '%s': %s" ), $name, $file_dt->strftime('%Y-%m-%d %H:%M:%S') ) if $self->verbose >= 3; -# } -# } - push @$list, $entry; } @@ -914,7 +932,7 @@ sub _parse_date { return undef; } - my $now = DateTime->now()->set_time_zone( $LocalTZ ); + my $now = DateTime->now()->set_time_zone( $self->local_timezone ); my $this_year = $now->year; my $create_hash = { @@ -924,7 +942,7 @@ sub _parse_date { hour => $hour + 0, minute => $minute + 0, second => 0, - time_zone => 'UTC', + time_zone => $self->ftp_remote_timezone, }; $self->debug( "Erstelle DateTime-Objekt aus folgenden Angaben: ", $create_hash ) if $self->verbose >= 3; diff --git a/lib/FrBr/Common/MooseX/Role/Types.pm b/lib/FrBr/Common/MooseX/Role/Types.pm index 0ec8e14..0c5bcf0 100644 --- a/lib/FrBr/Common/MooseX/Role/Types.pm +++ b/lib/FrBr/Common/MooseX/Role/Types.pm @@ -45,6 +45,14 @@ subtype 'XML::Simple' => where { $_->isa('XML::Simple') } => message { "Das übergebene Objekt muss vom Typ 'XML::Simple' sein" }; +subtype 'FrBr::Types::TimeZone' => as class_type('DateTime::TimeZone'); + +coerce 'FrBr::Types::TimeZone' + => from 'Object' + => via { $_->isa('DateTime::TimeZone') ? $_ : Params::Coerce::coerce( 'DateTime::TimeZone', $_ ); } + => from 'Str' + => via { DateTime::TimeZone->new( name => $_ ) }; + subtype 'FrBr::Types::URI' => as class_type('URI'); coerce 'FrBr::Types::URI'