5 use SL::Util qw(_hashify);
8 my ($class, %params) = @_;
9 return $class->new(hour => 0, minute => 0, second => 0, time_zone => $::locale->get_local_time_zone, %params);
13 return shift->now(time_zone => $::locale->get_local_time_zone);
17 return shift->now(time_zone => $::locale->get_local_time_zone)->truncate(to => 'day');
20 sub to_kivitendo_time {
21 my ($self, %params) = _hashify(1, @_);
22 return $::locale->format_date_object_to_time($self, %params);
26 my ($self, %params) = _hashify(1, @_);
27 return $::locale->format_date_object($self, %params);
36 return $::locale->parse_date_to_object($_[1]);
44 sub add_business_duration {
45 my ($self, %params) = @_;
47 my $abs_days = abs $params{days};
48 my $neg = $params{days} < 0;
49 my $bweek = $params{businessweek} || 5;
50 my $weeks = int ($abs_days / $bweek);
51 my $days = $abs_days % $bweek;
54 $self->subtract(weeks => $weeks);
55 $self->add(days => 8 - $self->day_of_week) if $self->day_of_week > $bweek;
56 $self->subtract(days => $self->day_of_week > $days ? $days : $days + (7 - $bweek));
58 $self->add(weeks => $weeks);
59 $self->subtract(days => $self->day_of_week - $bweek) if $self->day_of_week > $bweek;
60 $self->add(days => $self->day_of_week + $days <= $bweek ? $days : $days + (7 - $bweek));
66 sub add_businessdays {
67 my ($self, %params) = @_;
69 $self->add_business_duration(%params);
72 sub subtract_businessdays {
73 my ($self, %params) = @_;
77 $self->add_business_duration(%params);
88 SL::Helpers::DateTime - helper functions for L<DateTime>
94 =item C<new_local %params>
96 Returns the time given in C<%params> with the time zone set to the
101 Returns the current time with the time zone set to the local time zone.
105 Returns the current date with the time zone set to the local time zone.
107 =item C<to_kivitendo %param>
109 Formats the date and time according to the current kivitendo user's
110 date format with L<Locale::format_datetime_object>.
112 The legacy name C<to_lxoffice> is still supported.
114 =item C<from_kivitendo $string>
116 Parses a date string formatted in the current kivitendo user's date
117 format and returns an instance of L<DateTime>.
119 Note that only dates can be parsed at the moment, not the time
120 component (as opposed to L<to_kivitendo>).
122 The legacy name C<from_lxoffice> is still supported.
128 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>