note 56312 added to function.time
| From: | php-general at lists dot php dot net | Date: | Tue, 30 Aug 2005 13:26:27 +0000 |
| Subject: | note 56312 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94426@lists.php.net to get a copy of this message | ||
> Too many people are doing this in here
> and its BAD programming practice:
> BAD: $timeinfuture = time() + 60 * 60;
> GOOD: $timeinfuture = strtotime("+1 hour");
> Reasoning: Leap days / seconds etc...
I don't think that's true.
1) Leap days are just fine, since if we add 3600 seconds,
we get 1 hour into the future, regardless of whether
that future is a leap day or not
2) Leap seconds do not *exist* with the value
returned from the time() function.
This is a point of great debate in the ISO committees,
but no changes are possible now without breaking
compatibility.
What I mean is, at the transition of a leap second,
the time() function is supposed to return values like this:
1320, 1321, 1322, 1322, 1323...
(Here, the time() function will return the same value
for both the LEAP SECOND and the second before it)
So, once again, adding 3600 gets us the desired result
(That is, if before it was Jan 3 at 3:45 AM,
then we will get Jan 3 at 4:45 AM,
regardless of leap seconds or leap year)
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56312
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56312&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56312&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56312&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56312&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56312&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56312&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56312&report=yes
Search -- http://master.php.net/manage/user-notes.php