Forum

Please note that you can subscribe to the individual forums. A subscription for news only covers the news.

Notifications
Clear all

Time math

   RSS

0
Topic starter

Not quite sure, if it should work so, or not.

I have a code:

set!=!timePassed,!zzTime
subtract!=!timePassed,!lastUsageTime
round!=!timePassed,01:00
hours#=#timePassedHours,!timePassed

In the stat file: !lastUsageTime=1899-12-30 1600

In report it's work looks like:

mo 02 1751 !timePassed=1751
mo 02 1751 !timePassed=0151
mo 02 1751 !timePassed=0200
mo 02 1751 #timePassedHours=1

 

A bit later run of the same code:

mo 02 1852 !timePassed=1852
mo 02 1852 !timePassed=0252
mo 02 1852 !timePassed=0200
mo 02 1852 #timePassedHours=1

 

Ok, trying to set !lastUsageTime=1899-12-30 1500

mo 02 1851 !timePassed=1851
mo 02 1851 !timePassed=0251
mo 02 1851 !timePassed=0200
mo 02 1851 #timePassedHours=1

 

I'm just too curious to stop! 🙂

Ok, trying to set !lastUsageTime=1899-12-30 1500

mo 02 1844 !timePassed=1844
mo 02 1844 !timePassed=0244
mo 02 1844 !timePassed=0300
mo 02 1844 #timePassedHours=3

 

Seems hour# has some problems with being equal to 2 🙂

Ok, can it be any even number?

Setting !lastUsageTime=1899-12-30 1400

mo 02 1832 !timePassed=1832
mo 02 1832 !timePassed=0432
mo 02 1832 !timePassed=0400
mo 02 1832 #timePassedHours=3

 

Seems hours#=... has something against even numbers 🙂 At least after rounding.

If I comment "round!=!timePassed,01:00" line, even numbers of hours are ok:

mo 02 1853 !timePassed=1853
mo 02 1853 !timePassed=0253
mo 02 1853 #timePassedHours=2

 

Some magic is going on there... 🙂 Hope it can be fixed.

 

As for my case, I've switched to minutes to bypass this problem in my script:

set!=!timePassed,!zzTime
subtract!=!timePassed,!lastUsageTime
minutes#=#timePassedMinutes,!timePassed
set#=#timePassedHours,#timePassedMinutes
divide#=#timePassedHours,60

And it works fine, after some recalculations of "points" for "hours". Maybe next time I'll do it in seconds for even more accurate calculations.

Topic Tags
2 Answers
0

A time variable is really the number of days since 1899-12-30. With the time part being a fraction. As en example 0.5 is 6 hours. And one hour is 0.0416666....

Calculating on numbers like that can give rounding problems. And often does. That is the explanation of the strange behaviour.

If the 2 hours are just a fraction of a second less that the 2 hours, #hours will give 1, #minutes will give 59 and #seconds will give 59.

Usually all this is not a problem, though you sometimes see some strange time intervals in the report. But with creative calculations, it can give strange results, as you have seen.

Maybe I can do something about #hours, #minutes, #seconds to make them behave better. I will look into it.

 

Quite another subject:

Setting a variable to !zzTime, and later subtract it from !zzTime to get the difference, works fine, as long as you don't cross midnight. If you instead use !zzNow, it will work across midnight as well. Just a tip.

Sven

 

 

@admin Thank you for explanation and a tip. After the way of combining date part with time part into one variable using !zzNow is very easy.

And I'm very used to unixtime for some date math, so going into minutes and seconds seems very common for me.

0

@asub: Check how it works in the new beta 10.

Sven