5 use SL::Util qw(_hashify);
 
   8   return shift->now(time_zone => $::locale->get_local_time_zone);
 
  12   return shift->now(time_zone => $::locale->get_local_time_zone)->truncate(to => 'day');
 
  15 sub to_kivitendo_time {
 
  16   my ($self, %params) = _hashify(1, @_);
 
  17   return $::locale->format_date_object_to_time($self, %params);
 
  21   my ($self, %params) = _hashify(1, @_);
 
  22   return $::locale->format_date_object($self, %params);
 
  31   return $::locale->parse_date_to_object($_[1]);
 
  39 sub add_business_duration {
 
  40   my ($self, %params) = @_;
 
  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;
 
  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));
 
  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));
 
  61 sub add_businessdays {
 
  62   my ($self, %params) = @_;
 
  64   $self->add_business_duration(%params);
 
  67 sub subtract_businessdays {
 
  68   my ($self, %params) = @_;
 
  72   $self->add_business_duration(%params);
 
  83 SL::Helpers::DateTime - helper functions for L<DateTime>
 
  91 Returns the current time with the time zone set to the local time zone.
 
  95 Returns the current date with the time zone set to the local time zone.
 
  97 =item C<to_kivitendo %param>
 
  99 Formats the date and time according to the current kivitendo user's
 
 100 date format with L<Locale::format_datetime_object>.
 
 102 The legacy name C<to_lxoffice> is still supported.
 
 104 =item C<from_kivitendo $string>
 
 106 Parses a date string formatted in the current kivitendo user's date
 
 107 format and returns an instance of L<DateTime>.
 
 109 Note that only dates can be parsed at the moment, not the time
 
 110 component (as opposed to L<to_kivitendo>).
 
 112 The legacy name C<from_lxoffice> is still supported.
 
 118 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>