Possible to change time zone in comments?

Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Tue, 2002-08-20 21:10

First I just want to say how much I LOVE Gallery. Took me a bit to figure it all out, but now that I have it up and running, it's awesome! :smile:

A question - I've found most of the things I wanted to change by poking around in the Gallery files, but the one thing that's eluded me is how to change the time on the comments to reflect my time zone (PST) instead of what it's showing (CDT). Is that something I can change easily or not?

Thanks!

 
muggles
muggles's picture

Joined: 2002-08-19
Posts: 22
Posted: Tue, 2002-08-20 22:12

Gallery seems to use php's date function, which will output the time zone used wherever the server is located (Central Time in your case).

You could modify classes/Comment.php to adjust this, but it will always be wrong to someone :smile:

I have seen some Javascipt code that will use the users local time, but this is not a simple change.

Code from Comment.php:
return date("M d, Y H:i T", $time);

This <!-- BBCode Start --><A HREF="http://groups.google.com/groups?num=100&amp;hl=en&amp;lr=&amp;ie=ISO-8859-1&amp;q=change+time+zone+in+php+group%3A*php*" TARGET="_blank">Google Search</A><!-- BBCode End --> may shead some light on your situation.

no easy fix for this one, sorry.
muggles

 
Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Wed, 2002-08-21 01:02

Hi there

Thanks for the answer --I suspected as much (that it was tied into my server location). I don't think I'll worry about it too much since that's the case, but I will look thru the links in the google search you provided (much appreciated)!

Regards,

 
WebSnail

Joined: 2002-08-15
Posts: 34
Posted: Fri, 2002-08-23 08:44
Quote:
You could modify classes/Comment.php to adjust this, but it will always be wrong to someone :smile:

yeah, unfortunately because Gallery doesn't include a profile system with information such as their time zone you're a bit stuffed in this respect.

 
michellez
michellez's picture

Joined: 2002-11-07
Posts: 39
Posted: Mon, 2002-11-11 11:47

I guess that is referring to an older version of gallery as there is no comment.php in mine :/ (1.3.1)

Where abouts is it now? (The date/time output line.) Having no luck finding it yet..

 
michellez
michellez's picture

Joined: 2002-11-07
Posts: 39
Posted: Mon, 2002-11-11 12:11

How I've adjusted it to GMT:

Edited the file classes/Comments.php

Where it states:
$this->datePosted = time();

In the block of code:
function Comment($commentText, $IPNumber, $name, $UID="") {

$this->commentText = $commentText;
$this->datePosted = mktime();
$this->IPNumber = $IPNumber;
$this->name = $name;
$this->UID = $UID;
}

I changed this to:
$this->datePosted = mktime();

Then where is says:
return date("M d, Y H:i T", $time);

In the block of code:
function getDatePosted() {
$time = $this->datePosted;
return gmdate("M d, Y H:i T", $time);
}

I changed it to:
return gmdate("M d, Y H:i T", $time);

This solved my problem of my website being hosted in the US while I'm in England and so displaying the time there and not here :grin:

Hope that helps someone!

 
BaconSandwich

Joined: 2003-04-16
Posts: 4
Posted: Fri, 2003-05-09 16:18

Yes, the above works! It even adjusts comments that have already been posted. Thanksmichellez!

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Fri, 2003-05-09 16:37

Hmm... we could use PEAR's Date package for this (obviously checking if it's installed first). It would allow the option of setting a local time either for the whole site, or for individual users...

 
prophet

Joined: 2003-09-01
Posts: 12
Posted: Wed, 2003-09-03 17:24

The quick oneoff I used, since I can almost guarantee most folks will be coming from eastern, is the following:

class Comment {
	var $commentText;	// text of comment 
	var $datePosted; 	// time() the comment was entered
	var $IPNumber; 		// IP number from which the comment was posted
	var $name;		// name or email of person who entered comment
	var $UID;		// UID of person who entered comment

	function Comment($commentText, $IPNumber, $name, $UID="") {

		$this->commentText = $commentText;
		$this->datePosted = mktime();
		$this->IPNumber = $IPNumber;
		$this->name = $name;
		$this->UID = $UID;
	}

