The seconds problem - redefined

Dar Scott dsc at swcp.com
Thu Apr 15 01:23:06 EDT 2004


On Wednesday, April 14, 2004, at 09:39 PM, SimPLsol at aol.com wrote:

>      Hope that helps. Now back to the original question. Is there a 
> way to
> convert dates to seconds where every day has 86400 seconds?

Of course.

The problem is not just that Revolution thinks some days are 23 hours 
and some days are 25 hours.  In your environment, they _are_ just 23 
hours and 25 hours.  Revolution convert uses your environment.  I 
remember it like this:  "Convert is a command, not a function."

You are using an exact second match for something that does not exist 
as an exact second match.  This is for two reasons.  first of all the 
edge of the day changes.  Second, it is unreliable to do exact equality 
on floating point.

A quick fix would be to have a tolerance in your match text.  Look for 
a match plus or minus a few hours.

Another is what you asked for.  Take a day number and multiply by 
86400.  This will be meaningful as day-number-times-86400.

Or you can simply go with day numbers.

>      1. Does such a conversion exist in Revolution now?

>      2. If not, shouldn't it?

It would be nice to have date and time functions that do not look at 
time zone and daylight-savings parameters of the system but take these 
data as function parameters or settings.  In your case, you will use 
trivial values for these.  There are always special cases, though.  
Historically, some locals made gradual calendar changes and some 
switched back and forth.

A day value with the fraction being the fraction of the day is popular. 
  I have seen it in COM and in MATLAB.  The most general popular scheme 
seems to be the Julian Day which starts at noon GMT on some day long 
ago.

Even these can have creeping errors.  However for comparing day 
numbers, I suspect it is sufficient to round both day numbers and 
compare.  Even floating point equality should work.  Remember, daylight 
savings will shift around this, too.

> One that also calls for consistent seconds based
> on GMT.

Seconds is based on GMT.  Your time zone may not be GMT.

> PPS More fuel on the fire: finding days between dates will not produce 
> whole
> numbers if you convert the dates to seconds and divide by 86400 - when 
> the
> date range spans a 23 or 25 hour day.

Of course not.  You are asking for the seconds between midnight one day 
to midnight another day.

Dar Scott



More information about the use-livecode mailing list