Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

edited December 2013 in Beta Posts: 580

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.

Comments

  • Jmv38Jmv38 Mod
    edited December 2013 Posts: 3,295

    @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.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    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..)

  • edited December 2013 Posts: 580

    @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. (http://www.lua.org/manual/5.1/manual.html#pdf-os.time)

    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)

  • Posts: 1,255

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

  • Posts: 580

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

Sign In or Register to comment.