Save timestamp in UTC format

This commit is contained in:
nemunaire 2015-02-18 01:48:02 +01:00
parent dacb618069
commit 2e7a4ad132
2 changed files with 7 additions and 7 deletions

View file

@ -215,6 +215,8 @@ class Bot(threading.Thread):
except ValueError: except ValueError:
evt.id = eid evt.id = eid
# TODO: mutex here plz
# Add the event in its place # Add the event in its place
t = evt.current t = evt.current
i = 0 # sentinel i = 0 # sentinel

View file

@ -16,10 +16,10 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import xml.sax import calendar
from datetime import datetime, timezone from datetime import datetime, timezone
import logging import logging
import time import xml.sax
logger = logging.getLogger("nemubot.tools.xmlparser.node") logger = logging.getLogger("nemubot.tools.xmlparser.node")
@ -82,13 +82,11 @@ class ModuleState:
return source return source
else: else:
try: try:
return datetime.fromtimestamp(float(source), timezone.utc) return datetime.utcfromtimestamp(float(source)).replace(tzinfo=timezone.utc)
except ValueError: except ValueError:
while True: while True:
try: try:
return datetime.fromtimestamp(time.mktime( return time.strptime(source[:19], "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc)
time.strptime(source[:19], "%Y-%m-%d %H:%M:%S")),
timezone.utc)
except ImportError: except ImportError:
pass pass
@ -202,7 +200,7 @@ class ModuleState:
for att in self.attributes.keys(): for att in self.attributes.keys():
if att[0] != "_": # Don't save attribute starting by _ if att[0] != "_": # Don't save attribute starting by _
if isinstance(self.attributes[att], datetime): if isinstance(self.attributes[att], datetime):
attribs[att] = str(time.mktime( attribs[att] = str(calendar.timegm(
self.attributes[att].timetuple())) self.attributes[att].timetuple()))
else: else:
attribs[att] = str(self.attributes[att]) attribs[att] = str(self.attributes[att])