Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3a.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.067 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'seemed': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'mostly': 0.14; '-1,': 0.16; '-1.': 0.16; 'clear.': 0.16; 'compute': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'hack,': 0.16; 'sunset': 0.16; 'sender:addr:gmail.com': 0.17; 'else,': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'fine': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; "skip:' 10": 0.31; '(possibly': 0.31; 'closer': 0.31; 'handled': 0.32; 'stuff': 0.32; 'ago': 0.33; 'cases': 0.33; 'subject: (': 0.35; 'display': 0.35; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'are,': 0.36; 'seconds': 0.37; 'two': 0.37; 'previous': 0.38; 'little': 0.38; 'space': 0.40; 'how': 0.40; 'days': 0.60; 'even': 0.60; 'duration': 0.60; 'negative': 0.60; 'most': 0.60; 'length': 0.61; 'back': 0.62; 'skip:n 10': 0.64; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'between': 0.67; 'winter': 0.68; 'day': 0.76; '"how': 0.91; 'numbers:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=CkHBlb/SN9yiD9MhIABckFiHolaTSsMdzE7dgDc3XLE=; b=zjPO2WzFE09xy1VIkloZ/mD6d1HVP1AN2KGP6ExzWJC5nMKG1mZ9l99Sje6NrOf8Bn UJqPUNyOy8jRB1kUyfJkpUNIBnwl8B8TrOOllai5q1UXEpOLT1NfB2HXKMlgUoDByIDk 3mvgZlelHlhMtQi7D+WjMNfuTH3VovCoRyESYXUyu8orrCk7WGdFfuGgatcCUqkJP2Kk 8VGjNrLTykUq8AiOjPzxmabj/JVlWgSdbqyOQxAiywWQD8IDP/wTJ/05TMrxGOUr0jmR BZZS4jB4dR5oUdev/wEhm6goGA/MsXQTD+HyXTX45r6KvwoS3P9KANcVREvJxjCkeZrm alkA== MIME-Version: 1.0 X-Received: by 10.50.47.231 with SMTP id g7mr4271271ign.8.1395925299739; Thu, 27 Mar 2014 06:01:39 -0700 (PDT) Sender: skip.montanaro@gmail.com In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 27 Mar 2014 08:01:39 -0500 X-Google-Sender-Auth: ls8LWlPnD5kijQ73EthF-cye3yo Subject: Re: YADTR (Yet Another DateTime Rant) From: Skip Montanaro To: Chris Angelico Content-Type: text/plain; charset=UTF-8 Cc: Python 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395925308 news.xs4all.nl 2908 [2001:888:2000:d::a6]:50422 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69189 >> There are, >> as I see it, two common cases where t is negative: >> >> -1 day < t < 0 >> >> and >> >> t <= -1 day > > There are two types of negative numbers: Those closer to zero than -1, > and those not closer to zero than -1. Yeah, I think those are the most > common cases. :) Sorry I wasn't clear. I see two cases w.r.t. *display*, those where you need to display the number of days back (possibly accounting for even larger time intervals to make it more human readable), those where you don't. Yes, as you observed, they completely cover the negative timedelta space with two non-overlapping intervals. Roy's original rant was about how a negative timedelta was stringified, when what he seemed to care about was mostly the time interval between now and the previous sunset (which will be less than a day, unless your day length is advancing -- between the winter and summer solstices -- and you compute that interval a few seconds before sunset). The common "how long ago was sunset?" (|delta| < 1 day) case is handled just fine by my little negate-the-timedelta hack, e.g.: >>> "-%s" % (-datetime.timedelta(hours=-17, minutes=-12, seconds=-25.234)) '-17:12:25.234000' Negative timedeltas with a magnitude of one day or more require something else, perhaps like the ISO8601 duration stuff (which I personally find distasteful, but that might be the best you can do in the absence of an anchor datetime). Skip