[pmwiki-users] Today Tomorrow the day after and so on

Patrick R. Michaud pmichaud at pobox.com
Mon Apr 3 08:43:22 CDT 2006


On Mon, Apr 03, 2006 at 10:47:08AM +0100, Hans wrote:
> for tomorrow you can add to time() 24*60*60=86400 (seconds in a day):
> $FmtPV['$Tomorrow'] = 'strftime("%Y-%m-%d", time()+86400 )';
> 
> etc. multiples of 86400

Be careful -- not every day has 86400 seconds in it.  :-)

Yesterday in the United States the day had only 82800 localtime 
seconds in it (switch to daylight savings time), so from 2300h 
to midnight on April 1st the above would've incorrectly indicated 
"tomorrow" as being "2006-04-03".

Similarly, on October 29th of this year, the day will have 90000
localtime seconds in it, so from midnight to 0100h on that day
the above will incorrectly indicate "tomorrow" as "2006-10-29".

For this particular application, the difference might not be
worth worrying about.  However, I once wrote a financial
application that made the assumption of 86400 seconds in a day,
and the client was a little surprised when a day would go missing
in April and be repeated in October...

For a robust mechanism of computing tomorrow, "next week", "next
month", etc., try:

    list($sc, $mn, $hr, $dy, $mo, $yr) = localtime();
    
    $tomorrow = strftime('%Y-%m-%d', 
                         mktime($hr, $mn, $sc, $mo, $dy+1, $yr));

    $oneweek = strftime('%Y-%m-%d',
                         mktime($hr, $mn, $sc, $mo, $dy+7, $yr));

    $onemonth = strftime('%Y-%m-%d'
                         mktime($hr, $mn, $sc, $mo+1, $dy, $yr));

Pm




More information about the pmwiki-users mailing list