Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
start work on issue #59
Browse files Browse the repository at this point in the history
  • Loading branch information
ruleant committed Feb 16, 2015
1 parent 48fb49f commit 30bc0d0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
22 changes: 20 additions & 2 deletions buildtimetrend/build.py
Expand Up @@ -96,11 +96,17 @@ def get_properties(self):
if self.stages.started_at is not None and "started_at" not in data:
data["started_at"] = self.stages.started_at

if "started_at" in data:
data["started_at"] = split_isotimestamp(data["started_at"])

# add finished_at of last stage if it is defined
# and if it is not set in properties
if self.stages.finished_at is not None and "finished_at" not in data:
data["finished_at"] = self.stages.finished_at

if "finished_at" in data:
data["finished_at"] = split_isotimestamp(data["finished_at"])

return data

def set_started_at(self, isotimestamp):
Expand All @@ -110,7 +116,13 @@ def set_started_at(self, isotimestamp):
Parameters :
- isotimestamp : timestamp in iso format when build started
"""
self.add_property("started_at", split_isotimestamp(isotimestamp))
self.add_property("started_at", isotimestamp)

def get_started_at(self):
"""
Return timestamp when build started.
"""
return split_isotimestamp(self.get_property("started_at"))

def set_finished_at(self, isotimestamp):
"""
Expand All @@ -119,7 +131,13 @@ def set_finished_at(self, isotimestamp):
Parameters :
- isotimestamp : timestamp in iso format when build started
"""
self.add_property("finished_at", split_isotimestamp(isotimestamp))
self.add_property("finished_at", isotimestamp)

def get_finished_at(self):
"""
Return timestamp when build finished.
"""
return split_isotimestamp(self.get_property("finished_at"))

def load_properties_from_settings(self):
""" Load build properties from settings. """
Expand Down
4 changes: 2 additions & 2 deletions buildtimetrend/stages.py
Expand Up @@ -26,7 +26,7 @@

import csv
from buildtimetrend.tools import get_logger
from buildtimetrend.tools import split_timestamp
from buildtimetrend.tools import timestamp2iso
from buildtimetrend.tools import check_file
from buildtimetrend.tools import nano2sec
from lxml import etree
Expand Down Expand Up @@ -247,7 +247,7 @@ def set_timestamp(self, name, timestamp):
"""
if timestamp is not None and name is not None:
try:
self.data[name] = split_timestamp(timestamp)
self.data[name] = timestamp2iso(timestamp)
return True
except TypeError:
return False
Expand Down
23 changes: 21 additions & 2 deletions buildtimetrend/tools.py
Expand Up @@ -52,8 +52,27 @@ def split_timestamp(timestamp):
Parameters :
- timestamp : timestamp, seconds since epoch
"""
dt_utc = datetime.utcfromtimestamp(timestamp).replace(tzinfo=tzutc())
return split_datetime(dt_utc)
return split_datetime(timestamp2datetime(timestamp))


def timestamp2datetime(timestamp):
"""
Convert epoch timestamp into a datetime object.
Parameters :
- timestamp : timestamp in seconds since epoch
"""
return datetime.utcfromtimestamp(timestamp).replace(tzinfo=tzutc())


def timestamp2iso(timestamp):
"""
Convert epoch timestamp into an ISO timestamp formatted string.
Parameters :
- timestamp : timestamp in seconds since epoch
"""
return timestamp2datetime(timestamp).isoformat()


def split_isotimestamp(isotimestamp):
Expand Down
2 changes: 1 addition & 1 deletion buildtimetrend/travis.py
Expand Up @@ -469,7 +469,7 @@ def has_timing_tags(self):
Timing tags were introduced on Travis CI starting 2014-08-07,
check if started_at is more recent.
"""
started_at = self.current_job.get_property("started_at")
started_at = self.current_job.get_started_at()
if started_at is None or "timestamp_seconds" not in started_at:
return False

Expand Down

0 comments on commit 30bc0d0

Please sign in to comment.