-my ($date, $format, $today, $today0, $val, $re, $syspref);
-my @formats = sort keys %thash;
-diag "\n Testing Legacy Functions: format_date and format_date_in_iso";
-ok($syspref = C4::Dates->new->format(), "Your system preference is: $syspref");
+my ( $date, $format, $today, $today0, $val, $re, $syspref );
+my @formats = sort keys %thash;
+my $fake_syspref_default = 'us';
+my $fake_syspref = (@ARGV) ? shift : $ENV{KOHA_TEST_DATE_FORMAT};
+if ($fake_syspref) {
+ diag "You asked for date format '$fake_syspref'.";
+ unless ( scalar grep { /^$fake_syspref$/ } @formats ) {
+ diag "Warning: Unkown date format '$fake_syspref', reverting to default '$fake_syspref_default'.";
+ $fake_syspref = $fake_syspref_default;
+ }
+}
+$fake_syspref or $fake_syspref = $fake_syspref_default;
+$C4::Dates::prefformat = $fake_syspref; # So Dates doesn't have to ask the DB anything.
+
+diag <<EndOfDiag;
+
+In order to run without DB access, this test will substitute '$fake_syspref'
+as your default date format. Export environmental variable KOHA_TEST_DATE_FORMAT
+to override this default, or pass the value as an argument to this test script.
+
+NOTE: we test for the system handling dd=00 and 00 for TIME values, therefore
+you SHOULD see some warnings like:
+Illegal date specified (year = 1952, month = 1, day = 00) at t/Dates.t ...
+
+Testing Legacy Functions: format_date and format_date_in_iso
+
+EndOfDiag
+
+ok( $syspref = C4::Dates->new->format(), "Your system preference is: $syspref" );