Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e7cbe943

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID e7cbe943a8a891b714a81b0fae32adb0933cfe26
  • Vorgänger 8a286496
  • Nachfolger 3bdd1cc0

Zeiterfassung: Konvertierung: Prüfung Datums-Parameter

Unterschiede anzeigen:

SL/BackgroundJob/ConvertTimeRecordings.pm
63 63
  my $to_date;
64 64
  $from_date   = DateTime->from_kivitendo($self->data->{from_date}) if $self->data->{from_date};
65 65
  $to_date     = DateTime->from_kivitendo($self->data->{to_date})   if $self->data->{to_date};
66

  
67
  # DateTime->from_kivitendo returns undef if the string cannot be parsed. Therefore test the result if it shopuld have been parsed.
68
  die 'Cannot convert date from string "' . $self->data->{from_date} . '"' if $self->data->{from_date} && !$from_date;
69
  die 'Cannot convert date to string "'   . $self->data->{to_date}   . '"' if $self->data->{to_date}   && !$to_date;
70

  
66 71
  $from_date ||= DateTime->new( day => 1,    month => DateTime->today_local->month, year => DateTime->today_local->year)->subtract(months => 1);
67 72
  $to_date   ||= DateTime->last_day_of_month(month => DateTime->today_local->month, year => DateTime->today_local->year)->subtract(months => 1);
68 73

  
t/background_job/convert_time_recordings.t
1
use Test::More tests => 27;
1
use Test::More tests => 28;
2 2

  
3 3
use strict;
4 4

  
......
71 71
my %data   = (
72 72
  link_order => 1,
73 73
  project_id => $project->id,
74
  from_date  => '01.04.2021',
74
  from_date  => '01.01.2021',
75 75
  to_date    => '30.04.2021',
76 76
);
77 77
my $db_obj = SL::DB::BackgroundJob->new();
......
312 312
clear_up();
313 313

  
314 314

  
315
########################################
316
# are wrong params detected?
317
########################################
318
%data = (
319
  from_date  => 'x01.04.2021',
320
);
321
$db_obj = SL::DB::BackgroundJob->new();
322
$db_obj->set_data(%data);
323
$job    = SL::BackgroundJob::ConvertTimeRecordings->new;
324

  
325
my $err_msg = '';
326
eval { $ret = $job->run($db_obj);  1; } or do {$err_msg = $@};
327
ok($err_msg =~ '^Cannot convert date from string', 'wrong date string detected');
328

  
329
clear_up();
330

  
331

  
315 332
########################################
316 333

  
317 334
$::locale = $old_locale;

Auch abrufbar als: Unified diff