Merge pull request #23483 from ATM-Consulting/NEW_18_helper_functions_for_dates

New 18 helper functions for dates
This commit is contained in:
Laurent Destailleur 2023-01-11 20:29:15 +01:00 committed by GitHub
commit 44eab6b4e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 31 deletions

View File

@ -11559,7 +11559,6 @@ function dolForgeCriteriaCallback($matches)
}
/**
* Get timeline icon
* @param ActionComm $actionstatic actioncomm
@ -12275,3 +12274,63 @@ function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon = '', $n
print $out;
}
}
/**
* Helper function that combines values of a dolibarr DatePicker (such as Form::selectDate) for year, month, day (and
* optionally hour, minute, second) fields to return a timestamp.
*
* @param string $prefix Prefix used to build the date selector (for instance using Form::selectDate)
* @param string $hourTime 'getpost' to include hour, minute, second values from the HTTP request, 'XX:YY:ZZ' to set
* hour, minute, second respectively (for instance '23:59:59')
* @param string $gm Passed to dol_mktime
* @return int|string Date as a timestamp, '' or false if error
*/
function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto')
{
if ($hourTime === 'getpost') {
$hour = GETPOSTINT($prefix . 'hour');
$minute = GETPOSTINT($prefix . 'minute');
$second = GETPOSTINT($prefix . 'second');
} elseif (preg_match('/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
$hour = intval($m[1]);
$minute = intval($m[2]);
$second = intval($m[3]);
} else {
$hour = $minute = $second = 0;
}
// normalize out of range values
$hour = min($hour, 23);
$minute = min($minute, 59);
$second = min($second, 59);
return dol_mktime($hour, $minute, $second, GETPOSTINT($prefix . 'month'), GETPOSTINT($prefix . 'day'), GETPOSTINT($prefix . 'year'), $gm);
}
/**
* Helper function that combines values of a dolibarr DatePicker (such as Form::selectDate) for year, month, day (and
* optionally hour, minute, second) fields to return a a portion of URL reproducing the values from the current HTTP
* request.
*
* @param string $prefix Prefix used to build the date selector (for instance using Form::selectDate)
* @param int $timestamp If null, the timestamp will be created from request data
* @param bool $hourTime If timestamp is null, will be passed to GETPOSTDATE to construct the timestamp
* @param bool $gm If timestamp is null, will be passed to GETPOSTDATE to construct the timestamp
* @return string Portion of URL with query parameters for the specified date
*/
function buildParamDate($prefix, $timestamp = null, $hourTime = '', $gm = 'auto')
{
if ($timestamp === null) $timestamp = GETPOSTDATE($prefix, $hourTime, $gm);
$TParam = array(
$prefix . 'day' => intval(dol_print_date($timestamp, '%d')),
$prefix . 'month' => intval(dol_print_date($timestamp, '%m')),
$prefix . 'year' => intval(dol_print_date($timestamp, '%Y')),
);
if ($hourTime === 'getpost' || ($timestamp !== null && dol_print_date($timestamp, '%H:%M:%S') !== '00:00:00')) {
$TParam = array_merge($TParam, array(
$prefix . 'hour' => intval(dol_print_date($timestamp, '%H')),
$prefix . 'minute' => intval(dol_print_date($timestamp, '%M')),
$prefix . 'second' => intval(dol_print_date($timestamp, '%S'))
));
}
return '&' . http_build_query($TParam);
}

View File

@ -99,14 +99,8 @@ $search_country = GETPOST("search_country", 'int');
$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
$search_user = GETPOST('search_user', 'int');
$search_sale = GETPOST('search_sale', 'int');
$search_date_startday = GETPOST('search_date_startday', 'int');
$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
$search_date_startyear = GETPOST('search_date_startyear', 'int');
$search_date_endday = GETPOST('search_date_endday', 'int');
$search_date_endmonth = GETPOST('search_date_endmonth', 'int');
$search_date_endyear = GETPOST('search_date_endyear', 'int');
$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
$search_date_start = GETPOSTDATE('search_date_start', '', 'tzserver');
$search_date_end = GETPOSTDATE('search_date_end', '23:59:59', 'tzserver');
$search_datelimit_startday = GETPOST('search_datelimit_startday', 'int');
$search_datelimit_startmonth = GETPOST('search_datelimit_startmonth', 'int');
$search_datelimit_startyear = GETPOST('search_datelimit_startyear', 'int');
@ -277,12 +271,6 @@ if (empty($reshook)) {
$search_type = '';
$search_country = '';
$search_type_thirdparty = '';
$search_date_startday = '';
$search_date_startmonth = '';
$search_date_startyear = '';
$search_date_endday = '';
$search_date_endmonth = '';
$search_date_endyear = '';
$search_date_start = '';
$search_date_end = '';
$search_datelimit_startday = '';
@ -778,23 +766,11 @@ if ($limit > 0 && $limit != $conf->liste_limit) {
if ($search_all) {
$param .= '&search_all='.urlencode($search_all);
}
if ($search_date_startday) {
$param .= '&search_date_startday='.urlencode($search_date_startday);
if ($search_date_start) {
$param .= buildParamDate('search_date_start', null, '', 'tzserver');
}
if ($search_date_startmonth) {
$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
}
if ($search_date_startyear) {
$param .= '&search_date_startyear='.urlencode($search_date_startyear);
}
if ($search_date_endday) {
$param .= '&search_date_endday='.urlencode($search_date_endday);
}
if ($search_date_endmonth) {
$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
}
if ($search_date_endyear) {
$param .= '&search_date_endyear='.urlencode($search_date_endyear);
if ($search_date_end) {
$param .= buildParamDate('search_date_end', null, '', 'tzserver');
}
if ($search_datelimit_startday) {
$param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);