X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FHelper%2FAttrDuration.pm;h=c627f190cb6ba0abc23f64415c5e5f0658eaf43c;hb=c5057972d03f3546494fabe72224785e5a0a1714;hp=5bdd4bf7d146ecb516b48acf7e3878cd0bd0f395;hpb=96f2dabc7d64e28c74358fb5745a6c68b18527f3;p=kivitendo-erp.git diff --git a/SL/DB/Helper/AttrDuration.pm b/SL/DB/Helper/AttrDuration.pm index 5bdd4bf7d..c627f190c 100644 --- a/SL/DB/Helper/AttrDuration.pm +++ b/SL/DB/Helper/AttrDuration.pm @@ -116,6 +116,22 @@ sub _make_minutes { my $as_minutes = "${attribute}_as_minutes"; return defined($self->$attribute) ? sprintf('%d:%02d', $self->$as_hours, $self->$as_minutes) : undef; }; + + *{ $package . '::' . $attribute . '_in_hours' } = sub { + my ($self, $value) = @_; + + $self->$attribute(int($value * 60 + 0.5)) if @_ > 1; + return $self->$attribute / 60.0; + }; + + *{ $package . '::' . $attribute . '_in_hours_as_number' } = sub { + my ($self, $value) = @_; + + my $sub = "${attribute}_in_hours"; + + $self->$sub($::form->parse_amount(\%::myconfig, $value)) if @_ > 1; + return $::form->format_amount(\%::myconfig, $self->$sub, 2); + }; } 1; @@ -234,6 +250,17 @@ Access the full value as a formatted string in the form C, e.g. C<1:30> for the value 90 minutes. Parsing such a string is supported, too. +=item C + +Access the full value but convert to and from hours when +reading/writing the value. + +=item C + +Access the full value but convert to and from hours when +reading/writing the value. The value is formatted to/parsed from the +user's number format. + =back =head1 FUNCTIONS