Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a value such as 'timestamp' below, where the last three digits correspond to milliseconds.

timestamp = 1340830988768

I currently have code that looks like the following:

import indicate
indicator = indicate.Indicator()
indicator.set_property_time("time", int(timestamp[:-3]))

I want to amend it to use:

from gi.repository import Indicate
indicator = Indicate.Indicator()

However, the new version of set_property_time requires the second parameter to be a GLib.TimeVal. How do I create a GLib.TimeVal from my timestamp? Millisecond precision is not important for this application.

share|improve this question
add comment

1 Answer

This is what I came up with, maybe it is of any help:

>>> from gi.repository import GLib, Indicate
>>> timestamp = '1340830988768'
>>> indicator = Indicate.Indicator()
>>> timeval = GLib.TimeVal()
>>> timeval.tv_sec = int(timestamp[:-3])
>>> indicator.set_property_time("time", timeval)
>>>

Do note this section in the GLib reference manual:

GLib is attempting to unify around the use of 64bit integers to represent microsecond-precision time. As such, this type will be removed from a future version of GLib.

share|improve this answer
    
Thank you! I think this is what I need, but I can't confirm until I fix some other issues with my code. –  fluteflute Jul 3 '12 at 12:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.