Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e96a501

Browse files
committed
Don't use strftime with %b which relies on locale
1 parent a0325e9 commit e96a501

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

imbox/query.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import datetime
22

3+
from imbox.utils import date_to_date_text
4+
35

46
def build_search_query(imap_attribute_lookup, **kwargs):
57
query = []
68
for name, value in kwargs.items():
79
if value is not None:
810
if isinstance(value, datetime.date):
9-
value = value.strftime('%d-%b-%Y')
11+
value = date_to_date_text(value)
1012
if isinstance(value, str) and '"' in value:
1113
value = value.replace('"', "'")
1214
query.append(imap_attribute_lookup[name].format(value))

imbox/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import datetime
12
import logging
3+
from imaplib import Time2Internaldate
24
logger = logging.getLogger(__name__)
35

46

@@ -14,3 +16,10 @@ def str_decode(value='', encoding=None, errors='strict'):
1416
return value.decode(encoding or 'utf-8', errors=errors)
1517
else:
1618
raise TypeError("Cannot decode '{}' object".format(value.__class__))
19+
20+
21+
def date_to_date_text(date):
22+
"""Return a date in the RFC 3501 date-text syntax"""
23+
tzutc = datetime.timezone.utc
24+
dt = datetime.datetime.combine(date, datetime.time.min, tzutc)
25+
return Time2Internaldate(dt)[1:12]

0 commit comments

Comments
 (0)