By default in Vtiger 7.1 in user preferences you can find following date formats
- dd-mm-yyyy
- mm-dd-yyyy
- yyyy-mm-dd
As you can see there is no European or russian format: dd.mm.yyyy.
Using the development experience in the Vtiger 7.1 system, I will show you how to add a new European to the list of date format.
It should be remembered that the format needs to be added not only to the calendar, but also when exporting to Excel and PDF.
To add a date, you need some knowledge of MySQL and PHP, as well as the Linux command line.
Please note that any changes you make are at your own risk. I am not responsible for any errors. Therefore, do not forget to backup the database and files. The process should also be repeated if you upgraded Vtiger to a newer version. This manual is relevant for version 7.1 and it cannot be ruled out that it will not work in a newer version.
Below I describe in detail the process of adding a new date format dd.mm.yyyy in the Vtiger system.
0. Making backup before doing changes.
In this section, we make a copy of the folder so that we have the opportunity to roll back our changes.
cp -ar vtigercrm vtigercrm_backup
1. Adding new date format in dropdown.
To do this, we need to make changes to the vtiger_date_format table.
We go into the Mysql console and execute the following request:
INSERT INTO `vtiger_date_format` (`date_formatid`, `date_format`, `sortorderid`, `presence`) VALUES (4, 'dd.mm.yyyy', 0, 1);
The value in the third column of sortorderid is the priority when displaying date formats. In our case, the new format will be displayed in fourth.
I would also change the sort order and move the default back.
UPDATE vtiger_date_format SET sortorderid=1 WHERE date_format='dd-mm-yyyy';
2. Changing file vtlib/Vtiger/Functions.php
Function currentUserJSDateFormat (string 31)
You should add the following lines to the first block of the if statement (this is line 30 ++)
elseif ($current_user->date_format == 'dd.mm.yyyy') {
$dt_popup_fmt = "%d.%m.%Y";
}
Function currentUserDisplayDate (string 52)
Replace the date format in the function with the following:
if ($dat_fmt == '') {
$dat_fmt = 'dd.mm.yyyy';
}
3. Change file include/fields/DateTimeField.php
Function __convertToDBFormat (string 110)
Add the following block to the if statement:
elseif ($format == 'dd.mm.yyyy') {
if(strpos($date, "-") !== false) {
list($d, $m, $y) = explode('-', $date);
} else {
list($d, $m, $y) = explode('.', $date);
}
}
Function convertToUserFormat (string 152)
Here we say that we want to use the new format by default. For this we change
if(empty($format)) {
$format = 'dd-mm-yyyy';
}
to following:
if(empty($format)) {
$format = 'dd.mm.yyyy';
}
Function __convertToUserFormat (string 173)
Add the following block to the if statement:
elseif ($format == 'dd.mm.yyyy') {
$date[0] = $d . '.' . $m . '.' . $y;
}
4. Changes in file include/ComboStrings.php (string 305)
Please replace the entire 'date_format_dom' block with the following:
'date_format_dom' => Array('dd-mm-yyyy'=>'dd-mm-yyyy',
'dd.mm.yyyy'=>'dd.mm.yyyy',
'mm-dd-yyyy'=>'mm-dd-yyyy',
'yyyy-mm-dd'=>'yyyy-mm-dd'
),
5. File modules/Calendar/RepeatEvents.php
Function formattime (строка 45).
Adding new case in operator switch:
case 'dd.mm.yyyy': $format_string = 'd.m.Y H:i'; break;
6. File resources/app.js
Function convertToDatePickerFormat (строка 540)
Please add a new block to the condition statement:
else if (dateFormat == 'dd.mm.yyyy') {
return 'd.m.Y';
}
Function convertTojQueryDatePickerFormat (строка 552)
You need to make a lot more changes to this function, so replace the following line:
var splitDateFormat = dateFormat.split('-');
To this block of code
var dotMode = false;
if(dateFormat.indexOf(".") != -1 && dateFormat.indexOf("-") == -1) {
dotMode = true;
}
var splitDateFormat = dateFormat.split(dotMode?'.':'-');
Next in the for loop replace this line:
var joinedDateFormat = splitDateFormat.join('-');
To this block of code
var joinedDateFormat = splitDateFormat.join(dotMode?'.':'-');
7. Changing file layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js
Функция convertToDateRangePicketFormat строка 93
Добавляем в блок if сдеюущий блок с условием:
else if(userDateFormat == 'dd.mm.yyyy') {
return 'dd.MM.yyyy';
}
8. File resources/helper.js
Function getDateInstance строка 59
Replace the lines of code below. The snip part should be saved as follows:
var splittedDate = dateComponent.split("-");
<..snip..>
var splittedDateFormat = dateFormat.split("-");
Меняем на эти строчки кода:
var dotMode = false;
if(dateComponent.indexOf(".") != -1 && dateComponent.indexOf("-") == -1) {
dotMode = true;
}
var splittedDate = dateComponent.split(dotMode?".":"-");
<..snip..> до строки 67
var splittedDateFormat = dateFormat.split(dotMode?".":"-");
9. File layouts/v7/resources/helper.js
At line 85, make changes to the getDateInstance function by overwriting its beginning with the following option:
var dateTimeComponents = dateTime.split(" ");
var dateComponent = dateTimeComponents[0];
var timeComponent = dateTimeComponents[1];
var seconds = '00';
var splitter = '-';
if ( dateComponent.includes(".") ) {
splitter = '.';
}
var splittedDate = dateComponent.split(splitter);
if(splittedDate.length > 3) {
var errorMsg = app.vtranslate("JS_INVALID_DATE");
throw errorMsg;
}
var splittedDateFormat = dateFormat.split(splitter);
The result is already excellent. Now on the screen you can see the new date format and the result is exported, including to xls, pdf files.
I hope that in future versions of the system the Russian date format will be included in the code by default.