<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p> Dejte si bacha.</p>
<p> Pekne me dnes pokousaly timezony a to jsem si myslel, ze se
vyznam. :-)</p>
<p>Django 1.11 preslo nejak vic na vyuzivani `pytz`, ktere dodava
casove zony s vice informacemi a datetime.replace, ktere jsem do
te doby nespravne pouzival, se mi fakt nevyplatilo...</p>
<blockquote>
<p>>>> import datetime<br>
>>> import pytz<br>
<br>
>>> tz = pytz.timezone('Europe/Prague')<br>
>>> tz<br>
<DstTzInfo 'Europe/Prague' PMT+0:58:00 STD><br>
>>> # Strasidelne. :-) To mam nekde chybu, ne...</p>
>>> d_praha_naivni = datetime.datetime(2017, 6, 8, 10,
19, 52)<br>
>>> d_praha_vnuceno_blbe =
d_praha_naivni.replace(tzinfo=tz)<br>
<br>
>>> d_utc_naivni =
datetime.datetime.strptime('2017-06-08T08:19:52+00:00',
'%Y-%m-%dT%H:%M:%S+00:00')<br>
>>> d_utc_naivni<br>
datetime.datetime(2017, 6, 8, 8, 19, 52)<br>
<br>
>>> d_utc_vnuceno_blbe =
d_utc_naivni.replace(tzinfo=pytz.utc)<br>
>>> d_utc_vnuceno_blbe<br>
datetime.datetime(2017, 6, 8, 8, 19, 52, tzinfo=<UTC>)<br>
<br>
>>> d_praha_vnuceno_blbe == d_utc_vnuceno_blbe<br>
False<br>
>>> # Pritom stejny cas... lepe:<br>
<br>
>>> d_praha = tz.localize(d_praha_naivni)<br>
>>> d_praha<br>
datetime.datetime(2017, 6, 8, 10, 19, 52, tzinfo=<DstTzInfo
'Europe/Prague' CEST+2:00:00 DST>)<br>
<br>
>>> d_utc = pytz.utc.localize(d_utc_naivni)<br>
>>> d_utc<br>
datetime.datetime(2017, 6, 8, 8, 19, 52, tzinfo=<UTC>)<br>
<br>
>>> d_praha == d_utc<br>
True<br>
>>> # Konecne mi to uznal. :-)<br>
<br>
>>> d_utc == d_utc_vnuceno_blbe<br>
True<br>
>>> # Vnuceni UTC pomoci replace() zjevne vadi min...
:-><br>
<br>
</blockquote>
</body>
</html>