Logical reason for strtotime("east") and strtotime("west") returningvalid results?
Logical reason for strtotime("east") and strtotime("west") returningvalid results?
am 05.04.2010 19:39:55 von Colin Guthrie
Hi,
Long time no speak!
As part of a quick filter I'm writing I try to interpret free text
strings as dates and textual data.
Sometimes, this goes wrong.
For example, I discovered that some words (or strings beginning with
those words) will return false positives:
e.g.:
[colin@jimmy Search (working)]$ php -r 'var_dump(strtotime("east"));'
int(1270514111)
[colin@jimmy Search (working)]$ php -r 'var_dump(strtotime("west"));'
int(1270488914)
[colin@jimmy Search (working)]$ php -r 'var_dump(strtotime("now"));'
int(1270488928)
The last one is valid! But the other two appear to do much the same thing...
Can anyone think of why this would be valid results before I report this
to the relevant authorities?
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Logical reason for strtotime("east") and strtotime("west")returning valid results?
am 05.04.2010 20:15:32 von Kevin Kinsey
Colin Guthrie wrote:
>
> For example, I discovered that some words (or strings beginning with
> those words) will return false positives:
>
> e.g.:
>
> [colin@jimmy Search (working)]$ php -r 'var_dump(strtotime("east"));'
> int(1270514111)
> [colin@jimmy Search (working)]$ php -r 'var_dump(strtotime("west"));'
> int(1270488914)
> [colin@jimmy Search (working)]$ php -r 'var_dump(strtotime("now"));'
> int(1270488928)
>
>
> The last one is valid! But the other two appear to do much the same thing...
>
> Can anyone think of why this would be valid results before I report this
> to the relevant authorities?
Time Zones?
[11] Mon 05.Apr.2010 13:05:41 [admin@archangel][~]
php -r "echo date('r',strtotime('now'));"
Mon, 05 Apr 2010 13:05:47 -0500
This is correct for my timezone (US Central Daylight Time).
[12] Mon 05.Apr.2010 13:05:47 [admin@archangel][~]
php -r "echo date('r',strtotime('east'));"
Mon, 05 Apr 2010 14:05:51 -0500
This is correct for the time zone east of me, US Eastern Daylight Time.
However, the TZ offset is wrong for that TZ, it's still mine.
[13] Mon 05.Apr.2010 13:05:51
[kadmin@archangel][~]
php -r "echo date('r',strtotime('west'));"
Mon, 05 Apr 2010 07:05:59 -0500
This is correct for American Samoa, but I've no idea why :-D
Nonetheless, I'm suspecting the programmers had something
like this in mind. Isn't strtotime() based on some GNU utility?
Kevin Kinsey
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Logical reason for strtotime("east") and strtotime("west") returningvalid results?
am 06.04.2010 18:16:30 von Colin Guthrie
'Twas brillig, and Kevin Kinsey at 05/04/10 19:15 did gyre and gimble:
> Nonetheless, I'm suspecting the programmers had something
> like this in mind.
Yeah I guess that's why it interprets these terms. Good thinking :)
> Isn't strtotime() based on some GNU utility?
Yeah, that's why I said "the relevant authorities". I couldn't remember
off-hand where it came from so figured I'd not blame "PHP" just yet :p
Cheers
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Logical reason for strtotime("east") and strtotime("west")returning valid results?
am 07.04.2010 06:21:15 von Kevin Kinsey
Colin Guthrie wrote:
> 'Twas brillig, and Kevin Kinsey at 05/04/10 19:15 did gyre and gimble:
>> Nonetheless, I'm suspecting the programmers had something
>> like this in mind.
>
> Yeah I guess that's why it interprets these terms. Good thinking :)
>
>> Isn't strtotime() based on some GNU utility?
>
> Yeah, that's why I said "the relevant authorities". I couldn't remember
> off-hand where it came from so figured I'd not blame "PHP" just yet :p
Apparently these strings are being recognized as TZ stamps, but the underlying
logic is "not fully implemented": see
http://www.gnu.org/s/libc/manual/html_node/Low_002dLevel-Tim e-String-Parsing.html
Try it with some TZ stamps ... I'm pretty sure that in the previous
example it was taking "East" to be "EST", as I observed (rather by
accident) earlier.
Kevin Kinsey
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Logical reason for strtotime("east") and
am 07.04.2010 10:26:49 von Peter Lind
On a related note: does anyone know why
php -r "echo date('Y-m-d H:i:s', strtotime('a'));"
happily outputs a valid timestamp? And why all other letters work as
well (but only one character)? I'm sure there's a good reason for it,
it just completely escapes me right now :)
Regards
Peter
--
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php