	function getCommentText() {
		return $this->commentText;
	}

	function getDatePosted() {
		$time = $this->datePosted;
		putenv ("TZ=EST5EDT"); 
		return strftime("%m %A, %Y %H:%M %Z", $time); 
	}

	function getIPNumber() {
		return $this->IPNumber;
	}

	function getName() {
		return $this->name;
	}
	
	function getUID() {
		return $this->UID;
	}
}

If there's a way to use javascript to determine the user's timezone, this would be even cooler. You know, browsers really should send the timezone as part of the GET or POST request so the server knows where they are easily ;)

-P

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Thu, 2003-09-04 02:02

I've added a plan for v1.4.1 to add two items to Gallery:

1) Main configuration allows timezone offset (in case your server doesn't match). Drop-down for time offset.
2) Add the same thing to the user preferences, so each user can set her/his own timezone.

I want to shy away from detecting specific timezones (EDT, etc.) since we can't always tell whether the server is set to local time, or to GMT, or UTF.

Comments, thoughts about the best thing to do for the Gallery codebase?

 
prophet

Joined: 2003-09-01
Posts: 12
Posted: Fri, 2003-09-05 00:14

From an algorithmic perspective, frankly it doesn't matter if the server is in martian time -- as long as it's true to itself (if the admins change system time frequently, this method will suck, but then again, so will everything else).

I suggest that you store the timestamp in epoch time from the server's perspective, and when people hit the site, use javascript to get what **they** think the local time is on their remote machine. Compare it to what's on the server at that moment, create an offset, and add or subtract that from what the server thinks the time was when the comment was created, or picture added, or anything else that you're tracking time for. That way, it will always be correct relative to the user's computer.

The benefit here is that obviously, there's no database for each user's timezone, it's always correct relative to the computer you're on, and you don't need to be logged in :) If I fly to across the country, it will still seem right, as long as the machine I'm on has the right time ;)

-P

 
DanLivo

Joined: 2005-01-27
Posts: 3
Posted: Thu, 2005-01-27 01:11
beckett wrote:
I've added a plan for v1.4.1 to add two items to Gallery:

1) Main configuration allows timezone offset (in case your server doesn't match). Drop-down for time offset.
2) Add the same thing to the user preferences, so each user can set her/his own timezone.

I can't seem to find any server offset in the config or any further discussion on this in the forums...

This is of particular importance to me as I'm in Australia, but hosted in the US. So there's about a 17 hour time difference (depending on daylight saving) which means nearly all albums say they are posted the day before they actually were. Likewise comment time stamps are totally shot.

Any solution to this?

Thanks

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Thu, 2005-01-27 13:53

This never got finished. :(

Actually, this never got started either. :roll: I'll see if I can resurrect it somewhat on the feature todo list, but it's likely it won't get done soon unless someone jumps in and implements it...

-Beckett (

)

 
khoa
khoa's picture

Joined: 2005-05-03
Posts: 4
Posted: Tue, 2005-05-03 08:10

My website host won't change the timezone TZ variable for the site (I think the support folks don't know how), so the following one line addition to gallery/Comment.php file changes the TZ variable for Gallery's comment:

function getDatePosted() {
  global $gallery;
  putenv("TZ=PDT8PDT");  // Set to Pacific Daylight Savings Time
  $time = $this->datePosted;
  return strftime($gallery->app->dateTimeString, $time);
}

This works for the comment displayed when viewing a picture. There may be more places in Gallery that would benefit from the proper timezone setting.

Does anyone have a better place to putenv() TZ so that it would take effect for all of Gallery? This solution seems rather hacky.

Khoa

 
duvide

Joined: 2005-02-02
Posts: 15
Posted: Tue, 2005-08-16 15:19

Any idea how to resolve the time zone inssue in G2?

Thanks in advance/Frank

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2005-08-16 16:30

duvide,
post in the G2 forums as well as make a bug report or a RFE in the SF pages.