X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FHelpers%2FAttrDate.pm;fp=SL%2FDB%2FHelpers%2FAttrDate.pm;h=fa6338870a2af727483195d4da3ce439e1da026a;hb=82515b2d93dc5632f24d6e0b6f8f05f3fd19fbb0;hp=0000000000000000000000000000000000000000;hpb=4440782f0737cd715dbd96851ecc2dbd8cd639f2;p=kivitendo-erp.git diff --git a/SL/DB/Helpers/AttrDate.pm b/SL/DB/Helpers/AttrDate.pm new file mode 100644 index 000000000..fa6338870 --- /dev/null +++ b/SL/DB/Helpers/AttrDate.pm @@ -0,0 +1,42 @@ +package SL::DB::Helpers::AttrDate; + +use strict; + +use Carp; +use English; + +sub define { + my $package = shift; + 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); + } + } + + 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 1; +} + +1;