From 4eae657cb5d74b165e6cc03e3bc4cf4b69ae0a91 Mon Sep 17 00:00:00 2001 From: Abrar Ahmed <13979201+abrar71@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:54:22 +0000 Subject: [PATCH] Fixes timestamp issue fix #456 --- gyb.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gyb.py b/gyb.py index c9d8347..886201d 100755 --- a/gyb.py +++ b/gyb.py @@ -1983,11 +1983,15 @@ def convert_datetime(val): return datetime.datetime.fromisoformat(val.decode()) def convert_timestamp(val): - """Convert Unix epoch timestamp to datetime.datetime object.""" - # yuck, we aren't actually storing timestamps in the GYB - # database. I blame the original developer :-) - # return datetime.datetime.fromtimestamp(int(val)) - return datetime.datetime.strptime(val.decode('UTF-8'), '%Y-%m-%d %H:%M:%S') + val = val.decode('UTF-8') # Assuming `val` is a bytes object that needs decoding. + # Check if the datetime string contains fractional seconds. + if '.' in val: + # If yes, parse with fractional seconds. + format_str = '%Y-%m-%d %H:%M:%S.%f' + else: + # If no, parse without fractional seconds. + format_str = '%Y-%m-%d %H:%M:%S' + return datetime.datetime.strptime(val, format_str) def main(argv): global options, gmail