X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/82515b2d93dc5632f24d6e0b6f8f05f3fd19fbb0..cbbcefbbb1b2b58752bd9dd9d374c6092323ef27:/SL/DB/Helpers/AttrDate.pm diff --git a/SL/DB/Helpers/AttrDate.pm b/SL/DB/Helpers/AttrDate.pm index fa6338870..38d5696fd 100644 --- a/SL/DB/Helpers/AttrDate.pm +++ b/SL/DB/Helpers/AttrDate.pm @@ -10,31 +10,27 @@ sub define { my $attribute = shift; my %params = @_; - $params{places} = 2 if !defined($params{places}); - - my $code = <parse_date(\\\%::myconfig, \@_); - \$self->${attribute}(DateTime->new(year => \$yy, month => \$mm, day => \$dd)); - } else { - \$self->${attribute}(undef); + no strict 'refs'; + *{ $package . '::' . $attribute . '_as_date' } = sub { + my ($self, $string) = @_; + + if (@_ > 1) { + if ($string) { + my ($yy, $mm, $dd) = $::locale->parse_date(\%::myconfig, $string); + $self->$attribute(DateTime->new(year => $yy, month => $mm, day => $dd)); + } else { + $self->$attribute(undef); + } } - } - - return \$self->${attribute} ? \$::locale->reformat_date({ dateformat => 'yy-mm-dd' }, \$self->${attribute}->ymd, \$::myconfig{dateformat}) : undef; -} - -1; -CODE - eval $code; - croak "Defining '${attribute}_as_number' failed: $EVAL_ERROR" if $EVAL_ERROR; + return $self->$attribute + ? $::locale->reformat_date( + { dateformat => 'yy-mm-dd' }, + $self->${attribute}->ymd, + $::myconfig{dateformat} + ) + : undef; + }; return 1; }