Skip to content

Commit

Permalink
Improved BaseModel with date timezone support
Browse files Browse the repository at this point in the history
  • Loading branch information
libern committed Sep 17, 2016
1 parent 141871c commit b3ec0f6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Someline/Base/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,14 @@ protected function getAuthUserDateTimezone()
*/
public function setAttribute($key, $value)
{
if ($value && (in_array($key, $this->getDates()) || $this->isDateCastable($key))) {
$value = $this->fromDateTime($value);
}

if ($value instanceof Carbon && $this->timestamp_always_save_in_utc) {
$value->setTimezone('UTC');
if ($this->timestamp_always_save_in_utc) {
if ($value instanceof Carbon) {
$value->setTimezone('UTC');
} else if ($value && (in_array($key, $this->getDates()) || $this->isDateCastable($key))) {
$value = $this->fromDateTime($value);
$value->setTimezone('UTC');
}
}

return parent::setAttribute($key, $value);
Expand Down

0 comments on commit b3ec0f6

Please sign in to comment.