From 9d1c80e107b40cf0ec27201ade06a10450f36b8c Mon Sep 17 00:00:00 2001 From: dogoncouch Date: Thu, 5 Apr 2018 18:43:28 -0400 Subject: [PATCH] Fix bug with single digit months in now/nodate datestamp converters --- CHANGELOG.md | 4 ++++ logdissect/utils.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 198076e..f0834d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change log Change log for [logdissect](https://github.com/dogoncouch/logdissect) +## [Unreleased] +### Fixed +- Bug with single-digit months in `now`/`nodate` datestamp converters + ## [3.1] 2018-04-05 ### Added - `post_parse_action` parser method for more customization diff --git a/logdissect/utils.py b/logdissect/utils.py index a563709..c59145f 100644 --- a/logdissect/utils.py +++ b/logdissect/utils.py @@ -67,7 +67,7 @@ def convert_nodate_datestamp(entry, datedata): else: datedata['entry_time'] = int(entry['tstamp']) entry['year'] = str(datedata['timestamp'].year) - entry['month'] = str(datedata['timestamp'].month) + entry['month'] = str(datedata['timestamp'].month.rjust(2, '0')) entry['day'] = str(datedata['timestamp'].day).rjust(2, '0') entry['numeric_date_stamp'] = entry['year'] + entry['month'] + \ entry['day'] + entry['tstamp'] @@ -133,8 +133,8 @@ def convert_now_datestamp(entry): timestamp = datetime.now() entry['date_stamp'] = timestamp.strftime('%Y %b %d %H:%M:%S.%f') entry['year'] = str(timestamp.year) - entry['month'] = str(timestamp.month) - entry['day'] = str(timestamp.day) + entry['month'] = str(timestamp.month).rjust(2, '0') + entry['day'] = str(timestamp.day).rjust(2, '0') entry['tstamp'] = timestamp.strftime('%H%M%S.%f') entry['numeric_date_stamp'] = entry['year'] + entry['month'] + \ entry['day'] + entry['tstamp']