Skip to content

Commit

Permalink
Update datetime format string
Browse files Browse the repository at this point in the history
WIP

sad

update format
  • Loading branch information
ekuler committed Jan 8, 2024
1 parent cc74ae4 commit 7560ee0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pykeepass/baseelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, element, kp=None, icon=None, expires=False,
self._element.append(E.IconID(icon))
current_time_str = self._kp._encode_time(datetime.now(timezone.utc))
if expiry_time:
expiry_time_str = self._kp._encode_time(expiry_time)
expiry_time_str = self._kp._encode_time(expiry_time.astimezone(timezone.utc))
else:
expiry_time_str = current_time_str

Expand Down
8 changes: 4 additions & 4 deletions pykeepass/pykeepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
BLANK_DATABASE_FILENAME = "blank_database.kdbx"
BLANK_DATABASE_LOCATION = os.path.join(os.path.dirname(os.path.realpath(__file__)), BLANK_DATABASE_FILENAME)
BLANK_DATABASE_PASSWORD = "password"
DT_ISOFORMAT = "%Y-%m-%dT%H:%M:%S%z"
DT_ISOFORMAT = "%Y-%m-%dT%H:%M:%S%fZ"

class PyKeePass():
"""Open a KeePass database
Expand Down Expand Up @@ -795,7 +795,7 @@ def _encode_time(self, value):
struct.pack('<Q', diff_seconds)
).decode('utf-8')
else:
return value.isoformat()
return value.strftime(DT_ISOFORMAT)

def _decode_time(self, text):
"""datetime.datetime: Convert base64 time or plaintext time to datetime"""
Expand All @@ -810,9 +810,9 @@ def _decode_time(self, text):
)
)
except BinasciiError:
return datetime.strptime(text, DT_ISOFORMAT).astimezone(timezone.utc)
return datetime.strptime(text, DT_ISOFORMAT).replace(tzinfo=timezone.utc)
else:
return datetime.strptime(text, DT_ISOFORMAT).astimezone(timezone.utc)
return datetime.strptime(text, DT_ISOFORMAT).replace(tzinfo=timezone.utc)

def create_database(
filename, password=None, keyfile=None, transformed_key=None
Expand Down

0 comments on commit 7560ee0

Please sign in to comment.