<div><div dir="auto">Taky to tak nekde pouzivam. Pritom bych dal ruku do ohne, ze to bylo vycucly z nejaky dokumentace. </div><div dir="auto"><br></div><div dir="auto">Asi to nebyla dokumentace, ale stackoverflow :)</div><div dir="auto"><br></div><div dir="auto">Dik!</div><br><div class="gmail_quote"><div>On Wed, 26 Jul 2017 at 09:47, Vláďa Macek <<a href="mailto:macek@sandbox.cz">macek@sandbox.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div 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>
<br>
<p>
---------------------------------------------------------------------------
<br>
Freehosting PIPNI - <a href="http://www.pipni.cz/" target="_blank">http://www.pipni.cz/</a>
</p>
<br>
</div>
_______________________________________________<br>
Python mailing list<br>
<a href="mailto:python@py.cz" target="_blank">python@py.cz</a><br>
<a href="http://www.py.cz/mailman/listinfo/python" rel="noreferrer" target="_blank">http://www.py.cz/mailman/listinfo/python</a><br>
<br>
Visit: <a href="http://www.py.cz" rel="noreferrer" target="_blank">http://www.py.cz</a></blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature">Jakub Vysoky<br><br>mob: +420 605 852 377<br>jab: <a href="mailto:jakub.vysoky@gmail.com" target="_blank">jakub.vysoky@gmail.com</a><br>twit: <a href="https://twitter.com/kvbik" target="_blank">https://twitter.com/kvbik</a></div>