Skip to content

Commit

Permalink
Added a method to get user timezone as DateTimezone instance
Browse files Browse the repository at this point in the history
  • Loading branch information
julienV committed Mar 30, 2017
1 parent f45c0da commit 99c9e47
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libraries/cms/html/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public static function script($file, $options = array(), $attribs = array())
{
return $includes[0];
}

return $includes;
}

Expand Down Expand Up @@ -786,7 +786,7 @@ public static function date($input = 'now', $format = null, $tz = true, $gregori
$date = JFactory::getDate($input, 'UTC');

// Set the correct time zone based on the user configuration.
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
$date->setTimezone($user->getTimezone());
}
// UTC date converted to server time zone.
elseif ($tz === false)
Expand Down
2 changes: 1 addition & 1 deletion libraries/cms/html/jgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static function published($value, $i, $prefix = '', $enabled = true, $che
$nullDate = JFactory::getDbo()->getNullDate();
$nowDate = JFactory::getDate()->toUnix();

$tz = new DateTimeZone(JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset')));
$tz = JFactory::getUser()->getTimezone();

$publish_up = ($publish_up != $nullDate) ? JFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false;
$publish_down = ($publish_down != $nullDate) ? JFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false;
Expand Down
2 changes: 1 addition & 1 deletion libraries/fof/form/field/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function getCalendar($display)
if ((int) $this->value)
{
// Get a date object based on the correct timezone.
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
$date->setTimezone($user->getTimezone());
}
break;

Expand Down
2 changes: 1 addition & 1 deletion libraries/fof/form/header/fielddate.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function getFilter()
{
// Get a date object based on the correct timezone.
$date = FOFPlatform::getInstance()->getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
$date->setTimezone($user->getTimezone());

// Transform the date string.
$searchvalue = $date->format('Y-m-d H:i:s', true, false);
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/form/fields/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected function getInput()
{
// Get a date object based on the correct timezone.
$date = JFactory::getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
$date->setTimezone($user->getTimezone());

// Transform the date string.
$this->value = $date->format('Y-m-d H:i:s', true, false);
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/form/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ protected function filterField($element, $value)
}

// Get the user timezone setting defaulting to the server timezone setting.
$offset = JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset'));
$offset = JFactory::getUser()->getTimezone();

// Return a MySQL formatted datetime string in UTC.
try
Expand Down
14 changes: 14 additions & 0 deletions libraries/joomla/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,20 @@ public function getParameters()
// @codeCoverageIgnoreEnd
}

/**
* Method to get the user timezone.
*
* If the user didn't set a timezone, it will return the server timezone
*
* @return DateTimeZone
*/
public function getTimezone()
{
$timezone = $this->getParam('timezone', JFactory::getApplication()->get('offset', 'GMT'));

return new DateTimeZone($timezone);
}

/**
* Method to get the user parameters
*
Expand Down

0 comments on commit 99c9e47

Please sign in to comment.