Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b9cd11d7

Von Moritz Bunkus vor mehr als 3 Jahren hinzugefügt

  • ID b9cd11d78faef7815e435c11aa6a12793e9cb9c9
  • Vorgänger a206eca6
  • Nachfolger 9b16f8f8

AttrDuration für minutes: _in_hours und _in_hours_as_number

Generierte Helfer-Methoden für Attribute, die normalerweise Minuten
speichern. Die Funktion `attribute_in_hours` rechnet die Minuten in
Stunden um (beim Lesen) und umgekehrt (beim Schreiben).

`attribute_in_hours_as_number` formatiert zusätzlich den Wert in
Stunden zusätzlich in das Zahlenformat der Anwender*in bzw. parst
dieses Format beim Schreiben.

Unterschiede anzeigen:

SL/DB/Helper/AttrDuration.pm
116 116
    my $as_minutes = "${attribute}_as_minutes";
117 117
    return defined($self->$attribute) ? sprintf('%d:%02d', $self->$as_hours, $self->$as_minutes) : undef;
118 118
  };
119

  
120
  *{ $package . '::' . $attribute . '_in_hours' } = sub {
121
    my ($self, $value) = @_;
122

  
123
    $self->$attribute(int($value * 60 + 0.5)) if @_ > 1;
124
    return $self->$attribute / 60.0;
125
  };
126

  
127
  *{ $package . '::' . $attribute . '_in_hours_as_number' } = sub {
128
    my ($self, $value) = @_;
129

  
130
    my $sub = "${attribute}_in_hours";
131

  
132
    $self->$sub($::form->parse_amount(\%::myconfig, $value)) if @_ > 1;
133
    return $::form->format_amount(\%::myconfig, $self->$sub, 2);
134
  };
119 135
}
120 136

  
121 137
1;
......
234 250
e.g. C<1:30> for the value 90 minutes. Parsing such a string is
235 251
supported, too.
236 252

  
253
=item C<attribute_in_hours [$new_value]>
254

  
255
Access the full value but convert to and from hours when
256
reading/writing the value.
257

  
258
=item C<attribute_in_hours_as_number [$new_value]>
259

  
260
Access the full value but convert to and from hours when
261
reading/writing the value. The value is formatted to/parsed from the
262
user's number format.
263

  
237 264
=back
238 265

  
239 266
=head1 FUNCTIONS

Auch abrufbar als: Unified diff