Hi,
When using the creation_date and modification_date wizards I came across the fact that saving an item uses the GMT date as creation date.
This is a problem when using DST time.
When my local time is 12.38, saving an item results in a creation date 11.38, because of GMT.
This is caused by two code "problems":
- In the generated prepareTable function from the model file it uses:
$date = JFactory::getDate();
I believe the config offset should be taken into account (see also
docs.joomla.org/JFactory/getDate):
$date = JFactory::getDate('',JFactory::getConfig()->get('offset'));
Next stop is the generated toSql function in the HelperDates class.
In the prepareTable it is called ilke this:
if (empty($table->id))
{
//Creation date
if (empty($table->creation_date))
$table->creation_date = <CompName>HelperDates::toSql($date);
}
The function in the HelperDates class:
public static function toSql($date)
{
$version = new JVersion();
if ($version->isCompatible('3.0'))
return $date->toSql();
else
return $date->toMySQL();
}
For the toSQL I believe it should use the local time, that can be implemented using true as parameter
See
api.joomla.org/cms-3/classes/JDate.html#method_toSql
and
api.joomla.org/cms-2.5/classes/JDate.html#method_toMySQL
Complete code:
public static function toSql($date)
{
$version = new JVersion();
if ($version->isCompatible('3.0'))
return $date->toSql(true);
else
return $date->toMySQL(true);
}
I am now override the prepareTable like this:
protected function prepareTable($table)
{
$date = JFactory::getDate('',JFactory::getConfig()->get('offset'));
if (empty($table->id))
{
//Creation date
if (empty($table->creation_date))
$table->creation_date = $date->toSql(true);
}
else
{
//Modification date
$table->modification_date = $date->toSql(true);
}
}
This suits my needs, but I would also be glad to hear your opinions.