On 15-4-2013 22:12, Larry Martell wrote:
On Mon, Apr 15, 2013 at 1:59 PM, Lester Caine <les...@lsces.co.uk> wrote:
Larry Martell wrote:


No, I don't - this app runs in different locations all over the world.

I found some code at php.net that does this:

date_default_timezone_set(@date_default_timezone_get());
$deftz = date('T');

And that is working for me and giving me what I need.


But do you ACTUALLY know what time zone is stored IN the database? What if
te database was from another server?

One of the 'standards' adopted when working world wide is to ensure what is
stored IN the database is always UTC based. So you can always compare times
on the same consistent base. The only time you need the offset is to display
a local time, and that is either the time local to the server, or the time
local to the client.

The 'default' timezone is not necessarily the right one in either case ;)

I misspoke - the data in the db is in UTC. This is used to covert the
time of day on the server to the user's local timezone.


You are aware that the code you used is really bad practice, right? You're basically hiding the error "no default timezone set" by getting the default timezone, which returns an error; surpressing that error, providing the date_default_timezone_set function with the default value of date_default_timezone_get if none is defined (which there should!!), being "UTC".

So in short, you're saying "set the default timezone to the default timezone if no timezone is set, which I know there is not". That's very hard to understand for future programmers reading your code. Why not just set "date_default_timezone_set('UTC')". It's clear, resolves the warning and works perfectly, instead of relying on vague defaults somewhere, in the hope they're set right.

On a sidenote; the reason why your original "fix" did not work:
$deftz = date.timezone;
Is because date.timezone is an ini setting. Not valid PHP code. And the error actually tells you you need to SET date.timezone, not set a variable TO the ini setting. In other words, you wanted date.timezone = "UTC" instead of $tz = date.timezone (which makes no sense anyway)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to