From 085101376c4491bee45fa933777514a844740695 Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Sat, 1 Dec 2018 00:41:46 +0100 Subject: [PATCH 1/4] Introduce standard sql date format filter refactoring standard sql filter for date --- htdocs/core/lib/date.lib.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 7ad40349589..b75de970b19 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -3,7 +3,8 @@ * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2011-2015 Juanjo Menent * Copyright (C) 2017 Ferran Marcet - * + * Copyright (C) 2018 Charlene Benke +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or @@ -274,6 +275,36 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt } +/** + * générate standard filter date + * + * @param string $datefield fields where apply sql date filter + * @param int $day_date day date + * @param int $month_date month date + * @param int $year_date year date + + * @return string $sqldate sql part of date + */ + +function dol_sql_datefilter($datefield, $day_date, $month_date, $year_date) { + global $db; + $sqldate="" + if ($month_date > 0) { + if ($year_date > 0 && empty($day_date)) { + $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false)); + $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'"; + } else if ($year_date > 0 && ! empty($day_date)) { + $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date)); + $sqldate.= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'"; + } else + $sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; + } else if ($year_date > 0){ + $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false)); + $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'"; + } + return $sqldate; +} + /** * Convert a string date into a GM Timestamps date * Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not supported. If parameter gm is 1, we will use no TZ, if not we will use TZ of server, not the one inside string. From 19e4698488fba83253a7477c0045de259a8aa0c6 Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Sat, 1 Dec 2018 10:32:37 +0100 Subject: [PATCH 2/4] Update date.lib.php --- htdocs/core/lib/date.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index b75de970b19..e9dcc91ced7 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -288,7 +288,7 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt function dol_sql_datefilter($datefield, $day_date, $month_date, $year_date) { global $db; - $sqldate="" + $sqldate=""; if ($month_date > 0) { if ($year_date > 0 && empty($day_date)) { $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false)); From f94f7e15ca92ca59c7d23605436a0ac05eef733e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 1 Dec 2018 15:07:55 +0100 Subject: [PATCH 3/4] Update date.lib.php --- htdocs/core/lib/date.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index e9dcc91ced7..253b2814977 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -286,7 +286,7 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt * @return string $sqldate sql part of date */ -function dol_sql_datefilter($datefield, $day_date, $month_date, $year_date) { +function dolSqlDatefilter($datefield, $day_date, $month_date, $year_date) { global $db; $sqldate=""; if ($month_date > 0) { From 77c01a1fae076039faf809668e4767491c0442a2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Dec 2018 17:58:33 +0100 Subject: [PATCH 4/4] Update date.lib.php --- htdocs/core/lib/date.lib.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 253b2814977..48961a0c6d5 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -282,7 +282,6 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt * @param int $day_date day date * @param int $month_date month date * @param int $year_date year date - * @return string $sqldate sql part of date */