Re: Sniping on the List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 17 Nov 2011, Tedd Sperling wrote:

On Nov 17, 2011, at 11:58 AM, Stuart Dallas wrote:
The epoch specifies the exact time that 0 represents. It makes no claims as far as that being the start of anything...

"defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of Thursday, January 1, 1970 (Unix times are defined, but negative, before that date)" [http://en.wikipedia.org/wiki/Unix_time]

Good reference to support your point, but strtotime() doesn't qork that way.

Yes it does.

$ php -r 'echo strtotime ("31 Dec 1969 23:59 +0000");'
-60

For example, if you push '-1' though strtotime(-1), you'll get Wednesday only one day a week -- whereas 'null' works every time.
Technically I see that as a bug. I believe strtotime(null) should return null, but due to the way type inference works, null is interpreted as 0. The point here being that you're not getting the time at null, you're getting the time at 0.


Nope, zero time is absolutely January 1, 1970 00:00:00 -- which was a Thursday. If you pass zero through strtotime(), it reports "December 1969" and I claim that to be a bug.

Not here it doesn't.

$ php -r 'echo date ("r", strtotime ("zero"));'
Thu, 01 Jan 1970 00:00:00 +0000

But it might for you (see below).

In addition, passing -1 through strtotime() simply returns today,

Here it returns a time an hour later than now.

$ date -R; php -r 'echo date ("r", strtotime ("-1"));'
Thu, 17 Nov 2011 20:41:06 +0000
Thu, 17 Nov 2011 21:41:07 +0000

whereas 'null' returns a date prior to the start of everything and that makes more logical sense to me.

but here we hit the crux of the problem. 'strtotime("null")' isn't returning a null timestamp, it's simply returning the value for an inability to convert the string "null" to a timestamp.

Of course, now that I try to reproduce the "null == Wednesday" result, I find that I can't. Everything comes up as Thu, 01 Jan 1970 00:00:00 +0000 which probably invalidates much of what I've written above. Maybe I'm not running a new enough PHP (latest I have access to is 5.3.3). But if this is the case, this suggests this behaviour changed relatively recently.

Anyway, as I was going to say, the correct way to find out what null is is to do something like:

echo date ("r", null);

But this thread has gone through so many twists now that I can't remember if this is where we began or not.

Geoff.


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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux