Skip to content

Commit d7d0529

Browse files
committed
Fix expired entry editing. Display local time instead of UTC.
1 parent 70304a1 commit d7d0529

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

docs/usage.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
- Switch databases on the fly.
3838
- Alternate keyboard languages and layouts supported via xdotool or ydotool (for
3939
Wayland)
40-
- Display of expiring/expired passwords and shows the expiration time where set
41-
- Add, edit and type TOTP codes. RFC 6238, Steam and custom settings are supported.
40+
- Display of expiring/expired passwords (expiring within 3 days) and shows
41+
the expiration time where set.
42+
- Add, edit and type TOTP codes. RFC 6238, Steam and custom settings are
43+
supported.
4244
Supports TOTP attributes generated by [KeePass2][3], as well as [KeeOtp][4] and [TrayTOTP][5] plugins' [formats][6].
4345
- *Type entries*
4446
- Auto-type username and/or password on selection.

keepmenu/edit.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Methods for editing entries and groups
22
33
"""
4-
from datetime import datetime
4+
from datetime import datetime, timezone
55
import os
66
import random
77
from secrets import choice
@@ -17,6 +17,14 @@
1717
from keepmenu.type import type_text
1818

1919

20+
def format_expiry(expiry_time):
21+
"""Format expiry time for display (UTC to local, date-only if midnight)"""
22+
local_time = expiry_time.astimezone()
23+
if local_time.hour == 0 and local_time.minute == 0:
24+
return local_time.strftime("%Y-%m-%d")
25+
return local_time.strftime("%Y-%m-%d %H:%M")
26+
27+
2028
def add_entry(kpo):
2129
"""Add Keepass entry
2230
@@ -72,7 +80,7 @@ def edit_entry(kpo, kp_entry):
7280
str("TOTP: ******") if get_otp_url(kp_entry) else "TOTP: None",
7381
str(f"Url: {kp_entry.url}"),
7482
"Notes: <Enter to Edit>" if kp_entry.notes else "Notes: None",
75-
str(f"Expiry time: {kp_entry.expiry_time.strftime('%Y-%m-%d %H:%M')}")
83+
str(f"Expiry time: {format_expiry(kp_entry.expiry_time)}")
7684
if kp_entry.expires is True else "Expiry time: None"]
7785

7886
attrs = kp_entry.custom_properties
@@ -192,7 +200,7 @@ def edit_expiry(kp_entry):
192200
"Expiration Date (yyyy-mm-dd hh:mm OR "
193201
"yyyy-mm-dd OR HH:MM OR "
194202
"'None' to unset)",
195-
inp=kp_entry.expiry_time.strftime("%Y-%m-%d %H:%M") if
203+
inp=format_expiry(kp_entry.expiry_time) if
196204
kp_entry.expires is True else "")
197205
if not sel:
198206
return True
@@ -207,13 +215,13 @@ def edit_expiry(kp_entry):
207215

208216

209217
def exp_date(dtime):
210-
"""Convert string to datetime
218+
"""Convert string to datetime (local time input, returns UTC)
211219
212220
"""
213221
formats = ["%Y-%m-%d %H:%M", "%Y-%m-%d", "%H:%M"]
214222
for fmt in formats:
215223
try:
216-
return datetime.strptime(dtime, fmt)
224+
return datetime.strptime(dtime, fmt).astimezone(timezone.utc)
217225
except ValueError:
218226
continue
219227
dmenu_err("Invalid format. No changes made")

0 commit comments

Comments
 (0)