Having recently experimented with time zones, I find there is an inconsistency in the way CI handles its timestamps (mostly used in $useSoftDeletes / $createdField functionality):
The code in Model.php that handles the timestamps is as follows:
Code:
protected function setDate(int $userData = null)
{
$currentDate = is_numeric($userData) ? (int) $userData : time();
switch ($this->dateFormat)
{
case 'int':
return $currentDate;
case 'datetime':
return date('Y-m-d H:i:s', $currentDate);
case 'date':
return date('Y-m-d', $currentDate);
Case 'int' returns the time in UTC (GMT) whereas 'datetime' and 'date' both return the time in localized time... which makes it a horrible can of worms to manage in the application code if one has users in more than one time zone (or a user reconfigures their time zone).
I'd propose EITHER:
1) standardizing it (and conform to what some believe is 'best practice') to always NOT use zone'd timestamps (ie: making the same timestamp as 'int' be returned in all cases- easily done by using gmdate() in place of the two date() functions.
or
2) add two new (additional) cases, which would make it backward-compatible with what currently exists:
Code:
case 'datetime_utc':
return gmdate('Y-m-d H:i:s', $currentDate);
case 'date_utc':
return gmdate('Y-m-d', $currentDate);
Personally, I find 2) less desirable because it leans toward making what should be the 'standard' (and consistent) response a special case. I'd propose implementing 1) and then, if local time options were still desired, implement those as the special cases, perhaps with 'datetime_local' and 'date_local' options.