×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Timezone issue

Timezone issue 12 years 11 months ago #16455

  • Dino Spruyt
  • Dino Spruyt's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Hello Daniel

First I want to thank you for the reply on my mail with all my questions I had on adjusting the compojoom component. Everything works fine.

I have one issue that I can't resolve.
When a user posts a comment the date is shown correctly but the time isn't correct.
There's a 2 hour difference in time (0900 should be 1100).
I've searched the forum on this issue and I've found some topics on timezone errors.
But all the proposed solutions didn't work for me.

I have a 2.5.6 joomla site and I use the plugin to add comments on jevents events.

Is there a solution for this problem?

Dino

Re: Timezone issue 12 years 11 months ago #16464

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Dino,
It seems that things on joomla 2.5 have changed quite a bit and we need to modify out date functions.
go to components/com_comments/joscomment/utils.php find this function:
function getLocalDate($strdate, $format='%Y-%m-%d %H:%M:%S') {
 
		jimport('joomla.utilities.date');
		$user = & JFactory::getUser();
 
		//	    if we have an anonymous user, then use global config, instead of the user params
		if ($user->get('id')) {
			$tz = $user->getParam('timezone');
		} else {
			$conf = & JFactory::getConfig();
			$tz = $conf->getValue('config.offset');
		}
 
		$jdate = new JDate($strdate);
		$jdate->setOffset($tz);
 
		if ($format == 'age') {
			$current = new JDate();
			$current->setOffset($tz);
 
			$unixtst = (int) $jdate->toUnix();
			$diff = (int) ($current->toUnix() - $unixtst);
			$years = 0;
			$months = 0;
			$days = 0;
			$hours = 0;
			$minutes = 0;
			$seconds = 0;
 
 
			if ($diff > (60 * 60 * 24 * 365)) {
				// more than a yeas
				$years = floor($diff / (60 * 60 * 24 * 365));
				$diff = (int) ($diff % (60 * 60 * 24 * 365));
			}
			if ($diff > (60 * 60 * 24 * 30)) {
				// more than a month
				$months = floor($diff / (60 * 60 * 24 * 30));
				$diff = (int) ($diff % (60 * 60 * 24 * 30));
			}
 
			if ($diff > (60 * 60 * 24)) {
				// more than a day
				$days = floor($diff / (60 * 60 * 24));
				$diff = (int) ($diff % (60 * 60 * 24));
			}
 
			if ($diff > (60 * 60)) {
				// more than an hour
				$hours = floor($diff / (60 * 60));
				$diff = (int) ($diff % (60 * 60));
			}
 
			if ($diff > 60) {
				// more than a minute
				$minutes = floor($diff / 60);
				$diff = (int) ($diff % 60);
			}
 
			$seconds = $diff;
			if ((int) $years) {
				$formatDate = JText::sprintf('COM_COMMENT_YEAR' . ((int) $years == 1 ? '' : 'S') . '_AGO', $years);
			} elseif ((int) $months) {
				$formatDate = JText::sprintf('COM_COMMENT_MONTH' . ((int) $months == 1 ? '' : 'S') . '_AGO', $months);
			} elseif ((int) $days) {
				$formatDate = JText::sprintf('COM_COMMENT_DAY' . ((int) $days == 1 ? '' : 'S') . '_AGO', $days);
			} elseif ((int) $hours) {
				$formatDate = JText::sprintf('COM_COMMENT_HOUR' . ((int) $hours == 1 ? '' : 'S') . '_AGO', $hours);
			} elseif ((int) $minutes) {
				$formatDate = JText::sprintf('COM_COMMENT_MINUTE' . ((int) $minutes == 1 ? '' : 'S') . '_AGO', $minutes);
			} elseif ((int) $seconds) {
				$formatDate = JText::sprintf('COM_COMMENT_SECOND' . ((int) $seconds == 1 ? '' : 'S') . '_AGO', $seconds);
			} else {
				$formatDate = JText::sprintf('COM_COMMENT_SECOND' . ((int) $seconds == 1 ? '' : 'S') . '_AGO', $seconds);
			}
		} else {
			$formatDate = $jdate->toFormat($format);
		}
		return $formatDate;
	}
and change it to
 
