From 5d84b288e99ce30d4119dec135320290e4a76f15 Mon Sep 17 00:00:00 2001 From: Prasad <prasad@vtiger.com> Date: Tue, 4 Feb 2020 23:26:50 +0530 Subject: [PATCH] Fixes #1249: Support for UK slash date separator --- include/fields/DateTimeField.php | 44 ++++++++++++++++--- include/utils/utils.php | 4 +- .../Vtiger/resources/dashboards/Widget.js | 18 ++++++-- layouts/v7/resources/helper.js | 16 ++++--- .../Vtiger/resources/dashboards/Widget.js | 10 +++++ modules/Calendar/RepeatEvents.php | 9 +++- modules/Migration/schema/720_to_721.php | 1 + .../Import/modules/Import/actions/Data.php | 10 +++++ resources/app.js | 10 +++++ resources/helper.js | 16 ++++--- vtlib/Vtiger/Functions.php | 15 +++++++ 11 files changed, 131 insertions(+), 22 deletions(-) diff --git a/include/fields/DateTimeField.php b/include/fields/DateTimeField.php index 02d6160ae..b0a949c1a 100644 --- a/include/fields/DateTimeField.php +++ b/include/fields/DateTimeField.php @@ -86,8 +86,10 @@ class DateTimeField { $format = $current_user->date_format; if (empty($format)) { - if (false === strpos($date, '-')) { - $format = 'dd.mm.yyyy'; + if (false !== strpos($date, '.')) { + $format = 'dd.mm.yyyy'; + } else if (false !== strpos($date, '/')) { + $format = 'dd/mm/yyyy'; } else { $format = 'dd-mm-yyyy'; } @@ -108,8 +110,10 @@ class DateTimeField { $dbDate = ''; if (empty($format)) { - if (false === strpos($date, '-')) { - $format = 'dd.mm.yyyy'; + if (false !== strpos($date, '.')) { + $format = 'dd.mm.yyyy'; + } else if (false !== strpos($date, '/')) { + $format = 'dd/mm/yyyy'; } else { $format = 'dd-mm-yyyy'; } @@ -118,7 +122,22 @@ class DateTimeField { switch ($format) { case 'dd.mm.yyyy': list($d, $m, $y) = explode('.', $date); - break; + break; + case 'mm.dd.yyyy': + list($m, $d, $y) = explode('.', $date); + break; + case 'yyyy.mm.dd': + list($y, $m, $d) = explode('.', $date); + break; + case 'dd/mm/yyyy': + list($d, $m, $y) = explode('/', $date); + break; + case 'mm/dd/yyyy': + list($m, $d, $y) = explode('/', $date); + break; + case 'yyyy/mm/dd': + list($y, $m, $d) = explode('/', $date); + break; case 'dd-mm-yyyy': list($d, $m, $y) = explode('-', $date); break; @@ -183,6 +202,21 @@ class DateTimeField { switch ($format) { case 'dd.mm.yyyy': $date[0] = $d . '.' . $m . '.' . $y; + break; + case 'mm.dd.yyyy': + $date[0] = $m . '.' . $d . '.' . $y; + break; + case 'yyyy.mm.dd': + $date[0] = $y . '.' . $m . '.' . $d; + break; + case 'dd/mm/yyyy': + $date[0] = $d . '/' . $m . '/' . $y; + break; + case 'mm/dd/yyyy': + $date[0] = $m . '/' . $d . '/' . $y; + break; + case 'yyyy/mm/dd': + $date[0] = $y . '/' . $m . '/' . $d; break; case 'dd-mm-yyyy': $date[0] = $d . '-' . $m . '-' . $y; diff --git a/include/utils/utils.php b/include/utils/utils.php index 3266e04dc..7dd268dcd 100755 --- a/include/utils/utils.php +++ b/include/utils/utils.php @@ -1798,8 +1798,10 @@ function getValidDBInsertDateValue($value) { break; } } - if (false === strpos($value, '-')) { + if (false !== strpos($value, '.')) { list($y, $m, $d) = explode('.', $value); + } else if (false !== strpos($value, '/')) { + list($y, $m, $d) = explode('/', $value); } else { list($y, $m, $d) = explode('-', $value); } diff --git a/layouts/v7/modules/Vtiger/resources/dashboards/Widget.js b/layouts/v7/modules/Vtiger/resources/dashboards/Widget.js index 600bb3e8a..58b15c06d 100644 --- a/layouts/v7/modules/Vtiger/resources/dashboards/Widget.js +++ b/layouts/v7/modules/Vtiger/resources/dashboards/Widget.js @@ -86,11 +86,23 @@ Vtiger.Class('Vtiger_Widget_Js',{ }, convertToDateRangePicketFormat : function(userDateFormat) { - if(userDateFormat == 'yyyy-mm-dd') { + if ('dd.mm.yyyy' === userDateFormat) { + return 'dd.MM.yyyy'; + } else if ('mm.dd.yyyy' === userDateFormat) { + return 'MM.dd.yyyy' + } else if ('yyyy.mm.dd' === userDateFormat) { + return 'yyyy.MM.dd'; + } else if ('dd/mm/yyyy' === userDateFormat) { + return 'dd/MM/yyyy'; + } else if ('mm/dd/yyyy' === userDateFormat) { + return 'MM/dd/yyyy' + } else if ('yyyy/mm/dd' === userDateFormat) { + return 'yyyy/MM/dd'; + } else if ('yyyy-mm-dd' === userDateFormat) { return 'yyyy-MM-dd'; - }else if( userDateFormat == 'mm-dd-yyyy') { + } else if ('mm-dd-yyyy' === userDateFormat) { return 'MM-dd-yyyy'; - }else if(userDateFormat == 'dd-mm-yyyy') { + } else if ('dd-mm-yyyy' === userDateFormat) { return 'dd-MM-yyyy'; } }, diff --git a/layouts/v7/resources/helper.js b/layouts/v7/resources/helper.js index 0a9e127a3..79b3564f9 100644 --- a/layouts/v7/resources/helper.js +++ b/layouts/v7/resources/helper.js @@ -90,10 +90,12 @@ jQuery.Class("Vtiger_Helper_Js",{ var splittedDate = ''; var splittedDateFormat = ''; - if (dateFormat.indexOf('-') !== -1) { - splittedDate = dateComponent.split('-'); - } else { + if (dateFormat.indexOf('.') !== -1) { splittedDate = dateComponent.split('.'); + } else if (dateFormat.indexOf('/') !== -1) { + splittedDate = dateComponent.split('/'); + } else { + splittedDate = dateComponent.split('-'); } if(splittedDate.length > 3) { @@ -101,10 +103,12 @@ jQuery.Class("Vtiger_Helper_Js",{ throw errorMsg; } - if (dateFormat.indexOf('-') !== -1) { - splittedDateFormat = dateFormat.split('-'); - } else { + if (dateFormat.indexOf('.') !== -1) { splittedDateFormat = dateFormat.split('.'); + } else if (dateFormat.indexOf('/') !== -1) { + splittedDateFormat = dateFormat.split('/'); + } else { + splittedDateFormat = dateFormat.split('-'); } var year = splittedDate[splittedDateFormat.indexOf("yyyy")]; diff --git a/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js b/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js index 24692ac00..e8d50d206 100644 --- a/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js +++ b/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js @@ -86,6 +86,16 @@ jQuery.Class('Vtiger_Widget_Js',{ convertToDateRangePicketFormat : function(userDateFormat) { if ('dd.mm.yyyy' === userDateFormat) { return 'dd.MM.yyyy'; + } else if ('mm.dd.yyyy' === userDateFormat) { + return 'MM.dd.yyyy' + } else if ('yyyy.mm.dd' === userDateFormat) { + return 'yyyy.MM.dd'; + } else if ('dd/mm/yyyy' === userDateFormat) { + return 'dd/MM/yyyy'; + } else if ('mm/dd/yyyy' === userDateFormat) { + return 'MM/dd/yyyy' + } else if ('yyyy/mm/dd' === userDateFormat) { + return 'yyyy/MM/dd'; } else if ('yyyy-mm-dd' === userDateFormat) { return 'yyyy-MM-dd'; } else if ('mm-dd-yyyy' === userDateFormat) { diff --git a/modules/Calendar/RepeatEvents.php b/modules/Calendar/RepeatEvents.php index b1fd36736..93898a03f 100644 --- a/modules/Calendar/RepeatEvents.php +++ b/modules/Calendar/RepeatEvents.php @@ -39,7 +39,14 @@ class Calendar_RepeatEvents { global $current_user; $format_string = 'Y-m-d H:i'; switch($current_user->date_format) { - case 'dd.mm.yyyy': $format_string = 'd.m.Y H:i'; break; + case 'dd.mm.yyyy': $format_string = 'd.m.Y H:i'; break; + case 'mm.dd.yyyy': $format_string = 'm.d.Y H:i'; break; + case 'yyyy.mm.dd': $format_string = 'Y.m.d H:i'; break; + + case 'dd/mm/yyyy': $format_string = 'd/m/Y H:i'; break; + case 'mm/dd/yyyy': $format_string = 'm/d/Y H:i'; break; + case 'yyyy/mm/dd': $format_string = 'Y/m/d H:i'; break; + case 'dd-mm-yyyy': $format_string = 'd-m-Y H:i'; break; case 'mm-dd-yyyy': $format_string = 'm-d-Y H:i'; break; case 'yyyy-mm-dd': $format_string = 'Y-m-d H:i'; break; diff --git a/modules/Migration/schema/720_to_721.php b/modules/Migration/schema/720_to_721.php index 051d5b257..0e14acc38 100644 --- a/modules/Migration/schema/720_to_721.php +++ b/modules/Migration/schema/720_to_721.php @@ -78,4 +78,5 @@ if (defined('VTIGER_UPGRADE')) { $em->registerHandler('vtiger.field.afterdelete', 'modules/Vtiger/handlers/FieldEventHandler.php', 'FieldEventHandler'); $db->pquery('INSERT INTO vtiger_date_format (date_format, sortorderid, presence) VALUES (?, ?, ?)', ['dd.mm.yyyy', 3, 1]); + $db->pquery('INSERT INTO vtiger_date_format (date_format, sortorderid, presence) VALUES (?, ?, ?)', ['dd/mm/yyyy', 4, 1]); } \ No newline at end of file diff --git a/pkg/vtiger/modules/Import/modules/Import/actions/Data.php b/pkg/vtiger/modules/Import/modules/Import/actions/Data.php index e14ae6297..41a328d98 100644 --- a/pkg/vtiger/modules/Import/modules/Import/actions/Data.php +++ b/pkg/vtiger/modules/Import/modules/Import/actions/Data.php @@ -712,6 +712,16 @@ class Import_Data_Action extends Vtiger_Action_Controller { $userDateFormat = $current_user->column_fields['date_format']; if ('dd.mm.yyyy' === $userDateFormat) { $dateFormat = 'd.m.Y'; + } else if ('mm.dd.yyyy' === $userDateFormat) { + $dateFormat = 'm.d.Y'; + } else if ('yyyy.mm.dd' === $userDateFormat) { + $dateFormat = 'Y.m.d'; + } else if ('dd/mm/yyyy' === $userDateFormat) { + $dateFormat = 'd/m/Y'; + } else if ('mm/dd/yyyy' === $userDateFormat) { + $dateFormat = 'm/d/Y'; + } else if ('yyyy/mm/dd' === $userDateFormat) { + $dateFormat = 'Y/m/d'; } else if ('dd-mm-yyyy' === $userDateFormat) { $dateFormat = 'd-m-Y'; } else if ('mm-dd-yyyy' === $userDateFormat) { diff --git a/resources/app.js b/resources/app.js index f5970f101..55e86da44 100644 --- a/resources/app.js +++ b/resources/app.js @@ -538,6 +538,16 @@ var app = { convertToDatePickerFormat: function (dateFormat) { if ('dd.mm.yyyy' === dateFormat) { return 'd.m.Y'; + } else if ('mm.dd.yyyy' === dateFormat) { + return 'm.d.Y'; + } else if ('yyyy.mm.dd' === dateFormat) { + return 'Y.m.d'; + } else if ('dd/mm/yyyy' === dateFormat) { + return 'd/m/Y'; + } else if ('mm/dd/yyyy' === dateFormat) { + return 'm/d/Y'; + } else if ('yyyy/mm/dd' === dateFormat) { + return 'Y/m/d'; } else if ('yyyy-mm-dd' === dateFormat) { return 'Y-m-d'; } else if ('mm-dd-yyyy' === dateFormat) { diff --git a/resources/helper.js b/resources/helper.js index 803450790..b068f767d 100644 --- a/resources/helper.js +++ b/resources/helper.js @@ -59,10 +59,12 @@ jQuery.Class("Vtiger_Helper_Js",{ var splittedDate = ''; var splittedDateFormat = ''; - if (dateFormat.indexOf('-') !== -1) { - splittedDate = dateComponent.split('-'); - } else { + if (dateFormat.indexOf('.') !== -1) { splittedDate = dateComponent.split('.'); + } else if (dateFormat.indexOf('/') !== -1) { + splittedDate = dateComponent.split('/'); + } else { + splittedDate = dateComponent.split('-'); } if (splittedDate.length > 3) { @@ -70,10 +72,12 @@ jQuery.Class("Vtiger_Helper_Js",{ throw errorMsg; } - if (dateFormat.indexOf('-') !== -1) { - splittedDateFormat = dateFormat.split('-'); - } else { + if (dateFormat.indexOf('.') !== -1) { splittedDateFormat = dateFormat.split('.'); + } else if (dateFormat.indexOf('/') !== -1) { + splittedDateFormat = dateFormat.split('/'); + } else { + splittedDateFormat = dateFormat.split('-'); } var year = splittedDate[splittedDateFormat.indexOf("yyyy")]; diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php index e51904345..1062bdeb6 100644 --- a/vtlib/Vtiger/Functions.php +++ b/vtlib/Vtiger/Functions.php @@ -33,6 +33,21 @@ class Vtiger_Functions { switch ($currentUser->get('date_format')) { case 'dd.mm.yyyy': $datePopupFormat = '%d.%m.%Y'; + break; + case 'mm.dd.yyyy': + $datePopupFormat = '%m.%d.%Y'; + break; + case 'yyyy.mm.dd': + $datePopupFormat = '%Y.%m.%d'; + break; + case 'dd/mm/yyyy': + $datePopupFormat = '%d/%m/%Y'; + break; + case 'mm/dd/yyyy': + $datePopupFormat = '%m/%d/%Y'; + break; + case 'yyyy/mm/dd': + $datePopupFormat = '%Y/%m/%d'; break; case 'dd-mm-yyyy': $datePopupFormat = '%d-%m-%Y'; -- GitLab