Revision 81b492ac
Von Sven Schöling vor mehr als 10 Jahren hinzugefügt
SL/Helper/DateTime.pm | ||
---|---|---|
36 | 36 |
goto &from_kivitendo; |
37 | 37 |
} |
38 | 38 |
|
39 |
sub add_business_duration { |
|
40 |
my ($self, %params) = @_; |
|
41 |
|
|
42 |
my $abs_days = abs $params{days}; |
|
43 |
my $neg = $params{days} < 0; |
|
44 |
my $bweek = $params{businessweek} || 5; |
|
45 |
my $weeks = int ($abs_days / $bweek); |
|
46 |
my $days = $abs_days % $bweek; |
|
47 |
|
|
48 |
if ($neg) { |
|
49 |
$self->subtract(weeks => $weeks); |
|
50 |
$self->add(days => 8 - $self->day_of_week) if $self->day_of_week > $bweek; |
|
51 |
$self->subtract(days => $self->day_of_week > $days ? $days : $days + (7 - $bweek)); |
|
52 |
} else { |
|
53 |
$self->add(weeks => $weeks); |
|
54 |
$self->subtract(days => $self->day_of_week - $bweek) if $self->day_of_week > $bweek; |
|
55 |
$self->add(days => $self->day_of_week + $days <= $bweek ? $days : $days + (7 - $bweek)); |
|
56 |
} |
|
57 |
|
|
58 |
$self; |
|
59 |
} |
|
60 |
|
|
61 |
sub add_businessdays { |
|
62 |
my ($self, %params) = @_; |
|
63 |
|
|
64 |
$self->add_business_duration(%params); |
|
65 |
} |
|
66 |
|
|
67 |
sub subtract_businessdays { |
|
68 |
my ($self, %params) = @_; |
|
69 |
|
|
70 |
$params{days} *= -1; |
|
71 |
|
|
72 |
$self->add_business_duration(%params); |
|
73 |
} |
|
74 |
|
|
39 | 75 |
1; |
40 | 76 |
|
41 | 77 |
__END__ |
Auch abrufbar als: Unified diff
DateTime: (add|subtract)_businessdays Funktionen