Closed Jorilx closed 5 years ago
I am not sure this is related, but does this fix help anything?
Well the fix I mentioned in my post is enough for me, I was just wondering WHY SugarFieldDatetime looks for get_date_format
instead of get_date_time_format
:) Thanks for your help though!
Do you want to make a PR to add your fix to the SuiteCRM code?
I'll try, thanks! :D
Hey @Jorilx `$user_dateFormat = $timedate->get_date_format(); if (!empty($vardef['value']) && !$timedate->check_matching_format($vardef['value'], $user_dateFormat)) {
$sdt = $timedate->fromString($vardef['value'], $current_user);
if (!empty($sdt)) {
//the new 'date_formatted_value' array element will be used in include/SugarFields/Fields/Datetime/DetailView.tpl if it exists
$vardef['date_formatted_value'] = $timedate->asUserDate($sdt, $current_user);
}
}`
From looking at the code it appears that the get_date_format is only used to find out the user's preferences i.e. d/m/y or m/d/y which is needed to just 'confirm' that the value can be converted later at this point $vardef['date_formatted_value'] = $timedate->asUserDate($sdt, $current_user); So the point that you are really questioning is.... https://github.com/salesagility/SuiteCRM/blob/master/include/TimeDate.php#L674
Perhaps looking at https://github.com/salesagility/SuiteCRM/blob/master/include/TimeDate.php#L613 AsUser returns datetime field types which uses the get_date_time_format()
I'm not sure of what's going on, but my situation is the following:
using Studio I've added the "date_modified" field to the Accounts EditView, and if I leave SugarFieldDatetime.php as it is, the field gets rendered just as a date. If I apply my patch, it gets rendered correctly as datetime.
As a workaround I've found that I can leave SugarFieldDatetime.php alone if I specify
'customCode' => '{$fields.date_modified.value}'
inside metadata/editviewdefs.php.
I'll try and investigate the issue further, thanks for your time!
I'm sorry, but isn't it odd that a function that's trying to render a datetime calls asUserDate? Moreover, the comment for asUserDate is Format DateTime object as user date
so I'd be inclined to believe that the intention behind the code is really to render it as just a date... I'm quite confused :smile:
Can we close this @Jorilx? This an issue or have we got a work around?
Well I think that the original behaviour is "unexpected" and someone else could be bitten by this problem in the future, but the customCode workaround works so it's not an issue for me anymore.
Hi @Jorilx , I'm unable to replicate this issue on hotfix or latest LTS. Please let me know if this is still an issue you can replicate and we will investigate further. Thanks.
The class responsible for rendering datetimes inside templates,
include/SugarFields/Datetime/SugarFieldDatetime.php
, looks for the format to use with$user_dateFormat = $timedate->get_date_format();
instead of
$user_dateFormat = $timedate->get_date_time_format();
so if you use a datetime inside a
*viewdefs.php
, it gets rendered as a date instead of a datetime. Is this by design? Am I missing something?I'm on SuiteCRM 7.10.8 but this call has been there from the "beginning" :)