Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The disks are getting full; purge a file today.


devel / comp.lang.python / Re: Pre-Pre-PEP: The datetime.timedeltacal class

SubjectAuthor
o Re: Pre-Pre-PEP: The datetime.timedeltacal classBarry

1
Re: Pre-Pre-PEP: The datetime.timedeltacal class

<mailman.134.1650137154.20749.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22297&group=comp.lang.python#22297

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: barry@barrys-emacs.org (Barry)
Newsgroups: comp.lang.python
Subject: Re: Pre-Pre-PEP: The datetime.timedeltacal class
Date: Sat, 16 Apr 2022 20:25:45 +0100
Lines: 87
Message-ID: <mailman.134.1650137154.20749.python-list@python.org>
References: <20220416173551.fk6voaa3o25iuewm@hjp.at>
<F427EFF2-F276-4DA3-9048-B979C978813D@barrys-emacs.org>
Mime-Version: 1.0 (1.0)
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de e/g05A45whBHP/7dPPrHLgZ48VY8DASlTnkVQiY+hoAg==
Return-Path: <barry@barrys-emacs.org>
X-Original-To: Python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(e.g.': 0.05; 'happened':
0.07; 'tests': 0.07; 'cc:addr:python-list': 0.09; 'compute': 0.09;
'datetime': 0.09; 'filename:fname piece:asc': 0.09;
'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'float': 0.09;
'from:addr:barry': 0.09; "hasn't": 0.09; 'proposing': 0.09;
'received:217.70': 0.09; 'received:gandi.net': 0.09;
'received:mail.gandi.net': 0.09; "shouldn't": 0.09; 'smaller':
0.09; 'subject:class': 0.09; 'typically': 0.09; 'cc:no real
name:2**0': 0.14; 'url:mailman': 0.15; '"computer': 0.16;
'"creative': 0.16; '(unless': 0.16; '2022,': 0.16; '__/': 0.16;
'arithmetic': 0.16; 'backward': 0.16; 'barry': 0.16;
'challenge!"': 0.16; 'constructor': 0.16; 'daylight': 0.16;
'from:addr:barrys-emacs.org': 0.16; 'hjp@hjp.at': 0.16; 'holzer':
0.16; 'hours,': 0.16; 'impossible': 0.16; 'instead.': 0.16;
'message-id:@barrys-emacs.org': 0.16; 'objects.': 0.16;
'reality.': 0.16; 'rough': 0.16; 'semantics': 0.16; 'separately,':
0.16; 'stick': 0.16; 'stross,': 0.16; 'subject:Pre': 0.16;
'subject:skip:d 20': 0.16; 'supported.': 0.16; 'time",': 0.16;
'unlikely': 0.16; 'url-ip:212.17.106.137/32': 0.16; 'url-
ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16; 'url:hjp':
0.16; '|_|_)': 0.16; 'wrote:': 0.16; 'problem': 0.16; 'code.':
0.17; 'probably': 0.17; "can't": 0.17; 'subscribed': 0.19;
"aren't": 0.19; 'cc:addr:python.org': 0.20; 'feedback': 0.23;
'weeks': 0.23; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0': 0.25;
'url-ip:188.166/16': 0.25; 'seems': 0.26; 'intend': 0.26;
'library': 0.26; 'months,': 0.26; 'object': 0.26; 'bit': 0.27;
'function': 0.27; 'done': 0.28; 'mostly': 0.28; 'sense': 0.28;
'suggest': 0.28; 'takes': 0.31; 'url-ip:188/8': 0.31; 'think':
0.32; "doesn't": 0.32; 'gathering': 0.32; 'minutes,': 0.32;
'same,': 0.32; 'specified': 0.32; 'split': 0.32; 'weeks,': 0.32;
"wouldn't": 0.32; 'but': 0.32; "i'm": 0.33; "i'll": 0.33; 'there':
0.33; 'header:In-Reply-To:1': 0.34; 'months': 0.35; 'cases': 0.36;
'currently': 0.37; "it's": 0.37; 'class': 0.37; 'hard': 0.37;
'could': 0.38; 'two': 0.39; 'added': 0.39; 'adding': 0.39;
'least': 0.39; 'handle': 0.39; 'subject:PEP': 0.39; 'use': 0.39;
'break': 0.39; 'seconds': 0.40; 'something': 0.40; 'want': 0.40;
'should': 0.40; 'likely': 0.61; 'method': 0.61; 'finally': 0.62;
'here': 0.62; 'days': 0.62; 'hours': 0.63; 'between': 0.63;
'research': 0.64; 'years': 0.65; 'day': 0.66; 'received:217':
0.67; 'right': 0.68; 'content-type:multipart/mixed': 0.68;
'days,': 0.69; 'stores': 0.69; 'url-ip:212/8': 0.69; 'varying':
0.69; 'rules': 0.70; 'subject:The': 0.70; 'deal': 0.73; 'plus':
0.73; 'zone': 0.76; '"fix"': 0.84; 'direction.': 0.84; 'leap':
0.84; 'represented': 0.84; 'savings': 0.84; 'opposite': 0.91;
'somebody': 0.91; 'content-type:application/octet-stream': 0.94
In-Reply-To: <20220416173551.fk6voaa3o25iuewm@hjp.at>
X-Mailer: iPad Mail (19E258)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <F427EFF2-F276-4DA3-9048-B979C978813D@barrys-emacs.org>
X-Mailman-Original-References: <20220416173551.fk6voaa3o25iuewm@hjp.at>
 by: Barry - Sat, 16 Apr 2022 19:25 UTC

> On 16 Apr 2022, at 18:38, Peter J. Holzer <hjp-python@hjp.at> wrote:
>
> I intend to take this to python-ideas, but I'm not currently subscribed
> there and I think I should probably do a bit of research before
> proposing something over there. So I'll start by gathering some feedback
> here with a rough sketch.
>
> Datetime arithmetic in the real world is typically not done in seconds,
> but in calendaric units: Hours, days, weeks, months, years, ...
> The problem is that several of these have varying lengths:
>
> * 1 minute may be 60 or 61 seconds (theoretically also 59, but that
> hasn't happened yet).
> * 1 day can be 23, 24 or 25 hours (unless you are in Troll, Antarctica,
> where it's even weirder).
> * 1 month may be 28, 29, 30 or 31 days (let's stick to the Gregorian
> calendar)
>
> The standard library has a datetime.timedelta class which does store
> days and seconds separately, so somebody seems to have had the right
> idea, but the normalization rules make it impossible to distinguish
> between "1 day plus 1 hour" and "25 hours", and it doesn't deal with
> months at all.
>
> Technically it shouldn't be too hard to "fix" timedelta, but that
> wouldn't be backward compatible and would very likely break existing
> code.
>
> Therefore a new class (provisionally called timedeltacal, because it is
> calendaric, not absolute) should be added to datetime:
>
> Internally it stores months, days, seconds and microseconds as ints.
>
> The seconds and microseconds split is mostly for compatibility with
> datetime and timedelta. We could store seconds as a float instead.
>
> We don't store minutes since leap seconds aren't usually represented in
> "computer time", so they are unlikely to be useful in a timedeltacal
> object.
>
> Days are stored since they aren't a fixed multiple of any smaller unit.
> Months are stored since they aren't a fixed multiple of any smaller unit.
>
> Hours, weeks and years aren't stored since they are always 60 minutes, 7
> days and 12 months respectively.
>
> When adding a timedeltacal object to a datetime, the fields are added
> from most to least significant: First a new date is computed by
> advancing the number of months specified [TODO: Research how other
> systems handle overflow (e.g. 2022-01-31 + 1 month: 2022-02-31 doesn't
> exist)], then advance the number of days. Finally add the number of
> seconds and microseconds, taking into accout daylight savings time
> switches if the datetime is time zone aware.
>
> Subtracting a timedeltacal object from a datetime is the same, just in
> the opposite direction.
>
> Note that t + d - d is in general not equal to t.
>
> We can't cnange the semantics of datetime - datetime, so there must be a
> function to compute the difference between to datetimes as a
> timedeltacal. It could be a method on datetime (maybe t.sub(u) for t-u
> like in Go) or a constructor which takes two datetime objects.
>
> In any case I think that u + (t - u) == t should hold. [TODO: Check that
> this is possible]

Suggest that you start with the use cases that you want supported.
Then you can turn them into a set of tests to check that the solution works.

Barry

>
> hp
>
> --
> _ | Peter J. Holzer | Story must make more sense than reality.
> |_|_) | |
> | | | hjp@hjp.at | -- Charles Stross, "Creative writing
> __/ | http://www.hjp.at/ | challenge!"
> --
> https://mail.python.org/mailman/listinfo/python-list


devel / comp.lang.python / Re: Pre-Pre-PEP: The datetime.timedeltacal class

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor