From b565c492374cfab42bd743a0bc10adf671f2c26a Mon Sep 17 00:00:00 2001 From: stephen waite Date: Tue, 17 Jan 2023 17:32:50 -0500 Subject: [PATCH] handle pm times when locale set to 12 hrs (#6103) * handle pm times when locale set to 12 hrs * include secs * fix related js function and fix time in datepicker * fix if * check for empty string --- library/formatting.inc.php | 10 +++++++--- library/formatting_DateToYYYYMMDD_js.js.php | 13 ++++++++++--- library/js/xl/jquery-datetimepicker-2-5-4.js.php | 4 +++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/library/formatting.inc.php b/library/formatting.inc.php index b23bce694..ce344b0bc 100644 --- a/library/formatting.inc.php +++ b/library/formatting.inc.php @@ -178,13 +178,17 @@ function DateToYYYYMMDD($DateValue) function TimeToHHMMSS($TimeValue) { - //For now, just return the $TimeValue, since input fields are not formatting time. - // This can be upgraded if decided to format input time fields. - if (trim($TimeValue) == '') { return ''; } + $is_pm = (stripos($TimeValue, 'PM') !== false); + + if ($is_pm) { + $dt = new DateTime('1970-01-01' . $TimeValue); + $TimeValue = $dt->modify('+12 hours')->format('H:i:s'); + } + return $TimeValue; } diff --git a/library/formatting_DateToYYYYMMDD_js.js.php b/library/formatting_DateToYYYYMMDD_js.js.php index cce4f8a3f..1bece7449 100644 --- a/library/formatting_DateToYYYYMMDD_js.js.php +++ b/library/formatting_DateToYYYYMMDD_js.js.php @@ -32,13 +32,20 @@ function DateToYYYYMMDD_js(value){ } function TimeToHHMMSS_js(value){ - //For now, just return the Value, since input fields are not formatting time. - // This can be upgraded if decided to format input time fields. + if (value.trim() == '') { + return ''; + } + + var is_pm = value.trim().toUpperCase().indexOf('PM'); + if (is_pm > 0) { + let d = new Date("1970-01-01 " + value); + let value = d.setHours(d.getHours() + 12).toTimeString(); + } return value.trim(); } function DateToYYYYMMDDHHMMSS_js(value){ - if (typeof value === 'undefined') { + if (typeof value === 'undefined' || value.trim() == '') { return undefined; } var parts = value.split(' '); diff --git a/library/js/xl/jquery-datetimepicker-2-5-4.js.php b/library/js/xl/jquery-datetimepicker-2-5-4.js.php index 713be9306..a92400c16 100644 --- a/library/js/xl/jquery-datetimepicker-2-5-4.js.php +++ b/library/js/xl/jquery-datetimepicker-2-5-4.js.php @@ -92,7 +92,9 @@ - format: ' H:i', + format: ' g:i a', + formatTime:'g:i a', + validateOnBlur: false, format: 'Y-m-d H:i', -- 2.11.4.GIT