New submission from Arjan Keeman <arjan.kee...@gmail.com>:

Consider the following:

tz_naive_object = datetime.strptime("2018-01-05 13:10:00 CET", "%Y-%m-%d 
%H:%M:%S %Z")

Python's standard library is not capable of converting the timezone name CET to 
a tzinfo object. Therefore the case made above returns a timezone naive 
datetime object.

I propose to add an extra optional argument to _strptime.py's 
_strptime_datetime function, and to datetime.strptime: 
tzname_to_tzinfo:Optional[Callable[[str],Optional[tzinfo]]]=None. This 
parameter can be set with a function that accepts the timezone name and returns 
a tzinfo object or None (like pytz.timezone). None will mean that a timezone 
naive object will be created.

Usage:
tz_aware_object = datetime.strptime("2018-01-05 13:10:00 CET", "%Y-%m-%d 
%H:%M:%S %Z", pytz.timezone)

----------
components: Library (Lib)
messages: 309502
nosy: akeeman
priority: normal
severity: normal
status: open
title: datetime.strptime creates tz naive object from value containing a tzname
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32497>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to