[issue8822] datetime naive and aware types should have a well-defined definition that can be cross-referenced
New submission from anatoly techtonik
Changes by Antoine Pitrou
Alexander Belopolsky
'naive' and 'aware' are key datetime types - they need a proper definition and anchor for crossrefences.
The definition is given in the introductory section: """ There are two kinds of date and time objects: “naive” and “aware”. This distinction refers to whether the object has any notion of time zone, daylight saving time, or other kind of algorithmic or political time adjustment. """ I am not sure what you propose to add to this. Do you wan't to dedicate a separate subsection to naive and aware time and datetime? I feel that would be an overkill. Would simply adding index entries for naive and aware time/datetime objects be enough?
It is not said how to make non-naive object,
This may be due to the fact that there is no concrete tzinfo implementation in stdlib. See issue 5094. I think it can be added in datetime constructor section that providing a tzinfo argument results in an aware object. this is already so for datetime.fromtimestamp.
how to detect if object of naive or aware.
This is already clear IMO:
"""
An object d of type time or datetime may be naive or aware. d is aware if d.tzinfo is not None and d.tzinfo.utcoffset(d) does not return None. If d.tzinfo is None, or if d.tzinfo is not None but d.tzinfo.utcoffset(d) returns None, d is naive.
"""
----------
_______________________________________
Python tracker
Jakob Malm
'naive' and 'aware' are key datetime types
Perhaps the sentence could be changed to something like:
"date and time objects are either 'naive' or 'aware'.
----------
nosy: +shaq
_______________________________________
Python tracker
Jakob Malm
Alexander Belopolsky
I created a patch with the revised wording.
Your patch seems to reflow the entire paragraph which makes it hard to
review and if applied will appear as a bigger change than it is. Can
you regenerate the patch so that it does not have whitespace only
diffs? Thanks.
----------
nosy: +Alexander.Belopolsky
_______________________________________
Python tracker
anatoly techtonik
Alexander Belopolsky
5. Mention the fact: By default all objects are "naive", by definition, because they don't have any TZ information, and there are no classes in stdlib that provide this info (tzclass implemetations)
This is simply wrong: in py3k we have the timezone class that implements tzinfo interface.
6. Answer the questions: How to make non-naive object? How to detect if object of naive or aware?
I would go one step further: we should review the examples in datetime
module documentation and use aware datetime objects unless the point
of the example is to demonstrate a naive datetime. We should also
replace examples that use sample implementations of tzinfo to use the
timezone class.
----------
_______________________________________
Python tracker
Jakob Malm
Alexander Belopolsky
anatoly techtonik
Shouldn't we say "datetime and time" instead of "date and time"? There is no tzinfo attribute in date objects.
Does that mean that if aware `datetime` is converted to `date` and
then back, the tzinfo information is lost and object implicitly
becomes naive? In this case it should mentioned IMO.
--
anatoly t.
----------
_______________________________________
Python tracker
Alexander Belopolsky
Does that mean that if aware `datetime` is converted to `date` and then back, the tzinfo information is lost and object implicitly becomes naive?
Yes, but one cannot convert "back" from date to datetime. To get a datetime object, one needs to combine date and time and tzinfo is attached to the time component.
In this case it should mentioned IMO.
I agree. The following is not really intuitive:
-> None
In order to preserve tzinfo, one has to preserve it when extracting
the time component:
-> datetime.timezone.utc
----------
_______________________________________
Python tracker
Jakob Malm
Shouldn't we say "datetime and time" instead of "date and time"? There is no tzinfo attribute in date objects.
Perhaps like this?
:class:`datetime` and :class:`time` objects are...
----------
_______________________________________
Python tracker
Mark Lawrence added the comment:
I like the wording in the patch as it's clearer than the original and so think it should be applied.
----------
nosy: +BreamoreBoy
_______________________________________
Python tracker
Change by Mark Lawrence
Change by Senthil Kumaran
participants (6)
-
Alexander Belopolsky
-
anatoly techtonik
-
Antoine Pitrou
-
Jakob Malm
-
Mark Lawrence
-
Senthil Kumaran