Possible bug: does os.time() always return the same value?

Running this test, I always get the same value from os.time(). Can anyone else verify this?

function setup()
    local t1 = os.time()
    tween.delay(1, function()
        local t2 = os.time()
        print("t1:", t1)
        print("t2:", t2)
        print("t1 == t2:", t1 == t2)
        print("os.difftime(t2, t1):", os.difftime(t2, t1))
    end
end

Not sure if it’s a problem for the latest release build, or just the beta build, or just my ipad, but at any rate I’m pretty sure this behavior is incorrect.

@Toadkick i get the same as you. But this is not new:

  • os.time is mean for days and hours, not seconds: the Sub-second is beyond the number precision.
  • os.clock is to be used to measure seconds, or ms.

When i want the seconds i actually use os.date.
After your remark, i notice i’ve always used os.clock, os.date , or elapsedtime, and never os.time… I run the ‘standard’ version of Codea, not the beta (waiting for a beta with real value for me, like the clipboard…)

@Jmv38:

- os.time is mean for days and hours, not seconds: the Sub-second is beyond the number precision.

That’s not strictly true…where did you find this out from? It’s actually platform independent what is returned. (Lua 5.1 Reference Manual)

I’ve just not been able to find out what it’s returning for this particular platform.

(And yeah, I’ve started using os.date() too, it’s just kind of a pain)

The precision of os.time means it only gets updated at intervals of a couple of minutes.

@Mark @Jmv38 Thanks for clearing it up for me guys :slight_smile: I’ll just use something else.