diff options
| author | 2019-04-23 21:27:43 +0100 | |
|---|---|---|
| committer | 2019-04-23 21:27:43 +0100 | |
| commit | 87340bcbf91bba1aafd6beb77d6c64a595e6e5b0 (patch) | |
| tree | d2b9e6568469b071b582eede31381fb089c5f2b4 /src | |
| parent | Only show 'submitted' pull_request_review events (diff) | |
| signature | ||
change utils.iso8601_format to default to no milliseconds, switch to using
utils.iso8601 functions in badges.py
Diffstat (limited to 'src')
| -rw-r--r-- | src/IRCServer.py | 3 | ||||
| -rw-r--r-- | src/Logging.py | 2 | ||||
| -rw-r--r-- | src/utils/__init__.py | 12 |
3 files changed, 13 insertions, 4 deletions
diff --git a/src/IRCServer.py b/src/IRCServer.py index 3989374f..217dfe4c 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -236,7 +236,8 @@ class Server(IRCObject.Object): self.ping_sent = False now = datetime.datetime.utcnow() - self.set_setting("last-read", utils.iso8601_format(now)) + self.set_setting("last-read", + utils.iso8601_format(now, milliseconds=True)) return lines def send(self, line_parsed: IRCLine.ParsedLine): diff --git a/src/Logging.py b/src/Logging.py index fe7f3f91..49267086 100644 --- a/src/Logging.py +++ b/src/Logging.py @@ -13,7 +13,7 @@ LEVELS = { class BitBotFormatter(logging.Formatter): def formatTime(self, record, datefmt=None): datetime_obj = datetime.datetime.fromtimestamp(record.created) - return utils.iso8601_format(datetime_obj) + return utils.iso8601_format(datetime_obj, milliseconds=True) class Log(object): def __init__(self, to_file: bool, level: str, location: str): diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 22cff3b1..0a51493f 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -7,9 +7,17 @@ class Direction(enum.Enum): ISO8601_PARSE = "%Y-%m-%dT%H:%M:%S%z" -def iso8601_format(dt: datetime.datetime) -> str: - formatted = dt.isoformat(timespec="milliseconds") +def iso8601_format(dt: datetime.datetime, milliseconds: bool=False) -> str: + timespec = "seconds" + if milliseconds: + timespec = "milliseconds" + + formatted = dt.isoformat(timespec=timespec) return "%sZ" % formatted +def iso8601_format_now() -> str: + return iso8601_format(datetime.datetime.utcnow()) +def iso8601_parse(s: str) -> datetime.datetime: + return datetime.datetime.strptime(s, ISO8601_PARSE) TIME_SECOND = 1 TIME_MINUTE = TIME_SECOND*60 |
