my $to_date;
$from_date = DateTime->from_kivitendo($self->data->{from_date}) if $self->data->{from_date};
$to_date = DateTime->from_kivitendo($self->data->{to_date}) if $self->data->{to_date};
+
+ # DateTime->from_kivitendo returns undef if the string cannot be parsed. Therefore test the result if it shopuld have been parsed.
+ die 'Cannot convert date from string "' . $self->data->{from_date} . '"' if $self->data->{from_date} && !$from_date;
+ die 'Cannot convert date to string "' . $self->data->{to_date} . '"' if $self->data->{to_date} && !$to_date;
+
$from_date ||= DateTime->new( day => 1, month => DateTime->today_local->month, year => DateTime->today_local->year)->subtract(months => 1);
$to_date ||= DateTime->last_day_of_month(month => DateTime->today_local->month, year => DateTime->today_local->year)->subtract(months => 1);
-use Test::More tests => 27;
+use Test::More tests => 28;
use strict;
my %data = (
link_order => 1,
project_id => $project->id,
- from_date => '01.04.2021',
+ from_date => '01.01.2021',
to_date => '30.04.2021',
);
my $db_obj = SL::DB::BackgroundJob->new();
clear_up();
+########################################
+# are wrong params detected?
+########################################
+%data = (
+ from_date => 'x01.04.2021',
+);
+$db_obj = SL::DB::BackgroundJob->new();
+$db_obj->set_data(%data);
+$job = SL::BackgroundJob::ConvertTimeRecordings->new;
+
+my $err_msg = '';
+eval { $ret = $job->run($db_obj); 1; } or do {$err_msg = $@};
+ok($err_msg =~ '^Cannot convert date from string', 'wrong date string detected');
+
+clear_up();
+
+
########################################
$::locale = $old_locale;