From 819f44a4d39a56ad5001968d1ee6f6d0b500623a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 16 Mar 2021 12:54:00 +0000 Subject: [PATCH] Bug 23937: Allow for single date day or month When validating dates in JavaScript it is acceptable to have single digit days or months e.g,: 2011-6-16 When parsing in Koha::DateUtils->dt_from_string we die on these This patch changes the logic to allow for one or two digits in the days and months To test: 1 - Add new patron 2 - Enter birthdate as 2/11/1986 3 - Complete required fields 4 - Save 5 - Get ISE The given date (2/11/1986) does not match the date format (us) at /kohadevbox/koha/Koha/DateUtils.pm line 175 6 - Apply patch 7 - Repeat 1-4 8 - Patron successfully added 9 - Edit patron, try setting DOB to 2/1/1986 10 - Success! 11 - Repeat with other settings of system preference 'dateformat' https://bugs.koha-community.org/show_bug.cgi?id=27937 --- Koha/DateUtils.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 9b599e3c6d..6e6eec7ac7 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -69,17 +69,17 @@ sub dt_from_string { my $fallback_re = qr| (?\d{4}) - - (?\d{2}) + (?\d{1,2}) - - (?\d{2}) + (?\d{1,2}) |xms; if ( $date_format eq 'metric' ) { # metric format is "dd/mm/yyyy[ hh:mm:ss]" $regex = qr| - (?\d{2}) + (?\d{1,2}) / - (?\d{2}) + (?\d{1,2}) / (?\d{4}) |xms; @@ -87,9 +87,9 @@ sub dt_from_string { elsif ( $date_format eq 'dmydot' ) { # dmydot format is "dd.mm.yyyy[ hh:mm:ss]" $regex = qr| - (?\d{2}) + (?\d{1,2}) . - (?\d{2}) + (?\d{1,2}) . (?\d{4}) |xms; @@ -97,9 +97,9 @@ sub dt_from_string { elsif ( $date_format eq 'us' ) { # us format is "mm/dd/yyyy[ hh:mm:ss]" $regex = qr| - (?\d{2}) + (?\d{1,2}) / - (?\d{2}) + (?\d{1,2}) / (?\d{4}) |xms; -- 2.11.0