Hello!

My chat is two hours slower or behind the rest of the site, while a forum post can be logged at 15:51, the chat would say someone wrote something at 13:51. Both should obviously have the same time, at 15:51 if they were posted at the same time. Nothing I do, seems to rectify the clock skew of the chat.

Let me know if you require further feedback.

Best regards,
Ao

CommentFileSizeAuthor
#3 timezone.patch692 bytestorrance123
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Yasl’s picture

Drupal 7 variable_get('date_default_timezone', 0) returns string name and not an offset in seconds. Ugh.

It's showing UTC instead of local time I believe.

I used info from http://forum.civicrm.org/index.php?topic=20462.0

and I just hardwired my offset into the module.

function chatroom_get_user_timezone_offset() {
global $user;

$offset = variable_get('date_default_timezone', 0);
$offset = -25200; // -7(offset) * 60 * 60
if (variable_get('configurable_timezones', TRUE) && isset($user->timezone)) {
$offset = $user->timezone;
}
return $offset;
}

Now to get the day to show as many of our chats are over the course of days.

ok...changed the return in the chatroom_get_message_time_string function to:
return $date->format(variable_get('chatroom_msg_date_format', 'M:d:h:i:s:a'));

using this link to figure out - http://php.net/manual/en/function.date.php

All is well. :)

Aonoa’s picture

Thank you!

I just changed the date format slightly in variation with yours.. 'M-d H:i:s:a'. :-)

Best regards,
Ao

torrance123’s picture

Status: Active » Needs review
FileSize
692 bytes

I've attached a patch against the latest commit in 7.x-1.x which is a general solution to this problem.

See below for the new function:

/**
 * Return the current user's offset from UTC.
 */
function chatroom_get_user_timezone_offset() {
  global $user;

  $timezone = variable_get('date_default_timezone', 'UTC');
  if (variable_get('configurable_timezones', TRUE) && isset($user->timezone)) {
    $timezone = $user->timezone;
  }

  $timezone = new DateTimeZone($timezone);
  $now = new DateTime('now', $timezone);
  $offset = $timezone->getOffset($now);
  return $offset;
}
michlis’s picture

Version: 7.x-1.x-dev » 7.x-2.0
Status: Needs review » Reviewed & tested by the community

Solution provided by @torrance123 fixes time offset problem in 7.x-2.0.

Anonymous’s picture

Status: Reviewed & tested by the community » Fixed

thanks! committed and pushed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.