segdeha / phpfr

Automatically exported from code.google.com/p/phpfr
0 stars 0 forks source link

PHP problems with SL 10.6.2 #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Click on the little calendar icon
2. Enter 'Y' into the date selection box
3. See:
Warning: date(): It is not safe to rely on the system's timezone settings. You 
are *required* to use 
the date.timezone setting or the date_default_timezone_set() function. In case 
you used any of 
those methods and you are still getting this warning, you most likely 
misspelled the timezone 
identifier. We selected 'UTC' for 'GMT/0.0/no DST' instead in 
/Users/pc/Library/Widgets/PHPfr.wdgt/Assets/php/date.php on line 26 2009

What is the expected output? 2009

What do you see instead? as above

What version of the product are you using? 1.0.1

On what operating system? SL 10.6.2

Please provide any additional information below.

Original issue reported on code.google.com by p...@hillside.co.uk on 10 Nov 2009 at 4:45

GoogleCodeExporter commented 9 years ago
Hmm. Perhaps work arounds from the authors are not speedy.

I am in the UK and adding:

date_default_timezone_set('UTC');

after the ); which terminates the constants array in 
..home/Library/Widgets/PHPfr.wdgt/Assets/php/date.php
works for me. If you are in another timezone, then you can do this by hand. See 
below for context.

I had sort of expected that
date_default_timezone_set(date_default_timezone_get());

would work - but it didn't. The code needs to look at the system to get the 
timezone, if Apple isn't prepared to get php configured 'properly', it 
probably needs to use some posix type lookups to get the system time and set 
the timezone correctly. However, I suggest that you use the widget 
and lookup 
date_default_timezone_set
to find the timezone for you - then the quick and dirty hack will also work.

Here's the context for the code change - replace UTC by your timezone.

Old code:

        'DATE_W3C'     => DATE_W3C
);

if (!isset($argv[1]) || '' == $argv[1]) {
        $return = ' ';

New code:

        'DATE_W3C'     => DATE_W3C
);
date_default_timezone_set('UTC');

if (!isset($argv[1]) || '' == $argv[1]) {
        $return = ' ';

Original comment by p...@hillside.co.uk on 10 Nov 2009 at 6:47

GoogleCodeExporter commented 9 years ago
Thanks for alerting me to this. I expect Apple will fix this issue in a future 
OS release, but I will add your patch to 
the date parsing script in the meantime.

Original comment by segdeha on 10 Nov 2009 at 7:13

GoogleCodeExporter commented 9 years ago
I've been looking to see if there is a way of identifying the timezone from the 
system. It seems to be stored in a pllst - so if you 
replace the date_default_timezone_set('UTC') by this code, I think it should 
generate local times for people.

I've attempted to make this as safe as possible - but it probably should be 
tested on several machines to see if works - seems to 
work here of course:

// Use the .GlobalPreferences file to obtain the system timezone
// There is probably some official API that allows the read of
// the property list - but it seems just as easy to use the
// standard system command 'defaults'
$defaultTimezone = 'UTC';
$handle = @popen("/usr/bin/defaults read 
/Library/Preferences/.GlobalPreferences 
com.apple.TimeZonePref.Last_Selected_City", 
"r");
if ($handle) {
        $buffer = "";
        while (!feof($handle)) {
                $buffer .= fread($handle, 8192);
        }
        pclose($handle);
        // this ought to be something that looks like
        //(
        // "51.500000",
        // "-0.166656",
        //  11,
        // "Europe/London",
        // GB,
        //  London,
        // England,
        // London,
        // England
        // )
        // and we need line 5
        // 
        $parse = explode(",", $buffer);
        if (count($parse) > 4) {
                $tz = trim($parse[3]);
                if (preg_match('/"([^"]*)"/', $tz, $ma)) {
                        $defaultTimezone = $ma[1];
                }
        }
}
if (!date_default_timezone_set($defaultTimezone)) {
        date_default_timezone_set("UTC");
}

Original comment by p...@hillside.co.uk on 10 Nov 2009 at 11:57

GoogleCodeExporter commented 9 years ago
Here's my current date.php

Original comment by p...@hillside.co.uk on 10 Nov 2009 at 11:58

Attachments:

GoogleCodeExporter commented 9 years ago
Incidentally PHP expects you to set the timezone in php.ini - and so I don't 
think that Apple can really do that 
and retain world portability.

Original comment by p...@hillside.co.uk on 11 Nov 2009 at 12:02