set record timestamp

This commit is contained in:
Michael Davidsaver
2013-04-14 10:07:30 -04:00
parent 84a67c8e92
commit a834e4974d
2 changed files with 47 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import threading, sys, traceback
import threading, sys, traceback, time
from devsup.util import Worker
@@ -238,6 +238,24 @@ class Record(_dbapi._Record):
self._fld_cache[name] = fld
return fld
def setTime(self, ts):
"""Set record timestamp.
Has not effect if the TSE field is not set to -2.
Accepts timetuple, float, or (sec, nsec).
All inputs must be referenced to the posix epoch.
"""
if hasattr(ts, 'timetuple'):
ts = time.mktime(ts.timetuple())
try:
sec, nsec = ts
except TypeError:
sec = int(ts)
nsec = int(ts*1e9)%1000000000
super(Record, self).setTime(sec, nsec)
def __getattr__(self, name):
try:
F = self.field(name)