Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a method to get user timezone as DateTimezone instance #15007

Merged
merged 2 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a @since __DEPLOY_VERSION__ to the doc block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public function getTimezone()
{
$timezone = $this->getParam('timezone', JFactory::getApplication()->get('offset', 'GMT'));

return new DateTimeZone($timezone);
}

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