Path: csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:: [': 0.03; 'conversions': 0.07; 'dst': 0.07; 'reason,': 0.07; 'api': 0.09; 'cc:addr:python-list': 0.09; 'behave': 0.09; 'lengths': 0.09; 'bug': 0.10; 'python': 0.10; 'systems.': 0.11; 'applies': 0.15; '"proper': 0.16; 'clock.': 0.16; 'defer': 0.16; 'fold': 0.16; 'time"': 0.16; 'utc': 0.16; 'utc.': 0.16; 'module,': 0.18; ';-)': 0.18; 'subject:] ': 0.19; 'cc:addr:python.org': 0.20; 'posted': 0.21; 'work,': 0.21; '(the': 0.22; 'cc:2**1': 0.22; 'saying': 0.22; '(by': 0.22; 'clock': 0.22; 'subject:skip:i 10': 0.22; 'trying': 0.22; 'appears': 0.23; 'demonstrate': 0.23; 'unix': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'possibility': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'converting': 0.27; 'transition': 0.27; 'correct': 0.28; 'went': 0.28; 'about.': 0.29; 'arithmetic': 0.29; 'guarantees': 0.29; 'pep': 0.29; 'reflected': 0.29; 'another': 0.32; 'knows': 0.32; 'skip:. 10': 0.32; 'limitations': 0.33; 'values.': 0.33; 'changing': 0.34; 'correctly': 0.34; 'received:google.com': 0.35; 'ahead': 0.35; 'returning': 0.35; 'asking': 0.35; 'according': 0.36; 'but': 0.36; 'there': 0.36; 'subject:" ': 0.36; 'subject:?': 0.36; 'being': 0.37; 'seem': 0.37; 'presence': 0.38; 'why': 0.39; 'subject:-': 0.39; 'behavior': 0.61; 'skip:u 10': 0.61; 'default': 0.61; 'design,': 0.61; 'back': 0.62; 'different': 0.63; 'sample': 0.63; 'times': 0.63; 'strictly': 0.64; 'due': 0.65; 'between': 0.65; 'importantly,': 0.66; 'subject:there': 0.66; 'saving': 0.70; 'behaviors': 0.72; 'viewed': 0.79; '495': 0.84; 'ends)': 0.84; 'faithfully': 0.84; 'gap': 0.84; 'non-zero': 0.84; 'subject:any': 0.84; 'notion': 0.91; 'overdue': 0.91; 'subject:Are': 0.95; 'treatment': 0.95; 'hand,': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=MbvdCoPHPAvmXQEVDmdpbO+bKQRfy0Kh2WrbQ2z7PqY=; b=tzPg3ST8stmu/C9B4X0nwcJuz4jFno3bTe8tWcpw9atIeDc8gvIZxwTJLq50BLMY// Y1ZiIhl3kmQk476mrBbrzb/8sqaxoB0/g7nP5rXZByEBzc8icXq+sUdfBfeh9HkfNcN2 iFXwDIm+9EFcPktk40UOIRjzJ81CiYcN5ZWDAj3Ay85jaOf352aVuj2fECs34M9ioueL 4Vys5labIxhP6i0uRh7wLPy3avkb7XyAzZqA5POL/q8cHHcOrpSMyFhcZZoBsWcxFL7t KXsziVHZKPEHLbdklOCm6sfX8a+eqd6CNBZfSMgE1u9Q32afq6MOcOGzeb5QVwVvwsQD bj2A== X-Received: by 10.60.15.2 with SMTP id t2mr4251772oec.71.1442084001328; Sat, 12 Sep 2015 11:53:21 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Tim Peters Date: Sat, 12 Sep 2015 13:53:06 -0500 Subject: Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo? To: Random832 Cc: datetime-sig , Python-List Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442084009 news.xs4all.nl 23842 [2001:888:2000:d::a6]:43259 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96448 > I was trying to find out how arithmetic on aware datetimes is "supposed > to" work, and tested with pytz. When I posted asking why it behaves this > way I was told that pytz doesn't behave correctly according to the way > the API was designed. You were told (by me) that its implementation of tzinfos was not the _intended_ way. Which is another way of saying it was an unanticipated way. "Correctly" is a whole different kind of judgment. pytz users who faithfully follow the docs seem happy with it. > The tzlocal module, on the other hand, appears to > simply defer to pytz on Unix systems. > > My question is, _are_ there any correct reference implementations that > demonstrate the proper behavior in the presence of a timezone that has > daylight saving time transitions? Which specific "proper behaviors"? :"Hybrid" tzinfos following the recommendations in the Python docs, including the sample implementations in the docs, correctly mimic local clock behavior (skipping the clock ahead when DST starts, and moving the clock back when DST ends) when converting from UTC. It's impossible now to do local -> UTC conversions correctly in all cases, because it's impossible now to know which UTC time was intended for a local time in a fold. For the same reason, it's impossible now to know whether a local time in a fold is intended to be viewed as being in daylight time or standard time. But do note limitations of the default .fromutc() implementation: it only guarantees correct mimic-the-local-clock behavior when total-offset transitions are solely due to a notion of "daylight time" that strictly alternates between .dst() returning zero and non-zero values. Transitions due to any other reason may or may not be reflected in .fromutc()'s treatment of the local clock. Most importantly, a transition due to a zone changing its base ("standard") UTC offset is a possibility the default .fromutc() knows nothing about. The wrapping of the IANA ("Olson") zoneinfo database in dateutil uses hybrid tzinfos (the intended way of wrapping zones with multiple UTC offsets), and inherits the default .fromutc(), so all the above applies to it. Including all behaviors stemming from the impossibility of disambiguating local times in a fold. That's not a bug in dateutil. It's a gap in datetime's design, It was an intentional gap at the time, but that pytz went to such heroic lengths to fill it suggests PEP 495 may well be overdue ;-)