QT: How do I subtract clocktimes?

Mark Schonewille m.schonewille at economy-x-talk.com
Thu Sep 20 16:26:06 EDT 2007


Hi William,

Devin answered already and although I haven't tested it, I believe  
his solution is the most straighforward one.

If you want a more general solution, you run into a bug, which causes  
Revolution to return times, which are one hour off. The bug is said  
to be fixed, as you can read here <http://quality.runrev.com/qacenter/ 
show_bug.cgi?id=2387> but date calculations are still far from  
straightforward in Revolution. Maybe we should re-open that bug report?

The following is an attempt to provide a function that calculates  
time differences regardless of platform. Unfortunately, it fails  
miserable on Windows, if time difference is less than an hour. Also,  
I am not sure what the effect of daytime savings is. In theory, it  
should work, but it doesn't. I didn't test this on Linux yet.

-- this script does not always work correctly!
function clockTimeDif theTime1,theTime2,theFormat
   set the useSystemDate to true
   if theFormat is empty then put "short time" into theFormat
   if not (theFormat contains "sec") then
     -- correct for rev bug
     put the time into myTime
     convert myTime to long internet time
     put char -2 to -1 of myTime into myZoneM
     put char -4 to -3 of myTime into myZoneH
     put myZoneM * 60 + myZoneH * 60^2 into myBug
     -- another bug in Windows? DST?
     if the platform is "Win32" then
       subtract 60^2 from myBug
     end if
   else put 0 into myBug
   -- convert and subtract
   convert theTime1 from short time to seconds
   convert theTime2 from short time to seconds
   put (theTime1 - theTime2 - myBug) into myDif
   -- convert
   do "convert myDif from seconds to" && theFormat
   -- done
   return myDif
end clockTimeDif


end clockTimeDif

Why can't we just convert time to seconds, do the calculation and  
convert back the result to a time format? Shouldn't this be simple?

Best regards,

Mark Schonewille

--

Economy-x-Talk Consulting and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Quickly extract data from your HyperCard stacks with DIFfersifier.  
http://differsifier.economy-x-talk.com


Op 20-sep-2007, om 20:16 heeft William de Smet het volgende geschreven:

> Hi there all,
>
> I am subtracting some numbers and that is working ok with the  
> following code:
> put value (field "xt" - field "y") into fld "z"
>
> What If I want to use clock times like: 07.30 (seven thirty in the  
> morning) ?
> When I subract '16.00 - 07.30' I get '8.7' and I want it to be '08.30'
> So now Rev sees these numbers as decimal numbers.
>
> What code need I put in there to make it work?
>
>
> greetings,
>
> William de Smet





More information about the use-livecode mailing list