0

Server time.

Is there a way of asking shotgun what time it is?

 I'm working on a time logging hook to automatically keep track of how much time is spend on various tasks.

 I would like that if a person opens a file under a task they were working on 10 minutes ago, it does not create a new TimeLog, but continues updating the same TimeLog they had before.

I know for a fact that several of our machines are more than 5 minutes different from eachother, so I feel I cannot rely on the computer's local time to determine if the user has a TimeLog matching their task that was last updated within the past 10 minutes.

Many thanks,

 -derick

 

댓글 2개

  • 0
    Avatar
    KP

    Hi Derick,

    Keeping time is a little out of scope for the Shotgun API ;).

    When you create or update a TimeLog (or any entity in Shotgun), the updated_at field will be time-stamped with the server time on it (the created_at field will obviously be time-stamped when the entity is created). So I guess I see the issue since if the client machine is 5 minutes off from that, and you compare timestamps, you don't have a consistent baseline. While I think it might be easier to ensure that your machines are all getting synced with an NTP system so that you could better rely on the server time (which is also synced with a time server), perhaps there's a reason you can't do this?

    Otherwise, maybe you could use the ntplib python module to get a good standard timestamp and then create an additional field on TimeLog to store this standard timestamp in. Then you could use that each time you check before creating/updating your TimeLogs? Would that work?

    import ntplib
    from time import ctime
    c = ntplib.NTPClient()
    response = c.request('pool.ntp.org')
    print ctime(response.tx_time)
    

     

  • 0
    Avatar
    Derick Dressel

    Fantastic!

    I'll talk to IT about getting everyone synced to the rest of the world, and use that module just in case someone is working on some system not configured to reference a time server.

    Thank you so much :)

     

댓글을 남기려면 로그인하세요.