On Sat, 19 Nov 2011, Tedd Sperling wrote:
My observations are demonstrated here:
http://www.webbytedd.com/cccc/strtotime/index.php
this code would IMHO be more useful if it also displayed time, not just
date. It's also not clear what timezone you're using, as it's not set as
far as I can see.
Please note that regardless of time zone, the strtotime() function works
(or at least it does for me) such that:
If you enter '-1', the function will report back Todays Date with
current seconds. Note there is no difference between entering 'Today' or
'-1'.
This is not what your code shows.
String Given: -1
Seconds Computed from String: 1321805103
Date from Seconds Computed: 20 November, 2011 : Sunday
___________________________________________________________________________
Current Time (seconds): 1321819503
Current Date: 20 November, 2011 : Sunday
This is a difference of 14400 seconds or 4 hours.
String Given: today
Seconds Computed from String: 1321765200
Date from Seconds Computed: 20 November, 2011 : Sunday
___________________________________________________________________________
Current Time (seconds): 1321819877
Current Date: 20 November, 2011 : Sunday
This is a much larger difference. 'today' is meant to return the same as
'today 00:00:00'. I know it used not to, it was a PHP bug awhile back...
which begs the question, which PHP version are you using?
If you enter '0', the function will report back December, 31, 1969.
You'll also notice that the value of seconds computed from string is
blank (i.e. not 0). This is because strtotime() doesn't know what to do
with a value of '0'. Whether it should or not is probably a
phillosophical debate.
If you enter nothing (i.e., null), then it reports back December, 31, 1969.
It does, but we dont' know exactly when this is because your script
doesn't show time. It could be actually returning a 0 timestamp.
We can force your script to show us what 0 time is according to its
timezone by entering an absolute date including UTC offset.
String Given: 1 January 1970 +0000
Seconds Computed from String: 0
Date from Seconds Computed: 31 December, 1969 : Wednesday
___________________________________________________________________________
So your script shows 31/12/1969 for the epoch, so we dont' know if the
null value is the epoch or before.
To further prove my point, witness the number of seconds calculated from 1
January 1970 in your script's timezone:
String Given: 1 January 1970
Seconds Computed from String: 18000
Date from Seconds Computed: 1 January, 1970 : Thursday
___________________________________________________________________________
This means your script is using a timezone of UTC -0500 (US Eastern). So
any time within the first 5 hours of the epoch will show as being in 1969.
To avoid this, explicitly set your script to use UTC. Or use US Eastern
but be up front about the fact that your'e doing this.
It's clear (and by definition) that unix zero time (i.e., 00:00:00) happened in 1970.
It's also clear that time before unix zero happened before 1970 (i.e., 'December 31, 1969').
As such, null (and not the string 'null' as stated my someone else, duh) should come back as "undefined" OR "December, 31, 1969".
It doesn't for me, using either PHP 5.2.6 or 5.3.3.
php -r 'echo date ("r", strtotime (""));'
Thu, 01 Jan 1970 00:00:00 +0000
Furthermore, the string '-1' should default to '-1 second' instead of being the same as if I entered 'Today'.
Apart from the fact that for me at least, strtotime ("today") returns
today at midnight, whereas strtotime ("-1") seems to return something else
(time() + 3600 on boxes set to UTC, time() + 10800 on my box set to local
time in Israel), strtotime is meant to turn textual representations of
time into a unix timestamp. Surely the meaning of "-1" is at the very
least ambiguous, and the fact that it returns anything is surprising.
Now, where are my observations wrong? The code is shown in the demo.
To summarise, your observations are wrong because they do not take
timezone into account and do not show the time, only the date. And some
of your observations as given above do not match what your script outputs.
Geoff.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php