Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'that?': 0.05; 'subject:Python': 0.06; 'float': 0.07; 'postgresql': 0.07; 'preference': 0.07; '*is*': 0.09; 'abstraction': 0.09; 'boundaries.': 0.09; 'conversions': 0.09; 'method:': 0.09; 'things,': 0.09; 'whichever': 0.09; 'translate': 0.10; 'cc:addr :python-list': 0.11; 'python': 0.11; 'jan': 0.12; '(either': 0.16; 'ben,': 0.16; 'call?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'massively': 0.16; 'roy': 0.16; 'simple.': 0.16; 'somehow.': 0.16; 'time.time()': 0.16; 'timestamp': 0.16; 'utc': 0.16; 'utc,': 0.16; 'utc.': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'module': 0.19; 'thu,': 0.19; 'value.': 0.19; '>>>': 0.22; 'select': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'code': 0.31; 'clock': 0.31; 'everywhere': 0.31; 'figure': 0.32; 'know.': 0.32; 'maybe': 0.34; 'subject:the': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'module.': 0.36; 'object,': 0.36; 'representing': 0.36; 'done': 0.36; 'should': 0.36; 'seconds': 0.37; 'easiest': 0.38; 'stable': 0.38; 'pm,': 0.38; 'does': 0.39; 'expensive': 0.39; 'obtain': 0.39; 'either': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'future': 0.60; 'simply': 0.61; 'simple': 0.61; "you're": 0.61; 'times': 0.62; 'show': 0.63; 'personal': 0.63; 'more': 0.64; 'effectively': 0.66; 'smith': 0.68; 'effectively,': 0.84; 'resolution,': 0.84; 'to/from': 0.84; '1970': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=tBFthcopK3PM37dE4ygp0sH7FXHHMV/tU79kVgsmKbI=; b=huCJlnjDJew0nIHuHEQDWMmn9+Lnk0NnPOx4zMVRPbRb0xqEgkaFFNVKkmG0xRbRVX gvbr0mXGw2LKOTKCrlbxLD0B7JNo4k2ay4l04K9NLX1RQdNie47y9gr/Nunz/eWlMZHn 9kWp/bPGHj9SneghF3JIYtHEra3dGqbTq2LAffuB309m5GIeQI4PRXziitiXi7GPxvoD aP7cbOo1GZKTd+jZB2RVIeHCccuy5uctXs1oDQSx+neM5KU2pV6JJEMxF30lKZCXYn5N YzJn1rB6vJNSfx0yrFjpvx2pn0is6dGeKHBlPi6d61TcN0Aq+mcRwS7Bx2ZjeFlCcJzH c5+A== MIME-Version: 1.0 X-Received: by 10.68.247.6 with SMTP id ya6mr1020918pbc.45.1389240225991; Wed, 08 Jan 2014 20:03:45 -0800 (PST) In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Date: Thu, 9 Jan 2014 15:03:45 +1100 Subject: Re: the Gravity of Python 2 From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389240235 news.xs4all.nl 2845 [2001:888:2000:d::a6]:41624 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63564 On Thu, Jan 9, 2014 at 2:35 PM, Roy Smith wrote: >> Yes, it *is* simple. It *is* easy. I've been working with pure-UTC >> times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just >> float) for decades. Like with so many other things, the easiest >> solution is also the best, because you can just work with one stable >> representation and abstraction on the inside, with conversions to/from >> it at the boundaries. It IS that easy. > > Please show me the simple code to obtain an aware UTC datetime > representing the current time. In Pike: time(); In PostgreSQL: SELECT now(); In C: time(0); All of these give a value in UTC. The PostgreSQL one gives it to you as a TIMESTAMP WITH TIME ZONE, the others just as a simple value. I don't know how they go about figuring out what UTC is, on systems where the computer clock is in local time (eg Windows), but figure out they do. It might be expensive but it's done somehow. (Easiest way to check timezone in C is to look at what time(0)%86400/3600 is - that should be the hour-of-day in UTC, which as I type is 3. And it is.) I don't know how to do it in Python because I'm not familiar with the datetime module. But time.time() returns a value in UTC, which is verifiable by the above method: >>> int(time.time())%86400//3600 3 So maybe the key is to use utcfromtimestamp()? I don't know. My personal preference would be to simply use either int or float everywhere (float if you need subsecond resolution, int if you're concerned about massively past or future timestamps), and then translate to something else for display. Effectively, instead of working with a datetime object, I would just work with an alternative representation of instant-in-time which is simply seconds since 1970 (dealing with leap seconds whichever way you like). If the datetime module causes you pain, don't use it. Ben, if it's that expensive to get an aware timestamp, why does time.time() effectively do that? Is it a much more expensive call? ChrisA