function getLocalDate($strdate, $format='%Y-%m-%d %H:%M:%S') {
 
		jimport('joomla.utilities.date');
		//	    if we have an anonymous user, then use global config, instead of the user params
        $userTz = JFactory::getUser()->getParam('timezone');
        $timeZone = JFactory::getConfig()->getValue('offset');
        if($userTz) {
            $timeZone = $userTz;
        }
 
		$jdate = new JDate($strdate);
		$jdate->setTimezone(new DateTimeZone($timeZone));
 
		if ($format == 'age') {
			$current = new JDate();
			$current->setOffset($tz);
 
			$unixtst = (int) $jdate->toUnix();
			$diff = (int) ($current->toUnix() - $unixtst);
			$years = 0;
			$months = 0;
			$days = 0;
			$hours = 0;
			$minutes = 0;
			$seconds = 0;
 
 
			if ($diff > (60 * 60 * 24 * 365)) {
				// more than a yeas
				$years = floor($diff / (60 * 60 * 24 * 365));
				$diff = (int) ($diff % (60 * 60 * 24 * 365));
			}
			if ($diff > (60 * 60 * 24 * 30)) {
				// more than a month
				$months = floor($diff / (60 * 60 * 24 * 30));
				$diff = (int) ($diff % (60 * 60 * 24 * 30));
			}
 
			if ($diff > (60 * 60 * 24)) {
				// more than a day
				$days = floor($diff / (60 * 60 * 24));
				$diff = (int) ($diff % (60 * 60 * 24));
			}
 
			if ($diff > (60 * 60)) {
				// more than an hour
				$hours = floor($diff / (60 * 60));
				$diff = (int) ($diff % (60 * 60));
			}
 
			if ($diff > 60) {
				// more than a minute
				$minutes = floor($diff / 60);
				$diff = (int) ($diff % 60);
			}
 
			$seconds = $diff;
			if ((int) $years) {
				$formatDate = JText::sprintf('COM_COMMENT_YEAR' . ((int) $years == 1 ? '' : 'S') . '_AGO', $years);
			} elseif ((int) $months) {
				$formatDate = JText::sprintf('COM_COMMENT_MONTH' . ((int) $months == 1 ? '' : 'S') . '_AGO', $months);
			} elseif ((int) $days) {
				$formatDate = JText::sprintf('COM_COMMENT_DAY' . ((int) $days == 1 ? '' : 'S') . '_AGO', $days);
			} elseif ((int) $hours) {
				$formatDate = JText::sprintf('COM_COMMENT_HOUR' . ((int) $hours == 1 ? '' : 'S') . '_AGO', $hours);
			} elseif ((int) $minutes) {
				$formatDate = JText::sprintf('COM_COMMENT_MINUTE' . ((int) $minutes == 1 ? '' : 'S') . '_AGO', $minutes);
			} elseif ((int) $seconds) {
				$formatDate = JText::sprintf('COM_COMMENT_SECOND' . ((int) $seconds == 1 ? '' : 'S') . '_AGO', $seconds);
			} else {
				$formatDate = JText::sprintf('COM_COMMENT_SECOND' . ((int) $seconds == 1 ? '' : 'S') . '_AGO', $seconds);
			}
		} else {
			$formatDate = $jdate->format($format, true);
		}
		return $formatDate;
	}

This should be all. Let me know if after those modifications everything is ok.

Cheers,
Daniel

Re: Timezone issue 12 years 11 months ago #16491

  • Dino Spruyt
  • Dino Spruyt's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Hello Daniel

I changed the code as you suggested.
In the attachment you can see what the outcome is.
It doesn't give us the correct timing.
In the attachment you can see the result of the change.(%26-%b-%2012/%14:%juni)
Thanks a lot for the quick respons.
Greetz
Dino
Attachments:

Re: Timezone issue 12 years 11 months ago #16492

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
I think that I forgot to mention the final step :)
Go to the backend settings and add the following date format:
d-m-Y H:i:s

This should be all.
cheers,
Daniel

Re: Timezone issue 12 years 11 months ago #16504

  • Dino Spruyt
  • Dino Spruyt's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Hi Daniel

The final (forgotten :P )step did the trick.
I now see the correct time when a comment is posted.
Thank you for the excellent support.
I'll check your site on a regular basis for update's on the compojoom component.
I read that you are working on a complete new version.
Looking forward to try it out.
Greetz
Dino
  • Page:
  • 1
Time to create page: 0.179 seconds