[pmwiki-users] How to: calculate how many days left

Patrick R. Michaud pmichaud at pobox.com
Wed Feb 27 12:19:44 CST 2008

On Wed, Feb 27, 2008 at 05:51:56PM +0000, Hans wrote:
> Wednesday, February 27, 2008, 5:29:02 PM, Patrick R. Michaud wrote:
> >     {(div (sub (ftime %s {$:Date}) (ftime %s today)) 86400)}
> > One should note that both this and the udays approach have a
> > potential problem if the range of dates span changes in daylight
> > savings time.  In this case the difference will not be an even
> > multiple of 86400, and using floor() will provide an incorrect
> > value.
> The expression above will indeed produce a fraction in this case,
> but using
>     {(sub (udays '{$:Date}') (udays now) )}
> will still result in an integer number of days. 

...but that integer number of days will be incorrect (off by one)
in certain timezones and locales, since we can end up with two
midnights that have the same day number.

For example, in the U.S., the time difference between
2008-03-09T00:00 and 2008-03-10T00:00 is only 82800 seconds.

It's a minor nit, but just wanted to point out that the algorithm 
is not entirely accurate.


More information about the pmwiki-users mailing list