Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Where are the calculations that go with a calculated risk?


devel / comp.lang.python / Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

SubjectAuthor
* Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
+* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
|+* Re: Why does datetime.timedelta only have the attributes 'days' andPaul Bryan
||`* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
|| +* Re: Why does datetime.timedelta only have the attributes 'days' andMRAB
|| |`- Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
|| +- Re: Why does datetime.timedelta only have the attributes 'days' andMarco Sulla
|| +- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
|| `* Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||  `* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   +* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   |+* Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||   ||`* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   || +* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Dennis Lee Bieber
||   || |`- Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   || +- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
||   || `* Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||   ||  `* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
||   ||   `* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   ||    `* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
||   ||     `* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   ||      +* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
||   ||      |+* Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   ||      ||`- Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
||   ||      |`* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Dennis Lee Bieber
||   ||      | +* Re: Why does datetime.timedelta only have the attributes 'days' andBarry
||   ||      | |`- Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   ||      | `* Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
||   ||      |  `- Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Mark Lawrence
||   ||      `- Re: Why does datetime.timedelta only have the attributes 'days' andMRAB
||   |+- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
||   |+- Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||   |+- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
||   |+- Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||   |+- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
||   |+- Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||   |`- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
||   +* Re: Why does datetime.timedelta only have the attributes 'days' andPeter J. Holzer
||   |`- Re: Why does datetime.timedelta only have the attributes 'days' andJon Ribbens
||   +- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico
||   `* Re: Why does datetime.timedelta only have the attributes 'days' andRandom832
||    `- Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?Loris Bennett
|`- Re: Why does datetime.timedelta only have the attributes 'days' andLars Liedtke
`- Re: Why does datetime.timedelta only have the attributes 'days' andChris Angelico

Pages:12
Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?
Date: Thu, 14 Apr 2022 15:35:13 +0200
Organization: Freie Universitaet Berlin
Lines: 25
Message-ID: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de HaxP8xddj9RFBoH5k/s8EQjnw4eamj0wwYQjhyGobhXQOO
Cancel-Lock: sha1:Y/RFC2Y7g7e2SLvZhEKxcO1oNe0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Loris Bennett - Thu, 14 Apr 2022 13:35 UTC

Hi,

With Python 3.9.2 I get

$ import datetime
$ s = "1-00:01:01"
$ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
$ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute, seconds=t.second)
$ d.days
1
$ d.seconds
61
$ d.minutes
AttributeError: 'datetime.timedelta' object has no attribute 'minutes'

Is there a particular reason why there are no attributes 'minutes' and
'hours and the attribute 'seconds' encompasses is the entire fractional
day?

Cheers,

Loris

--
This signature is currently under construction.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?
Date: Thu, 14 Apr 2022 15:38:14 +0200
Organization: ZEDAT, Freie Universität Berlin
Lines: 33
Message-ID: <87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de uU3gzuhG7XzuF8XBAviFRAtNY37RP3XKD3FStwbsBiXmJH
Cancel-Lock: sha1:juezBR6/hQHsH8gBRnsF/x6FvMI=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Loris Bennett - Thu, 14 Apr 2022 13:38 UTC

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> Hi,
>
> With Python 3.9.2 I get
>
> $ import datetime
> $ s = "1-00:01:01"
> $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
> $ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute, seconds=t.second)
> $ d.days
> 1
> $ d.seconds
> 61
> $ d.minutes
> AttributeError: 'datetime.timedelta' object has no attribute 'minutes'
>
> Is there a particular reason why there are no attributes 'minutes' and
> 'hours and the attribute 'seconds' encompasses is the entire fractional
> day?

That should read:

Is there a particular reason why there are no attributes 'minutes' and
'hours' and the attribute 'seconds' encompasses the entire fractional
day?

> Cheers,
>
> Loris
--
Dr. Loris Bennett (Herr/Mr)
ZEDAT, Freie Universität Berlin Email loris.bennett@fu-berlin.de

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: pbr...@anode.ca (Paul Bryan)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Thu, 14 Apr 2022 08:01:40 -0700
Lines: 48
Message-ID: <mailman.87.1649948491.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de dAKmKPoB1cZiaoECZaolpQGV3bzif4c1FiAVJxTsX03Q==
Return-Path: <pbryan@anode.ca>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=anode.ca header.i=@anode.ca header.b=Zr9S3A+h;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.018
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:Why': 0.07;
'datetime': 0.09; 'writes:': 0.09; 'cheers,': 0.11; 'import':
0.15; '+0200,': 0.16; '8bit%:73': 0.16; 'attributes': 0.16;
'bennett': 0.16; 'read:': 0.16; 'received:10.202': 0.16;
'received:10.202.2': 0.16; 'received:64.147': 0.16;
'received:64.147.123': 0.16; 'received:internal': 0.16;
'received:messagingengine.com': 0.16; 'seconds.': 0.16;
'subject:does': 0.16; 'subject:seconds': 0.16; 'times,': 0.16;
'wrote:': 0.16; 'python': 0.16; 'thu,': 0.19; 'to:addr:python-
list': 0.20; 'cannot': 0.25; 'object': 0.26; 'header:User-
Agent:1': 0.30; 'think': 0.32; 'there': 0.33; 'particular': 0.33;
'header:In-Reply-To:1': 0.34; 'berlin': 0.35; 'subject:skip:d 10':
0.35; 'seconds': 0.40; 'should': 0.40; 'skip:h 10': 0.61; 'days':
0.62; 'hours': 0.63; 'email': 0.63; 'skip:b 20': 0.63; 'entire':
0.67; 'received:64': 0.67; 'subject:have': 0.75; 'dr.': 0.77;
'attribute': 0.84; 'composed': 0.84; 'leap': 0.84; 'subject:days':
0.84; 'subject:only': 0.84; 'skip:d 30': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anode.ca; h=cc
:content-type:date:date:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:sender:subject
:subject:to:to; s=fm1; t=1649948487; x=1650034887; bh=7wLbWV1Nsb
bb6D8X5nQLLfZ6ldOo5lORwZSNYq2hYwI=; b=Zr9S3A+h4xp9I2rqlKWSxS3JV+
mUU80N6g7yVXQ+mQEUfywtWHJCk76wR8tmnX1VVXaI7r1vlh8Dk+cAtHgXefBHyN
1OkL/n0sw2KpKFMOAOQBFi5O/caYKWvNpMOAMBEM4HHL5O9i2+J/YizGoO5b8x27
M8BEd4sIvWalgJx3A9zS8veYj7BCuGeE5HaKXus17a4EdGQgaH2wipNYMaeQSBw6
dOBnNidvy5u+HvFDQIwRNBPU+aZZ17gc2auhSzZYjt86j3D0sOsOnF29aQ4LfCpL
hJVYOKnhIkDZc+vTJkqA549ENo1exWM8p4rBB1DmCiPLQYGksjYlJ4Vu0Tuw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-type:date:date:from:from
:in-reply-to:in-reply-to:message-id:mime-version:references
:reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy
:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1649948487; x=
1650034887; bh=7wLbWV1Nsbbb6D8X5nQLLfZ6ldOo5lORwZSNYq2hYwI=; b=r
dCOpvmJnsL4JTzJtxkWA9hlEnVy6C7dFl4bhwpxJlm8tLiuURfhjK4r+yBiudi3d
gzihE0Vhzx+oFDYH2QUiuwLbY1OGMumWbOQnAtrgRgCsfc5mohQgfqqPYzWzfw9/
r0nLGAcD5IXbihCQefYXPeI3stAVqxg3Vlfr21GXsmucJcQ0nFsP1Qfd5muSDvN3
fK/GWf+3kIHcjVU4w+KoPH95Nm1o9TcAZrPq7JCqa6iVoQ5AWTwSTSBOzcDvUE0C
W/VN5QlNSBxq5syLpin7zVkL9cn05lXPP/r9LK2efiKZD9K0B9GXdu59bgrGTcBy
MNi4LYQVw+wdLibdZekug==
X-ME-Sender: <xms:RzdYYgrW4_0Y-v8YKgZhBMn51NqKo8NSugth2YnlWFCQsyBLXEuJng>
<xme:RzdYYmo6fRHP9ef3F25waWh6A8MlaTAUnEpzCNYROrLqYsOGcoden7FlXWe1lIXXW
OVf0Hgu7LM9Xj7M3Eo>
X-ME-Received: <xmr:RzdYYlNz5bGebHfziS6KuSo9rdphEPuRIxpt9Q25zRyC3so27UOgPyXmUNlAZzVoe8pKr345x8w5LrQjdB8F2USbkuHEOfMmp6UxQQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudelfedgkeefucetufdoteggodetrfdotf
fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne
cujfgurhepkffuhffvffgjfhgtfgggsegrtderredtreejnecuhfhrohhmpefrrghulhcu
uehrhigrnhcuoehpsghrhigrnhesrghnohguvgdrtggrqeenucggtffrrghtthgvrhhnpe
dvtdetieekhfetlefgvdffieegteekkeevfeegiefgteeijeeulefhfeehkeeigeenucev
lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsghrhigrnh
esrghnohguvgdrtggr
X-ME-Proxy: <xmx:RzdYYn4YtnME1fNl-b49HGMXnbzzpQzKIxsYIverANYESlV1-rbUSg>
<xmx:RzdYYv5l9fJlcItqBkf9M7WAyZPm1R5E_opb909fO1hf5MWtQsmnwQ>
<xmx:RzdYYng9Lbd9wMa5Y-ci8nEIU-NAJjsdISYpTmrnVdiOrFxjaZ1WrA>
<xmx:RzdYYsiHgNE-lrHvYGwIMw-3DI-XLAQ6C7GjcvA7D1OfHOPgA_962g>
In-Reply-To: <87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
User-Agent: Evolution 3.44.0
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: <0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
 by: Paul Bryan - Thu, 14 Apr 2022 15:01 UTC

I think because minutes and hours can easily be composed by multiplying
seconds. days is separate because you cannot compose days from seconds;
leap seconds are applied to days at various times, due to
irregularities in the Earth's rotation.

On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote:
> "Loris Bennett" <loris.bennett@fu-berlin.de> writes:
>
> > Hi,
> >
> > With Python 3.9.2 I get
> >
> >   $ import datetime
> >   $ s = "1-00:01:01"
> >   $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
> >   $ d = datetime.timedelta(days=t.day, hours=t.hour,
> > minutes=t.minute, seconds=t.second)
> >   $ d.days
> >   1
> >   $ d.seconds
> >   61
> >   $ d.minutes
> >   AttributeError: 'datetime.timedelta' object has no attribute
> > 'minutes'
> >
> > Is there a particular reason why there are no attributes 'minutes'
> > and
> > 'hours and the attribute 'seconds' encompasses is the entire
> > fractional
> > day?
>
> That should read:
>
>   Is there a particular reason why there are no attributes 'minutes'
> and
>   'hours' and the attribute 'seconds' encompasses the entire
> fractional
>   day?
>
> > Cheers,
> >
> > Loris
> --
> Dr. Loris Bennett (Herr/Mr)
> ZEDAT, Freie Universität Berlin         Email
> loris.bennett@fu-berlin.de

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Thu, 14 Apr 2022 15:22:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
Injection-Date: Thu, 14 Apr 2022 15:22:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2fdfa296348d7bacaa7716edad0e418d";
logging-data="17819"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/v73hlATQr4NYOYumcspEhloLFaCXQ2Ek="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:xJiohdzmf9xkz3frqtP9nnASJ8Q=
 by: Jon Ribbens - Thu, 14 Apr 2022 15:22 UTC

On 2022-04-14, Paul Bryan <pbryan@anode.ca> wrote:
> I think because minutes and hours can easily be composed by multiplying
> seconds. days is separate because you cannot compose days from seconds;
> leap seconds are applied to days at various times, due to
> irregularities in the Earth's rotation.

That's an argument that timedelta should *not* have a 'days' attribute,
because a day is not a fixed number of seconds long (to know how long
a day is, you have to know which day you're talking about, and where).
It's an undocumented feature of timedelta that by 'day' it means '86400
seconds'.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lal...@solute.de (Lars Liedtke)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Thu, 14 Apr 2022 17:17:16 +0200
Lines: 93
Message-ID: <mailman.88.1649949909.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<2f4526de-7c71-8c0b-707b-3881e637d82e@solute.de>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de F7VSz46q1KDB8BYUJbVIsg+IsWNdLas9WynafGAH4drA==
Return-Path: <lal@solute.de>
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.098
X-Spam-Evidence: '*H*': 0.81; '*S*': 0.01; 'argument': 0.04;
'subject:Why': 0.07; 'datetime': 0.09; 'float': 0.09; 'int': 0.09;
'schrieb': 0.09; 'url:de': 0.09; 'writes:': 0.09; 'cheers,': 0.11;
'import': 0.15; '+0200,': 0.16; '721': 0.16; '8bit%:73': 0.16;
'attributes': 0.16; 'bennett': 0.16; 'brands': 0.16; 'gmbh': 0.16;
'read:': 0.16; 'seconds.': 0.16; 'sitz': 0.16; 'subject:does':
0.16; 'subject:seconds': 0.16; 'times,': 0.16; 'wrote:': 0.16;
'python': 0.16; 'thu,': 0.19; 'to:addr:python-list': 0.20;
'received:de': 0.23; 'cannot': 0.25; 'register': 0.25; 'object':
0.26; '>>>': 0.28; 'expect': 0.28; 'header:User-Agent:1': 0.30;
'think': 0.32; 'there': 0.33; 'particular': 0.33; 'header:In-
Reply-To:1': 0.34; 'subject:skip:d 10': 0.35; 'could': 0.38;
'valid': 0.39; 'base': 0.40; 'exact': 0.40; 'received:213': 0.40;
'seconds': 0.40; 'both': 0.40; 'want': 0.40; 'should': 0.40;
'skip:h 10': 0.61; 'policy': 0.62; 'germany': 0.62; 'skip:z 10':
0.62; 'days': 0.62; 'hours': 0.63; 'email': 0.63; 'skip:b 20':
0.63; 'privacy': 0.64; 'entire': 0.67; 'phone:': 0.68;
'amtsgericht': 0.69; 'der': 0.69; 'depending': 0.70; 'them,':
0.70; 'fax:': 0.75; 'subject:have': 0.75; 'url:php': 0.75;
'cheers': 0.76; 'dr.': 0.77; 'paul': 0.81; 'returned': 0.81;
'attribute': 0.84; 'composed': 0.84; 'court:': 0.84; 'in?': 0.84;
'leap': 0.84; 'subject:days': 0.84; 'subject:only': 0.84;
'units.': 0.84; 'url-ip:62/8': 0.84; 'skip:d 30': 0.86; 'e-mail:':
0.88
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Content-Language: en-US
In-Reply-To: <0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
X-ClientProxiedBy: solute-exc2019.solute.ka (10.11.5.25) To
solute-exc2019.solute.ka (10.11.5.25)
X-EsetResult: clean, is OK
X-EsetId: 37303A291E3FD15264706A
X-C2ProcessedOrg: 6b8a70a0-c2cb-4e72-a27d-0fc2d5a54e94
X-CrossPremisesHeadersFilteredBySendConnector: solute-exc2019.solute.ka
X-OrganizationHeadersPreserved: solute-exc2019.solute.ka
X-Mailman-Approved-At: Thu, 14 Apr 2022 11:25:08 -0400
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: <2f4526de-7c71-8c0b-707b-3881e637d82e@solute.de>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
 by: Lars Liedtke - Thu, 14 Apr 2022 15:17 UTC

Additionally, which datatype would you expect them to be returned in?

One could argument for int or float (Decimal?),  both could be valid
datatypes, depending on how exact you might want them, while the second
is the time base of SI units.

Cheers
Lars

--
Lars Liedtke
Software Entwickler


Phone:
Fax: +49 721 98993-
E-mail: lal@solute.de

solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany

Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798

Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 14.04.22 um 17:01 schrieb Paul Bryan:
> I think because minutes and hours can easily be composed by multiplying
> seconds. days is separate because you cannot compose days from seconds;
> leap seconds are applied to days at various times, due to
> irregularities in the Earth's rotation.
>
> On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote:
>> "Loris Bennett" <loris.bennett@fu-berlin.de> writes:
>>
>>> Hi,
>>>
>>> With Python 3.9.2 I get
>>>
>>>   $ import datetime
>>>   $ s = "1-00:01:01"
>>>   $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
>>>   $ d = datetime.timedelta(days=t.day, hours=t.hour,
>>> minutes=t.minute, seconds=t.second)
>>>   $ d.days
>>>   1
>>>   $ d.seconds
>>>   61
>>>   $ d.minutes
>>>   AttributeError: 'datetime.timedelta' object has no attribute
>>> 'minutes'
>>>
>>> Is there a particular reason why there are no attributes 'minutes'
>>> and
>>> 'hours and the attribute 'seconds' encompasses is the entire
>>> fractional
>>> day?
>> That should read:
>>
>>   Is there a particular reason why there are no attributes 'minutes'
>> and
>>   'hours' and the attribute 'seconds' encompasses the entire
>> fractional
>>   day?
>>
>>> Cheers,
>>>
>>> Loris
>> --
>> Dr. Loris Bennett (Herr/Mr)
>> ZEDAT, Freie Universität Berlin         Email
>> loris.bennett@fu-berlin.de

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Thu, 14 Apr 2022 18:11:44 +0100
Lines: 16
Message-ID: <mailman.91.1649956494.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de Ax/+G7u3FJR/IjFW8aqS+wZQQ+1ZkOMCC1EToG9qk+gQ==
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=Xvbbsuwu;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.024
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'argument': 0.04; '(to':
0.07; 'subject:Why': 0.07; '*not*': 0.09; 'from:addr:python':
0.09; 'received:192.168.1.64': 0.09;
'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16;
'hours,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:84.93': 0.16; 'received:84.93.230': 0.16;
'received:plus.net': 0.16; 'seconds.': 0.16; 'subject:does': 0.16;
'subject:seconds': 0.16; 'times,': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; 'cannot': 0.25; 'header:User-Agent:1': 0.30;
'think': 0.32; 'python-list': 0.32; 'received:192.168.1': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'subject:skip:d 10':
0.35; "it's": 0.37; 'received:192.168': 0.37; 'means': 0.38;
'seconds': 0.40; 'should': 0.40; 'days': 0.62; 'hours': 0.63;
'day': 0.66; 'subject:have': 0.75; 'paul': 0.81; 'about,': 0.84;
'attribute': 0.84; 'bryan': 0.84; 'composed': 0.84; 'jon': 0.84;
'leap': 0.84; 'subject:days': 0.84; 'subject:only': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1649956306; bh=RlkIyTr23hH3JSXHTCj+0AAH0JC41kdlr/EqxovxXMU=;
h=Date:Subject:To:References:From:In-Reply-To;
b=Xvbbsuwug+6sNZYuRJn88TheEoDzk2YnEOcRhU/Zcmo3tCWZx5oo9y25sExrQRL4Z
KTpBz3k0DYJU2i57vUBtzH2P4GaZfoArmE9kqbqGLYf0ETmSpkg4pespp65tH26Osk
rxQzd/YIIRSV+mCUdHS5R0YguFoJzVN2DZArUXMEO+mjoXgWYAZEFGkgCM43MTjxTq
BR37rAEcY+yBYtmAkU0hiky/Da+CJOY2Fd3Z/HUh0EBwfPKsHyctQrcm3dCOP4jPSo
9u7s/ksasYcmfnLZwQUfYwEC/GgFJ5s6YX/YKxx4l6dZ7hjSahkKkEVSiXsPVHny+K
bMG7DfcjhYlXw==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=Zs/+lv3G c=1 sm=1 tr=0 ts=625855d2
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=SO8S7t-XJe_s-KJb:21 a=IkcTkHD0fZMA:10 a=P84AbIVpAAAA:8
a=PimvXIDRTs5es3_rWJYA:9 a=QEXdDO2ut3YA:10 a=-WGtrfRMxLqBHcxsy0AX:22
a=8Y4fAUoeXZjZw0FnLti1:22
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Content-Language: en-GB
In-Reply-To: <slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
X-CMAE-Envelope: MS4xfImRG5oPbCRD+z18tEApypxfOdUndXpiuU/HK644ydp1K671uMuNXtGAwKwEZawFTXCEEcyz2cg2F0qxktihYAGNHJjbJcdDKGoGCKIy4KkymDYiK1OO
w6jkzILn/SwhNGmnac2CTqI3Uchm6zTuCNXWVG9o/Az+X4yWEQAMZnTNhmnB3ghUIE5M8DLBzbKtmRMTZFfZsySjLu0XJNSpew0=
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: <4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
 by: MRAB - Thu, 14 Apr 2022 17:11 UTC

On 2022-04-14 16:22, Jon Ribbens via Python-list wrote:
> On 2022-04-14, Paul Bryan <pbryan@anode.ca> wrote:
>> I think because minutes and hours can easily be composed by multiplying
>> seconds. days is separate because you cannot compose days from seconds;
>> leap seconds are applied to days at various times, due to
>> irregularities in the Earth's rotation.
>
> That's an argument that timedelta should *not* have a 'days' attribute,
> because a day is not a fixed number of seconds long (to know how long
> a day is, you have to know which day you're talking about, and where).
> It's an undocumented feature of timedelta that by 'day' it means '86400
> seconds'.

When you're working only with dates, timedelta not having a 'days'
attribute would be annoying, especially when you consider that a day is
usually 24 hours, but sometimes 23 or 25 hours (DST).

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Marco.Su...@gmail.com (Marco Sulla)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Thu, 14 Apr 2022 19:43:33 +0200
Lines: 11
Message-ID: <mailman.93.1649958251.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
<CABbU2U9qH2K4Ny8t-E7hxgWv-HCrTWoWndMPw8r+Jfkozwnd+w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de /jSAbyFCqIL/5s85JK/QKQ3fgGHoySnTJ8d1ZmMOWXwg==
Return-Path: <elbarbun@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=gh8dzxul;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.067
X-Spam-Evidence: '*H*': 0.87; '*S*': 0.01; '2022': 0.05;
'subject:Why': 0.07; 'cc:addr:python-list': 0.09; 'cc:no real
name:2**0': 0.14; 'from:name:marco sulla': 0.16; 'furthermore,':
0.16; 'hours,': 0.16; 'question,': 0.16; 'subject:does': 0.16;
'subject:seconds': 0.16; 'wrote:': 0.16; 'thu,': 0.19;
'cc:addr:python.org': 0.20; 'cc:2**0': 0.25; 'think': 0.32;
'message-id:@mail.gmail.com': 0.32; 'but': 0.32; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'question.': 0.35;
'subject:skip:d 10': 0.35; 'from:addr:gmail.com': 0.35; "it's":
0.37; 'received:209.85': 0.37; 'could': 0.38; 'received:209':
0.39; 'seconds': 0.40; 'initial': 0.61; 'hours': 0.63; 'day':
0.66; 'subject:have': 0.75; 'attribute': 0.84; 'delta,': 0.84;
'etc?': 0.84; 'leap': 0.84; 'subject:days': 0.84; 'subject:only':
0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=gz9PwcZpfeftou7SnsL+dOmjs0Ce70p3tCk33qD+HAc=;
b=gh8dzxullF2Pwi0ajM14mZtSue4gdtsbeQxHABtTM0o4mqg+YukhY+ga1jwandQ5S/
EsKkN2+4IPOJPOevHTSzvn2761M2IAq+VHu8nBIR1cptd5A4RecwRx2jHhwD1bbaelcm
zIVGbePRtJTxF/BfvrHMQEjapmxYBh8WVd8jMjyJqhJJEQZaV77bH04S6LfcA0w4tPOp
me91zY3x1QtnJCXYld0lwQOn5iEn55IryJjZoQOylPBQRkq1ghIdqEigdIHJSV0VeiBP
brLhgp2eqVEOZbYE3DtHGxeTLItb8a9takVOZtKER25VDaeLfdo7+RY+WP+DHW3V3KmC
EvGg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=gz9PwcZpfeftou7SnsL+dOmjs0Ce70p3tCk33qD+HAc=;
b=LfP3mOkPS1zQkHp+LakWRxtlH0CsYkQG559i/ThHAZ0fXnYSHJUwCEgnyOdaYkHzun
ynugflDw6JzD8y2Fy9C1vyydRJvoVUSrd9a/+BKewSmWpDFbKU9e4t7xe2yjvzioGD4C
hg8tn33IvV9ITbGAY0Bcft3IloanX3vn85Gkojjo7LDOMUlNZm2e8sSTHNUmGjAtWdXO
IPgsn+6mg7jvIrDi2PRmn9jin1kPyXT81hNCh1Lij+2G5rXyVfN9YjfIr6rNG5b+AlmW
geLoZBkpzC1wFQFUT1I+4ThiSim+zzKp2qF52R4MicrLmCxMkN+j6GmzA2XbnLpFWm+p
75cg==
X-Gm-Message-State: AOAM531YnJ40765aMNTOP6itgo+8Kvt4EBmd+TSg03nsdFnWBeM781tj
Un8aLlvGKED6I3fjhTzhnfLE2paq0YmnZxdhFTFuxwzX
X-Google-Smtp-Source: ABdhPJyHIFfFlP6nGdrFqvYOBL7Y36g2OmKqhGB/uhxtgAx0Tea6try3ZEgJN90jjFcxUrhGgGuVk/bZvAHsGjj/4JM=
X-Received: by 2002:a81:ad47:0:b0:2ee:927d:ff39 with SMTP id
l7-20020a81ad47000000b002ee927dff39mr2990298ywk.249.1649958249992; Thu, 14
Apr 2022 10:44:09 -0700 (PDT)
In-Reply-To: <4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
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: <CABbU2U9qH2K4Ny8t-E7hxgWv-HCrTWoWndMPw8r+Jfkozwnd+w@mail.gmail.com>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
 by: Marco Sulla - Thu, 14 Apr 2022 17:43 UTC

On Thu, 14 Apr 2022 at 19:16, MRAB <python@mrabarnett.plus.com> wrote:
>
> When you're working only with dates, timedelta not having a 'days'
> attribute would be annoying, especially when you consider that a day is
> usually 24 hours, but sometimes 23 or 25 hours (DST).

I agree. Furthermore, timedelta is, well, a time delta, not a date
with a timezone. How could a timedelta take into account DST, leap
seconds etc?

About the initial question, I think it's a good question.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Fri, 15 Apr 2022 03:58:17 +1000
Lines: 20
Message-ID: <mailman.95.1649959111.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
<CABbU2U9qH2K4Ny8t-E7hxgWv-HCrTWoWndMPw8r+Jfkozwnd+w@mail.gmail.com>
<CAPTjJmoVOBFdn28Fiix=Uy-h1ufZTe9nNUV0UfXpzhnmmyPWzA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de FrZmzs64m5YPXCuCmojgWg98x/replqZQaheGE0LxOBw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=B/41Rduk;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.031
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; '2022': 0.05;
'subject:Why': 0.07; 'datetime': 0.09; 'received:209.85.128.46':
0.09; 'received:mail-wm1-f46.google.com': 0.09; 'situations':
0.09; 'absence': 0.16; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'furthermore,': 0.16; 'hours,':
0.16; 'object,': 0.16; 'subject:does': 0.16; 'subject:seconds':
0.16; 'wrote:': 0.16; 'thu,': 0.19; 'to:addr:python-list': 0.20;
'fri,': 0.22; 'cannot': 0.25; 'message-id:@mail.gmail.com': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'subject:skip:d 10': 0.35; 'from:addr:gmail.com': 0.35;
'possibly': 0.36; "it's": 0.37; 'received:209.85': 0.37; 'could':
0.38; 'received:209': 0.39; 'seconds': 0.40; 'want': 0.40;
'hours': 0.63; 'day': 0.66; 'subject:have': 0.75; 'period.': 0.76;
'attribute': 0.84; 'delta,': 0.84; 'etc?': 0.84; 'leap': 0.84;
'subject:days': 0.84; 'subject:only': 0.84; 'sulla': 0.84;
'acknowledge': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=1Yu34pvP3EHq9jZmYEzm+5IJyH9l/8HUBNZSd6P3Ss4=;
b=B/41RdukzRElRDdjxfXIw2c9+zgcSYZScaK5pvONWSOPeur8sJg8DVtVFBR31nxLOA
PrfY3lp6Bi1pwW21OHXjK9tzzLssJNJ/iLr+RennC8vWGBpYnCNk1gjqNl4U43dSXgPc
httQFvrTCFR83mTIDXRPSmWEm264iKZgcz06XAuPqZCQJeVGKwWf3M7QPT4+Z8inEo5D
Izm5ScNX8FHg/ZqrK+Ea+nbaENXjR6huHp31ctltGOL9wr716hqTwHTbB9do/5yy+NTf
EsIJ4rsrSFF67mR4JaIqdv/pnL2RVCl/VZXyCNXMMxM1HTMkap0NzT8mbaZQyP/TSLOg
QKpw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=1Yu34pvP3EHq9jZmYEzm+5IJyH9l/8HUBNZSd6P3Ss4=;
b=3Vk2JdYfwoBoZU2rYpyDrrDspaG4SzsD+cv/Njs9Wo0iwpfl4bflpAUB/gQr2SbWtl
VsR/Dg3tF2w3jdLI2dequ+ozwoMcFsZDdQBnSIzacSkQx2BULtl5JzYJqiJVV/9zOHtC
UbNyqdaA6ncBRh9NfPEry294VYifiPTYqUNvFjFlEGQV2GtJ2pFUIfHY+3NxOvt5Iwvd
g8aNyEU91gNUW2COzVFmKv3akGh9xx5Sf+7dbC04iojDcFLaxN80Idd+Rivzl8IY12D0
EPQumind/LgbGjPxJ7ump+FEgGVxdVneSd0T0e1Z4X3EfgSVkc1K6QWftm4Byl5/WVGT
trRg==
X-Gm-Message-State: AOAM5339WKNvMTZoHssC1X6U0Xjd5l3aZpHD1/9CQZuGQF3F6VHGz75k
a4PPT37BHpHRrIC5hIR3IOvdAQuT6RuTP/nOCguEsrL/
X-Google-Smtp-Source: ABdhPJy0e/ycs33KzugB33U9oXBGMdaqRilO0saoHQPeG5kqPpUyn6I8ZqMAq4zk+w5VakUO3ixLRtuFrdKQ35m73hM=
X-Received: by 2002:a7b:cbd3:0:b0:38e:bc95:5048 with SMTP id
n19-20020a7bcbd3000000b0038ebc955048mr4213531wmi.203.1649959109266; Thu, 14
Apr 2022 10:58:29 -0700 (PDT)
In-Reply-To: <CABbU2U9qH2K4Ny8t-E7hxgWv-HCrTWoWndMPw8r+Jfkozwnd+w@mail.gmail.com>
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: <CAPTjJmoVOBFdn28Fiix=Uy-h1ufZTe9nNUV0UfXpzhnmmyPWzA@mail.gmail.com>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
<CABbU2U9qH2K4Ny8t-E7hxgWv-HCrTWoWndMPw8r+Jfkozwnd+w@mail.gmail.com>
 by: Chris Angelico - Thu, 14 Apr 2022 17:58 UTC

On Fri, 15 Apr 2022 at 03:45, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
>
> On Thu, 14 Apr 2022 at 19:16, MRAB <python@mrabarnett.plus.com> wrote:
> >
> > When you're working only with dates, timedelta not having a 'days'
> > attribute would be annoying, especially when you consider that a day is
> > usually 24 hours, but sometimes 23 or 25 hours (DST).
>
> I agree. Furthermore, timedelta is, well, a time delta, not a date
> with a timezone. How could a timedelta take into account DST, leap
> seconds etc?

It can't. It's a simple representation of a time period. It is useful
for situations where you want to express questions like "from this
date/time, wait this long, what will the date/time be?".

In the absence of a corresponding timezone-aware datetime object, it
cannot possibly acknowledge DST.

ChrisA

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<slrnt5gojb.41c.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Thu, 14 Apr 2022 18:05:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <slrnt5gojb.41c.jon+usenet@raven.unequivocal.eu>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<4346b8a5-30ff-6340-e03d-b32ee9433f31@mrabarnett.plus.com>
<mailman.91.1649956494.20749.python-list@python.org>
Injection-Date: Thu, 14 Apr 2022 18:05:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2fdfa296348d7bacaa7716edad0e418d";
logging-data="30878"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ikKKlaDgyBl4OxIOuHdEEjNVdxzqe4yY="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:+CAPKa3qsZmXFZaT9dMqiiQjvlQ=
 by: Jon Ribbens - Thu, 14 Apr 2022 18:05 UTC

On 2022-04-14, MRAB <python@mrabarnett.plus.com> wrote:
> On 2022-04-14 16:22, Jon Ribbens via Python-list wrote:
>> On 2022-04-14, Paul Bryan <pbryan@anode.ca> wrote:
>>> I think because minutes and hours can easily be composed by multiplying
>>> seconds. days is separate because you cannot compose days from seconds;
>>> leap seconds are applied to days at various times, due to
>>> irregularities in the Earth's rotation.
>>
>> That's an argument that timedelta should *not* have a 'days' attribute,
>> because a day is not a fixed number of seconds long (to know how long
>> a day is, you have to know which day you're talking about, and where).
>> It's an undocumented feature of timedelta that by 'day' it means '86400
>> seconds'.
>
> When you're working only with dates, timedelta not having a 'days'
> attribute would be annoying, especially when you consider that a day is
> usually 24 hours, but sometimes 23 or 25 hours (DST).

The second half of your sentence is the argument as to why the first half
of your sentence is wrong. The difference between noon on the 26th March
2022 in London and noon on the 27th March 2022 is "1 day" from one point
of view but is not "1 day" according to timedelta.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Fri, 15 Apr 2022 04:07:30 +1000
Lines: 58
Message-ID: <mailman.97.1649959664.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<CAPTjJmoLKE+HDt-ZkWbBGZJGGFQ13ttHFqyH2GwRqJivE-jhbw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de NFHeJvETRNbNaP8YwE3dDgMqJU6RyjsEcbtnjMOgG8AA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=TK/atSjc;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.021
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '2022': 0.05; 'bunch':
0.05; 'subject:Why': 0.07; 'datetime': 0.09; 'properties': 0.09;
'import': 0.15; '1441': 0.16; 'attributes': 0.16; 'bennett': 0.16;
'chosen,': 0.16; 'chrisa': 0.16; 'constructor': 0.16; 'easiest':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'mentioned,': 0.16; 'relatively': 0.16; 'sequentially': 0.16;
'subject:does': 0.16; 'subject:seconds': 0.16; 'ways.': 0.16;
'wrote:': 0.16; 'python': 0.16; 'applications': 0.17; 'probably':
0.17; 'to:addr:python-list': 0.20; 'fri,': 0.22; 'weeks': 0.23;
'object': 0.26; 'done': 0.28; '>>>': 0.28; 'question': 0.32;
'weeks,': 0.32; "wouldn't": 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'there': 0.33; 'particular': 0.33; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'subject:skip:d
10': 0.35; 'from:addr:gmail.com': 0.35; 'those': 0.36;
'received:209.85': 0.37; 'hard': 0.37; 'way': 0.38; 'could': 0.38;
'received:209': 0.39; 'adding': 0.39; 'enough': 0.39; 'define':
0.40; 'otherwise,': 0.40; 'seconds': 0.40; 'view': 0.60; 'skip:h
10': 0.61; "there's": 0.61; 'days': 0.62; 'hours': 0.63; 'full':
0.64; 'definition': 0.64; 'let': 0.66; 'entire': 0.67; 'obvious':
0.69; 'subject:have': 0.75; 'yourself': 0.75; '....': 0.76;
'change,': 0.76; 'unit': 0.81; 'attribute': 0.84; 'label,': 0.84;
'subject:days': 0.84; 'subject:only': 0.84; 'skip:d 30': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=QDAixKZjepICIbZye48w0YqxfSGUL9vge86WIol+Nig=;
b=TK/atSjcYkjUYHqqIb0u8xoBp+yJAQhhhit7bTmhkaT0x1fVi9Jv74JKdRw0BJ9dH5
Vks8jEHAYlebIJZQW1HuppvO9gifqN3FU5mV9jAsM4vevDPl7J+Rx3RtblOBLn4qHDmZ
2qm9K59gn1cMEUaVJ8zvroC6mnW1p4dkhJkyMoqcoh7tCUc5NrsFhVSQ5Rv6CS5GclFX
YX8wIn7SEF/7dVdErUEPy7BE61ygCtbG0pTDooZC+hQ2AXSuonUR7aeZqiG1I5SJ4gNl
IhsqbaaLw2tAeMBAZv8Zx6cUAbAmSGqSQ1vv4sJl2nsmG+pbybdlhkUtKkmEeIspWIQA
+r9g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=QDAixKZjepICIbZye48w0YqxfSGUL9vge86WIol+Nig=;
b=qNR80T8c/pvTTdYgyTzoR0Vpk2MJ5GdW8wiqDZvGttzZVb40i6CBF8WMcYy0reamf7
JPNkEI2BlklMqzlxk9wZX3u+PJWNGjYDOms3NxpAb4THUE2daQpBp2867Lnf1UgO0BnD
7kiwkOM3b3i21rjERC1VvnaOfMtYMVGDqYDi7CxwBoZz75mMfs+zDgU30wEt81X3pCMs
6X8/TERC0j8Gr5INueQbXxsiDasylXn4VTiQch170NdcB0AcG/sWuIlTcPwv5BoqUAAP
OvDs5uoetutzsCXsBQlNTO2hCBAFKzi0i4Kz2P9CwitOv4/YU6M9Jj0iZLwIoJKYrhyR
Wufg==
X-Gm-Message-State: AOAM533dBwTX61/mB+xcwrc91ESfmjMID2/mWKKao4e0fQxy3IR15exo
k1dTOcFTpOIV4IdiscZI+z0DX5LW7AVPxTIi4qnnR6E1ZTY=
X-Google-Smtp-Source: ABdhPJwrBZzyKrc/s2MjvswrmCBk6Byg31TP/eHjRWP4lLLmMgDn29Gawug+PxT7Lf72C6UBTayqZTlXraRHBkNe/cQ=
X-Received: by 2002:a05:600c:4f15:b0:38c:b729:4838 with SMTP id
l21-20020a05600c4f1500b0038cb7294838mr4355786wmq.132.1649959662059; Thu, 14
Apr 2022 11:07:42 -0700 (PDT)
In-Reply-To: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
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: <CAPTjJmoLKE+HDt-ZkWbBGZJGGFQ13ttHFqyH2GwRqJivE-jhbw@mail.gmail.com>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
 by: Chris Angelico - Thu, 14 Apr 2022 18:07 UTC

On Fri, 15 Apr 2022 at 00:54, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>
> Hi,
>
> With Python 3.9.2 I get
>
> $ import datetime
> $ s = "1-00:01:01"
> $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
> $ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute, seconds=t.second)
> $ d.days
> 1
> $ d.seconds
> 61
> $ d.minutes
> AttributeError: 'datetime.timedelta' object has no attribute 'minutes'
>
> Is there a particular reason why there are no attributes 'minutes' and
> 'hours and the attribute 'seconds' encompasses is the entire fractional
> day?
>

You can get those by dividing:

>>> divmod(d, datetime.timedelta(minutes=1))
(1441, datetime.timedelta(seconds=1))

But the obvious question is: how many minutes ARE there in this time
period? I give a response of 1441 (or if you prefer, 1441 + 1/60 or
roughly 1441.017), but you might just as reasonably consider that
there is one minute.

If a good definition could be chosen, it wouldn't be too hard to add a
bunch of properties to the timedelta that let you view it in other
ways. Otherwise, the easiest way is probably to define yourself a set
of units and sequentially divmod:

>>> units = {"days": datetime.timedelta(days=1), "hours": datetime.timedelta(hours=1), "minutes": datetime.timedelta(minutes=1), "seconds": datetime.timedelta(seconds=1)}
>>> for label, unit in units.items():
.... n, d = divmod(d, unit)
.... print(n, label)
....
1 days
0 hours
1 minutes
1 seconds
>>>

This way, you have full control over which units are "interesting";
for instance, the constructor supports weeks, but a lot of
applications won't consider them to be important, and would prefer to
see "20 days" than "2 weeks and 6 days".

But, as mentioned, adding properties to timedelta would be a
relatively benign change, so it could be done if there's enough need
and a good definition.

ChrisA

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 10:44:11 +0200
Lines: 110
Message-ID: <mailman.123.1650098653.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="uehwh3ukohibtlcm"
X-Trace: news.uni-berlin.de kVWBklGwvRkhMHmkRInM+g/nqgRYOb5/lqZ15KrNmcVA==
Return-Path: <hjp-python@hjp.at>
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; 'argument': 0.04; 'content-
type:multipart/signed': 0.05; '(to': 0.07; '26,': 0.07;
'subject:Why': 0.07; 'wrong.': 0.07; '*not*': 0.09; '27,': 0.09;
'content-type:application/pgp-signature': 0.09; 'datetime': 0.09;
'filename:fname piece:asc': 0.09; 'filename:fname
piece:signature': 0.09; 'filename:fname:signature.asc': 0.09;
'smaller': 0.09; 'import': 0.15; '"creative': 0.16; '__/': 0.16;
'arithmetic': 0.16; 'bug,': 0.16; 'challenge!"': 0.16;
'determines': 0.16; 'from:addr:hjp-python': 0.16;
'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'hjp@hjp.at': 0.16; 'holzer': 0.16; 'missed': 0.16; 'noon': 0.16;
'reality.': 0.16; 'seconds.': 0.16; 'separately': 0.16; 'stross,':
0.16; 'subject:does': 0.16; 'subject:seconds': 0.16; 'times,':
0.16; 'timezone': 0.16; 'units,': 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; 'python': 0.16; 'larger': 0.17; "can't": 0.17; 'to:addr
:python-list': 0.20; "i'd": 0.24; 'cannot': 0.25; '>>>': 0.28;
'sense': 0.28; 'effect': 0.31; 'think': 0.32; 'here,': 0.32;
'python-list': 0.32; 'march': 0.33; 'same': 0.34; 'work.': 0.34;
'header:In-Reply-To:1': 0.34; 'subject:skip:d 10': 0.35; "it's":
0.37; 'means': 0.38; 'seconds': 0.40; 'should': 0.40;
'received:212': 0.62; 'days': 0.62; 'hours': 0.63; 'simply': 0.63;
'months.': 0.64; 'received:userid': 0.66; 'day': 0.66; 'exactly':
0.68; 'url-ip:212/8': 0.69; 'subject:have': 0.75; '8bit%:100':
0.76; 'paul': 0.81; 'time:': 0.81; 'about,': 0.84; 'bryan': 0.84;
'composed': 0.84; 'jon': 0.84; 'leap': 0.84; 'received:at': 0.84;
'subject:days': 0.84; 'subject:only': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
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: <20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
 by: Peter J. Holzer - Sat, 16 Apr 2022 08:44 UTC
Attachments: signature.asc (application/pgp-signature)

On 2022-04-14 15:22:29 -0000, Jon Ribbens via Python-list wrote:
> On 2022-04-14, Paul Bryan <pbryan@anode.ca> wrote:
> > I think because minutes and hours can easily be composed by multiplying
> > seconds. days is separate because you cannot compose days from seconds;
> > leap seconds are applied to days at various times, due to
> > irregularities in the Earth's rotation.
>
> That's an argument that timedelta should *not* have a 'days' attribute,
> because a day is not a fixed number of seconds long (to know how long
> a day is, you have to know which day you're talking about, and where).

Which is exactly why timedelta *must* have separate fields for seconds,
days and months. You can't simply express the larger units as
multiples of the smaller units, so they have to be stored separately for
date arithmetic to work.

> It's an undocumented feature of timedelta that by 'day' it means '86400
> seconds'.

I'd call that a bug, not a feature:

>>> from datetime import datetime, timedelta
>>> t0 = datetime.fromisoformat("2022-03-26T12:00").astimezone()
>>> t0
datetime.datetime(2022, 3, 26, 12, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
>>> d = timedelta(days=1)
>>> t1 = t0 + d
>>> t1
datetime.datetime(2022, 3, 27, 12, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
>>> t1.isoformat()
'2022-03-27T12:00:00+01:00'

Python missed the switch to DST here, the timezone is wrong.

If I do the same thing in PostgreSQL:

hjp=> select '2022-03-26T12:00'::timestamptz;
╔════════════════════════╗
║ timestamptz ║
╟────────────────────────╢
║ 2022-03-26 12:00:00+01 ║
╚════════════════════════╝
(1 row)

Time: 5.542 ms
hjp=> select '2022-03-26T12:00'::timestamptz + '1 day'::interval;
╔════════════════════════╗
║ ?column? ║
╟────────────────────────╢
║ 2022-03-27 12:00:00+02 ║
╚════════════════════════╝
(1 row)

It correctly determines that DST is already in effect at noon of March 27th.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 13:47:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
Injection-Date: Sat, 16 Apr 2022 13:47:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5b0817d76f537876a52dc40a5b0887ce";
logging-data="16334"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vq/2wvTQraIxwFWvCqGzmOoTOBA3mDrI="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:FcJ17ilagkE0dcJXCzhhdnYtnzg=
 by: Jon Ribbens - Sat, 16 Apr 2022 13:47 UTC

On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
> On 2022-04-14 15:22:29 -0000, Jon Ribbens via Python-list wrote:
>> On 2022-04-14, Paul Bryan <pbryan@anode.ca> wrote:
>> > I think because minutes and hours can easily be composed by multiplying
>> > seconds. days is separate because you cannot compose days from seconds;
>> > leap seconds are applied to days at various times, due to
>> > irregularities in the Earth's rotation.
>>
>> That's an argument that timedelta should *not* have a 'days' attribute,
>> because a day is not a fixed number of seconds long (to know how long
>> a day is, you have to know which day you're talking about, and where).
>
> Which is exactly why timedelta *must* have separate fields for seconds,
> days and months. You can't simply express the larger units as
> multiples of the smaller units, so they have to be stored separately for
> date arithmetic to work.

That's impossible unless you redefine 'timedelta' from being, as it is
now, a fixed-length period of time, to instead being the difference
between two specific dates and times in specific timezones. Days and
months have different lengths depending on when and where you are.

>> It's an undocumented feature of timedelta that by 'day' it means '86400
>> seconds'.
>
> I'd call that a bug, not a feature:

It's the only possible way of implementing it, so it can't be a bug.
The documentation could be better though.

>>>> from datetime import datetime, timedelta
>>>> t0 = datetime.fromisoformat("2022-03-26T12:00").astimezone()
>>>> t0
> datetime.datetime(2022, 3, 26, 12, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
>>>> d = timedelta(days=1)
>>>> t1 = t0 + d
>>>> t1
> datetime.datetime(2022, 3, 27, 12, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
>>>> t1.isoformat()
> '2022-03-27T12:00:00+01:00'
>
> Python missed the switch to DST here, the timezone is wrong.

Because you didn't let it use any timezone information. You need to
either use the third-party 'pytz' module, or in Python 3.9 or above,
the built-in 'zoneinfo' module.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 14:22:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
Injection-Date: Sat, 16 Apr 2022 14:22:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5b0817d76f537876a52dc40a5b0887ce";
logging-data="32049"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180iJJOUFZZKCqonmAI512ea5dnUseiKgs="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:A2hCFQuJSXCAEz9/gqVymOzTzts=
 by: Jon Ribbens - Sat, 16 Apr 2022 14:22 UTC

On 2022-04-16, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
> On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
>> Python missed the switch to DST here, the timezone is wrong.
>
> Because you didn't let it use any timezone information. You need to
> either use the third-party 'pytz' module, or in Python 3.9 or above,
> the built-in 'zoneinfo' module.

.... although now having looked into the new 'zoneinfo' module slightly,
it really should have a giant red flashing notice at the top of it
saying "BEWARE, TIMEZONES IN PYTHON ARE UTTERLY BROKEN, NEVER USE THEM".

Suppose we do this:

>>> import datetime, zoneinfo
>>> LOS_ANGELES = zoneinfo.ZoneInfo('America/Los_Angeles')
>>> UTC = zoneinfo.ZoneInfo('UTC')
>>> d = datetime.datetime(2020, 10, 31, 12, tzinfo=LOS_ANGELES)
>>> print(d)
2020-10-31 12:00:00-07:00
>>> d1 = d + datetime.timedelta(days=1)
>>> print(d1)
2020-11-01 12:00:00-08:00

d1 is *wrong*. timedelta(days=1) is 24 hours (as you can check by
calling timedelta(days=1).total_seconds() ), but d1 is 25 hours later
than 'd'. If we do the calculations in UTC instead, it works correctly:

>>> print((d.astimezone(UTC) + datetime.timedelta(days=1)).astimezone(LOS_ANGELES))
2020-11-01 11:00:00-08:00

It seems that Python is assuming that if the tzinfo attributes of two
datetimes are the same, then it can pretend timezones don't exist and
do 'naive' arithmetic. This is of course a totally false assumption.
Apparently when making the native version of 'zoneinfo', the lessons
learned from 'pytz' have been discarded.

There is a general guideline that you should always keep and use your
datetimes as UTC, only ever using timezones for the purposes of display.
Usually this is because it keeps things simpler for the programmer, and
hence they are less likely to introduce bugs into their programs. It
appears that with Python it's not so much a guideline as an absolute
concrete rule, and not because programmers will introduce bugs, but
because you need to avoid bugs in the standard library!

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 17:27:26 +0200
Lines: 103
Message-ID: <mailman.126.1650122848.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<20220416152726.nayck4tihbzsnrk7@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="cliohtjianvqclux"
X-Trace: news.uni-berlin.de KQQ6vEGJZnGKG6MFkJ3TBQrSKRgoxNyJPU39Moo2+ALQ==
Return-Path: <hjp-python@hjp.at>
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; 'argument': 0.04;
'containing': 0.05; 'content-type:multipart/signed': 0.05; '(to':
0.07; '26,': 0.07; 'have,': 0.07; 'simple.': 0.07; 'subject:Why':
0.07; 'wrong.': 0.07; '*not*': 0.09; '27,': 0.09; 'content-
type:application/pgp-signature': 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; 'smaller': 0.09; 'import': 0.15; '"creative': 0.16;
'>>>>': 0.16; '__/': 0.16; 'are.': 0.16; 'arithmetic': 0.16;
'bug,': 0.16; 'challenge!"': 0.16; 'from:addr:hjp-python': 0.16;
'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'hjp@hjp.at': 0.16; 'holzer': 0.16; 'impossible': 0.16; 'missed':
0.16; 'reality.': 0.16; 'seconds.': 0.16; 'separately': 0.16;
'stross,': 0.16; 'subject:does': 0.16; 'subject:seconds': 0.16;
'times,': 0.16; 'timezone': 0.16; 'units,': 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; 'python': 0.16; 'larger': 0.17; 'instead': 0.17; "can't":
0.17; 'calls': 0.19; 'implement': 0.19; 'to:addr:python-list':
0.20; 'languages': 0.22; "i'd": 0.24; 'cannot': 0.25;
'programming': 0.25; "isn't": 0.27; 'expect': 0.28; 'sense': 0.28;
'it,': 0.29; 'think': 0.32; 'here,': 0.32; 'python-list': 0.32;
'unless': 0.32; "i'm": 0.33; "didn't": 0.34; 'work.': 0.34;
'header:In-Reply-To:1': 0.34; 'complex': 0.35; 'definitely': 0.35;
'subject:skip:d 10': 0.35; 'months': 0.35; "it's": 0.37; 'class':
0.37; 'way': 0.38; 'means': 0.38; 'two': 0.39; 'quite': 0.39;
'use': 0.39; 'otherwise,': 0.40; 'seconds': 0.40; 'something':
0.40; 'should': 0.40; 'received:212': 0.62; 'days': 0.62; 'hours':
0.63; 'simply': 0.63; 'between': 0.63; 'months.': 0.64; 'let':
0.66; 'received:userid': 0.66; 'day': 0.66; 'now,': 0.67; 'types':
0.67; 'time,': 0.67; 'exactly': 0.68; 'url-ip:212/8': 0.69;
'times': 0.69; 'depending': 0.70; 'too.': 0.70; 'subject:have':
0.75; 'implemented': 0.76; 'zone': 0.76; 'paul': 0.81; 'period':
0.81; 'returned': 0.81; 'about,': 0.84; 'being,': 0.84; 'bryan':
0.84; 'composed': 0.84; 'jon': 0.84; 'leap': 0.84; 'postgresql':
0.84; 'received:at': 0.84; 'subject:days': 0.84; 'subject:only':
0.84; 'skip:( 50': 0.93
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
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: <20220416152726.nayck4tihbzsnrk7@hjp.at>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
 by: Peter J. Holzer - Sat, 16 Apr 2022 15:27 UTC
Attachments: signature.asc (application/pgp-signature)

On 2022-04-16 13:47:32 -0000, Jon Ribbens via Python-list wrote:
> On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > On 2022-04-14 15:22:29 -0000, Jon Ribbens via Python-list wrote:
> >> On 2022-04-14, Paul Bryan <pbryan@anode.ca> wrote:
> >> > I think because minutes and hours can easily be composed by multiplying
> >> > seconds. days is separate because you cannot compose days from seconds;
> >> > leap seconds are applied to days at various times, due to
> >> > irregularities in the Earth's rotation.
> >>
> >> That's an argument that timedelta should *not* have a 'days' attribute,
> >> because a day is not a fixed number of seconds long (to know how long
> >> a day is, you have to know which day you're talking about, and where).
> >
> > Which is exactly why timedelta *must* have separate fields for seconds,
> > days and months. You can't simply express the larger units as
> > multiples of the smaller units, so they have to be stored separately for
> > date arithmetic to work.
>
> That's impossible unless you redefine 'timedelta' from being, as it is
> now, a fixed-length period of time, to instead being the difference
> between two specific dates and times in specific timezones. Days and
> months have different lengths depending on when and where you are.

That's what I would have expected it to be. Otherwise, why bother with a
class when a simple float suffices?

Date arithmetic isn't simple. You need complex data types to implement
it correctly.

> >> It's an undocumented feature of timedelta that by 'day' it means '86400
> >> seconds'.
> >
> > I'd call that a bug, not a feature:
>
> It's the only possible way of implementing it,

It's definitely not the only possible way of implementing it. PostgreSQL
for examply has implemented it correctly. I'm quite sure some other
programming languages have, too.

> >>>> from datetime import datetime, timedelta
> >>>> t0 = datetime.fromisoformat("2022-03-26T12:00").astimezone()
> >>>> t0
> > datetime.datetime(2022, 3, 26, 12, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
> >>>> d = timedelta(days=1)
> >>>> t1 = t0 + d
> >>>> t1
> > datetime.datetime(2022, 3, 27, 12, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET'))
> >>>> t1.isoformat()
> > '2022-03-27T12:00:00+01:00'
> >
> > Python missed the switch to DST here, the timezone is wrong.
>
> Because you didn't let it use any timezone information.

I used astimezone() and it returned something something that Python
calls "timezone aware" containing time zone information which is
correct for that time and my location
(tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET')). Why
should I expect a "timezone aware" datetime to not be actually timezone
aware?

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 18:00:28 +0200
Lines: 121
Message-ID: <mailman.127.1650124831.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="ocu6oscfap7t46yz"
X-Trace: news.uni-berlin.de gnRD1eRPULXV+KwGjs77VwoIgKP6fbROHshLg2xiOp5g==
Return-Path: <hjp-python@hjp.at>
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; 'this:': 0.03; '31,': 0.05;
'absolute': 0.05; 'content-type:multipart/signed': 0.05; '2023':
0.07; 'programmer': 0.07; 'subject:Why': 0.07; 'utc': 0.07;
'wrong.': 0.07; 'adapt': 0.09; 'content-type:application/pgp-
signature': 0.09; 'datetime': 0.09; 'filename:fname piece:asc':
0.09; 'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'module.': 0.09;
"shouldn't": 0.09; 'skip:z 20': 0.09; 'import': 0.15; 'problem.':
0.15; '"creative': 0.16; '(there': 0.16; '(unless': 0.16; '18:00':
0.16; '3.9': 0.16; '__/': 0.16; 'assuming': 0.16; 'attributes':
0.16; 'bugs': 0.16; 'calculations': 0.16; 'challenge!"': 0.16;
'examples.': 0.16; 'from:addr:hjp-python': 0.16;
'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'happen.': 0.16; 'hjp@hjp.at': 0.16; 'holzer': 0.16; 'hours,':
0.16; 'missed': 0.16; 'reality.': 0.16; 'rules.': 0.16;
'scheduling': 0.16; 'stross,': 0.16; 'subject:does': 0.16;
'subject:seconds': 0.16; 'third-party': 0.16; 'though:': 0.16;
'timezone': 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; 'python': 0.16; 'advance.':
0.17; 'to:addr:python-list': 0.20; 'maybe': 0.22; 'purposes':
0.22; '(and': 0.25; 'saying': 0.25; 'seems': 0.26; 'library':
0.26; 'local': 0.27; '>>>': 0.28; 'expect': 0.28; 'sense': 0.28;
'example,': 0.28; 'wrong': 0.28; 'looked': 0.31; 'module': 0.31;
"doesn't": 0.32; '(as': 0.32; 'context': 0.32; 'guess': 0.32;
'here,': 0.32; 'programmers': 0.32; 'python-list': 0.32; 'same,':
0.32; 'skip:2 10': 0.32; 'but': 0.32; 'there': 0.33; "didn't":
0.34; 'header:In-Reply-To:1': 0.34; 'subject:skip:d 10': 0.35;
'cases': 0.36; 'work,': 0.36; 'year': 0.36; 'guide': 0.37;
'really': 0.37; 'using': 0.37; "it's": 0.37; 'way': 0.38; 'two':
0.39; 'adding': 0.39; 'use': 0.39; 'still': 0.40; 'appears': 0.40;
'both': 0.40; 'want': 0.40; 'should': 0.40; 'july': 0.60;
'stated': 0.60; '10,': 0.61; 'likely': 0.61; 'received:212': 0.62;
'days': 0.62; 'ever': 0.63; 'hours': 0.63; 'simply': 0.63;
'events': 0.63; 'your': 0.64; 'top': 0.65; 'less': 0.65; 'pay':
0.65; 'let': 0.66; 'received:userid': 0.66; 'day': 0.66;
'decided': 0.67; 'generally': 0.67; 'skip:t 30': 0.67; 'customer':
0.67; 'url-ip:212/8': 0.69; 'within': 0.69; 'above,': 0.70;
'depending': 0.70; 'instead,': 0.70; 'rules': 0.70;
'subject:have': 0.75; 'extra': 0.84; 'aware,': 0.84; 'jon': 0.84;
'pretend': 0.84; 'received:at': 0.84; 'skip:z 40': 0.84;
'subject:days': 0.84; 'subject:only': 0.84; 'want.': 0.84; 'cet':
0.91; 'somebody': 0.91; 'zone.': 0.91
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
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: <20220416160028.tmedahn64gdpzsov@hjp.at>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
 by: Peter J. Holzer - Sat, 16 Apr 2022 16:00 UTC
Attachments: signature.asc (application/pgp-signature)

On 2022-04-16 14:22:04 -0000, Jon Ribbens via Python-list wrote:
> On 2022-04-16, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
> > On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
> >> Python missed the switch to DST here, the timezone is wrong.
> >
> > Because you didn't let it use any timezone information. You need to
> > either use the third-party 'pytz' module, or in Python 3.9 or above,
> > the built-in 'zoneinfo' module.
>
> ... although now having looked into the new 'zoneinfo' module slightly,
> it really should have a giant red flashing notice at the top of it
> saying "BEWARE, TIMEZONES IN PYTHON ARE UTTERLY BROKEN, NEVER USE THEM".
>
> Suppose we do this:
>
> >>> import datetime, zoneinfo
> >>> LOS_ANGELES = zoneinfo.ZoneInfo('America/Los_Angeles')
> >>> UTC = zoneinfo.ZoneInfo('UTC')
> >>> d = datetime.datetime(2020, 10, 31, 12, tzinfo=LOS_ANGELES)
> >>> print(d)
> 2020-10-31 12:00:00-07:00
> >>> d1 = d + datetime.timedelta(days=1)
> >>> print(d1)
> 2020-11-01 12:00:00-08:00
>
> d1 is *wrong*.

No, this is correct. That's the result you want.

So why didn't this work for me (I also used Python 3.9)? My guess is
that astimezone() doesn't pick the correct time zone.

> timedelta(days=1) is 24 hours (as you can check by
> calling timedelta(days=1).total_seconds() ),

It shouldn't be. 1 Day is not 24 hours in the real world.

> but d1 is 25 hours later
> than 'd'. If we do the calculations in UTC instead, it works correctly:
>
> >>> print((d.astimezone(UTC) + datetime.timedelta(days=1)).astimezone(LOS_ANGELES))
> 2020-11-01 11:00:00-08:00
>
> It seems that Python is assuming that if the tzinfo attributes of two
> datetimes are the same,

There is only one datetime in your examples.

> then it can pretend timezones don't exist and do 'naive' arithmetic.

On the contrary. When a datetime is timezone aware, it must use that
timezone's rules. Adding one day to a datetime just before a DST switch
must add 23 or 25 hours, not 24. This is NOT naive.

(There is an ambiguity, though: Should 2021-03-27T12:00 CEST -
2021-03-26T12:00 CET return 1 day or 25 hours? Both results are correct,
and depending on context you might prefer one or the other).

> There is a general guideline that you should always keep and use your
> datetimes as UTC, only ever using timezones for the purposes of display.
> Usually this is because it keeps things simpler for the programmer, and
> hence they are less likely to introduce bugs into their programs.

While I generally do this (and often preach it to my collegues) it must
be stated that this is only a GENERAL guide line. There are many
exceptions, especially when scheduling events in the future. For
example, if want to meet somebody on July 18th, 2023 at 19:00 in Vienna,
Austria, it would be wrong to store that date as 2023-07-18T17:00Z. The
EU has decided to abolish DST, and while I don't expect them to get
around to it within the next year (or maybe ever), it might still
happen. So we simply don't know yet whether 19:00 local time will be
17:00 or 18:00 UTC. There have been cases where countries have changed
their DST rules only days in advance.

> It appears that with Python it's not so much a guideline as an
> absolute concrete rule, and not because programmers will introduce
> bugs, but because you need to avoid bugs in the standard library!

As a programmer you must always adapt to the problem. Saying "I must do
it the wrong way because my library is buggy" is just lazy. Use a
different library or write one yourself. (Unless of course the customer
doesn't want to pay for the extra work, then they get what they pay
for.)

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sun, 17 Apr 2022 02:14:44 +1000
Lines: 49
Message-ID: <mailman.128.1650125697.20749.python-list@python.org>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de iYyV94ONxsT2pXOnWbgdnArgTKfhsJovRvnq8+iqNcAA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=IJlCcdsB;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '2022': 0.05;
'subject:Why': 0.07; 'sun,': 0.07; 'utc': 0.07; 'datetime': 0.09;
'later,': 0.09; "shouldn't": 0.09; 'problem.': 0.15; '(there':
0.16; 'assuming': 0.16; 'attributes': 0.16; 'calculations': 0.16;
'chrisa': 0.16; 'examples.': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'holzer': 0.16; 'hours,': 0.16;
'means.': 0.16; 'received:209.85.221.51': 0.16; 'received:mail-
wr1-f51.google.com': 0.16; 'rules.': 0.16; 'subject:does': 0.16;
'subject:seconds': 0.16; 'though:': 0.16; 'timezone': 0.16;
'wrote:': 0.16; 'python': 0.16; "can't": 0.17; 'it?': 0.19;
'to:addr:python-list': 0.20; 'seems': 0.26; 'again,': 0.26; '>>>':
0.28; '(as': 0.32; '168': 0.32; 'context': 0.32; 'python-list':
0.32; 'same,': 0.32; 'message-id:@mail.gmail.com': 0.32; 'skip:2
10': 0.32; 'but': 0.32; 'there': 0.33; 'same': 0.34; 'mean': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'subject:skip:d 10': 0.35; 'following': 0.35;
'from:addr:gmail.com': 0.35; "it's": 0.37; 'received:209.85':
0.37; 'received:209': 0.39; 'two': 0.39; 'adding': 0.39; 'use':
0.39; 'date.': 0.40; 'both': 0.40; 'should': 0.40; 'true': 0.63;
'hours': 0.63; 'imagine': 0.64; 'your': 0.64; 'required': 0.65;
'day': 0.66; 'skip:t 30': 0.67; 'exactly': 0.68; 'depending':
0.70; 'instead,': 0.70; 'subject:have': 0.75; 'period': 0.81;
'aware,': 0.84; 'jon': 0.84; 'pretend': 0.84; 'subject:days':
0.84; 'subject:only': 0.84; 'cet': 0.91; 'clock': 0.93; 'friend,':
0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=ylUgfJR6ygjgZqNE55TsvrQI8Ablss0Wk8O+j/jlsAI=;
b=IJlCcdsBoccdKgmgKY9iTxJwDF7xekR6o7TBdFtbF0m/TthR6i4Oya4wngG2X/XriD
duT7mLpf50NezA2RSvEs+HaYtKwdhqSPaTTHL+Mera+smNxx5IRI++OZKRvnB7oXD7l/
o8yPR7FS5SvAlCRJl0p8COGAnbRBbs7MXPgiwJX/qPp49E4xN9m+j0HjdQt9//aVNgSi
GjBSvqfEtzi1cKqzHgq3QWKrau7y7fn8kcGGKhXk1BjSwBjFk9RN2FJYOJ3dxK6AOMFb
mt6/rQqSTa+ugZvBBniQ8IHfKijSWxQZB+1P3F48qdDEO5a9MFY5E+1AMWlRq3xNna9S
Mstg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=ylUgfJR6ygjgZqNE55TsvrQI8Ablss0Wk8O+j/jlsAI=;
b=gVOLzBGgQ417i02vrwHCy0PbnQycbkC83oqwTFYi9d9QaSiPSbUsVBNHOsrLadR4jh
PzLqp404esLUUvytMoe3sed5K08ylCtaKfyqTmtQfiKdiaPrPGkc+MgE9TX/uDl3nocw
xHnq83kpYXCoSrSMORKIn+ZEq/BVEe8c3LIrQNrusH/zXSuZVzXtRau35RBZu3jew6KU
BXiMXw2MuHRMrROe9oJa2y81jhouXajB79mFbrAe58+k0ANFCmQ1C8diM2xgvCMGwqOR
yDMCVmygFqbkCKTEuycL6G4wa8nznXm0Qsj7J9nODXjJkpo7pThNQVMf/hPzzA2BdiBo
MiGQ==
X-Gm-Message-State: AOAM5312eAyEyF0tY3m0jqy5PiRc0bs2qmPbSUtGLPMwa1YXv7gRAvlQ
AxcV3Y6qBnbK8Wa+L8ByOc0UeFDm7GLfAvMG+EAo7bVN
X-Google-Smtp-Source: ABdhPJyePc4O9EENqhGINxgwSifc9UMTVGEhgEbjT7krjYo52czj7cee+4lK449voHkoJB7jCjmnLVmcxw4i/IvI3cA=
X-Received: by 2002:a5d:64e7:0:b0:204:b62:94c3 with SMTP id
g7-20020a5d64e7000000b002040b6294c3mr2897298wri.243.1650125696191; Sat, 16
Apr 2022 09:14:56 -0700 (PDT)
In-Reply-To: <20220416160028.tmedahn64gdpzsov@hjp.at>
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: <CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
X-Mailman-Original-References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
 by: Chris Angelico - Sat, 16 Apr 2022 16:14 UTC

On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer <hjp-python@hjp.at> wrote:
>
> On 2022-04-16 14:22:04 -0000, Jon Ribbens via Python-list wrote:
> > timedelta(days=1) is 24 hours (as you can check by
> > calling timedelta(days=1).total_seconds() ),
>
> It shouldn't be. 1 Day is not 24 hours in the real world.
>
> > but d1 is 25 hours later
> > than 'd'. If we do the calculations in UTC instead, it works correctly:
> >
> > >>> print((d.astimezone(UTC) + datetime.timedelta(days=1)).astimezone(LOS_ANGELES))
> > 2020-11-01 11:00:00-08:00
> >
> > It seems that Python is assuming that if the tzinfo attributes of two
> > datetimes are the same,
>
> There is only one datetime in your examples.
>
> > then it can pretend timezones don't exist and do 'naive' arithmetic.
>
> On the contrary. When a datetime is timezone aware, it must use that
> timezone's rules. Adding one day to a datetime just before a DST switch
> must add 23 or 25 hours, not 24. This is NOT naive.
>
> (There is an ambiguity, though: Should 2021-03-27T12:00 CEST -
> 2021-03-26T12:00 CET return 1 day or 25 hours? Both results are correct,
> and depending on context you might prefer one or the other).
>

That's exactly the problem. A day IS 24 hours *and* it is the time
period required for you to get to the same clock on the following
date. It's fundamentally ambiguous.

Let's take this out of Python altogether for a moment. Imagine that
it's 9AM Thursday. You say to your friend, hey, let's meet up again,
same time next week. Are you planning to meet 168 hours later, or at
9AM the following Thursday?

OF COURSE you mean 168 hours later. That's what "next week" means.

OF COURSE you're meeting at 9AM the following Thursday. That's what
"next week" means.

And they can't both be true if DST is changing.

So which one is it? Which one do you get when you add days=7 to a datetime?

ChrisA

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 18:44:08 +0200
Lines: 80
Message-ID: <mailman.129.1650127449.20749.python-list@python.org>
References: <87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="2s4u3a5ni3lzxdo7"
X-Trace: news.uni-berlin.de 2xLx4fUKNfEd7lFCozsXCArqwQ+t/72glOYJaVo0Kf+A==
Return-Path: <hjp-python@hjp.at>
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.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2022': 0.05; 'content-
type:multipart/signed': 0.05; 'subject:Why': 0.07; 'sun,': 0.07;
'angelico': 0.09; 'content-type:application/pgp-signature': 0.09;
'datetime': 0.09; 'filename:fname piece:asc': 0.09;
'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'later,': 0.09; 'problem.':
0.15; '"creative': 0.16; '(there': 0.16; '__/': 0.16;
'challenge!"': 0.16; 'from:addr:hjp-python': 0.16;
'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'general.': 0.16; 'hjp@hjp.at': 0.16; 'holzer': 0.16; 'hours,':
0.16; 'humans': 0.16; 'means.': 0.16; 'reality.': 0.16; 'rules.':
0.16; 'spec': 0.16; 'stross,': 0.16; 'subject:does': 0.16;
'subject:seconds': 0.16; 'though:': 0.16; 'timezone': 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; 'python': 0.16; "can't": 0.17; 'it?': 0.19; 'to:addr:python-
list': 0.20; 'again,': 0.26; "isn't": 0.27; 'chris': 0.28;
'sense': 0.28; 'error': 0.29; 'think': 0.32; '168': 0.32;
'context': 0.32; 'skip:2 10': 0.32; 'but': 0.32; 'same': 0.34;
'mean': 0.34; 'header:In-Reply-To:1': 0.34; 'subject:skip:d 10':
0.35; 'following': 0.35; 'also,': 0.36; 'count': 0.36; "it's":
0.37; 'this.': 0.37; 'means': 0.38; 'two': 0.39; 'adding': 0.39;
'enough': 0.39; 'use': 0.39; 'date.': 0.40; 'weeks.': 0.40;
'both': 0.40; 'should': 0.40; 'gives': 0.62; 'received:212': 0.62;
'true': 0.63; 'hours': 0.63; 'imagine': 0.64; 'your': 0.64;
'look': 0.65; 'required': 0.65; 'received:userid': 0.66; 'day':
0.66; 'rate': 0.67; 'technical': 0.67; 'exactly': 0.68; 'clear.':
0.69; 'url-ip:212/8': 0.69; 'depending': 0.70; 'subject:have':
0.75; 'zone': 0.76; 'period': 0.81; 'acutely': 0.84; 'aware,':
0.84; 'received:at': 0.84; 'subject:days': 0.84; 'subject:only':
0.84; 'cet': 0.91; 'clock': 0.93; 'friend,': 0.95
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
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: <20220416164408.zxnulyergevqprn7@hjp.at>
X-Mailman-Original-References: <87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
 by: Peter J. Holzer - Sat, 16 Apr 2022 16:44 UTC
Attachments: signature.asc (application/pgp-signature)

On 2022-04-17 02:14:44 +1000, Chris Angelico wrote:
> On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > On the contrary. When a datetime is timezone aware, it must use that
> > timezone's rules. Adding one day to a datetime just before a DST switch
> > must add 23 or 25 hours, not 24. This is NOT naive.
> >
> > (There is an ambiguity, though: Should 2021-03-27T12:00 CEST -
> > 2021-03-26T12:00 CET return 1 day or 25 hours? Both results are correct,
> > and depending on context you might prefer one or the other).
> >
>
> That's exactly the problem. A day IS 24 hours *and* it is the time
> period required for you to get to the same clock on the following
> date. It's fundamentally ambiguous.
>
> Let's take this out of Python altogether for a moment. Imagine that
> it's 9AM Thursday. You say to your friend, hey, let's meet up again,
> same time next week. Are you planning to meet 168 hours later, or at
> 9AM the following Thursday?
>
> OF COURSE you mean 168 hours later. That's what "next week" means.

Of course NOT. It means that only in 50 out of 52 weeks. A 4% error rate
is more than enough to make me acutely aware that it isn't true in
general. Also, won't count off 168 hours but look at my calendar/clock.

> OF COURSE you're meeting at 9AM the following Thursday. That's what
> "next week" means.

This. Certainly when meeting a friend. Almost certainly when dealing
with humans (if they are in a different time zone we may have to agree
on a time zone for "same time"). For a technical process I *might*
simplify "1 week" to "168 hours", but only if the spec gives me
sufficient leeway.

> And they can't both be true if DST is changing.
>
> So which one is it? Which one do you get when you add days=7 to a datetime?

For adding a datetime and timedelta I think the answer is clear.
But subtracting two datetimes is ambiguous.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sun, 17 Apr 2022 02:46:38 +1000
Lines: 52
Message-ID: <mailman.130.1650127613.20749.python-list@python.org>
References: <87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de +gHTWiIU99xjwxZRHXsC1gvn4fVJb0Cbl09nKp0mIXew==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=YCj2vu5o;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.033
X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '2022': 0.05;
'subject:Why': 0.07; 'sun,': 0.07; 'angelico': 0.09; 'datetime':
0.09; 'later,': 0.09; 'problem.': 0.15; '(there': 0.16; 'chrisa':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'general.': 0.16; 'holzer': 0.16; 'hours,': 0.16; 'humans': 0.16;
'means.': 0.16; 'received:209.85.128.41': 0.16; 'received:mail-
wm1-f41.google.com': 0.16; 'rules.': 0.16; 'spec': 0.16;
'subject:does': 0.16; 'subject:seconds': 0.16; 'though:': 0.16;
'timezone': 0.16; 'wrote:': 0.16; 'python': 0.16; "can't": 0.17;
'it?': 0.19; 'to:addr:python-list': 0.20; 'again,': 0.26; "isn't":
0.27; 'chris': 0.28; 'error': 0.29; 'think': 0.32; '168': 0.32;
'context': 0.32; 'message-id:@mail.gmail.com': 0.32; 'skip:2 10':
0.32; 'but': 0.32; 'same': 0.34; 'mean': 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'subject:skip:d 10':
0.35; 'following': 0.35; 'from:addr:gmail.com': 0.35; 'also,':
0.36; 'count': 0.36; "it's": 0.37; 'received:209.85': 0.37;
'this.': 0.37; 'means': 0.38; 'received:209': 0.39; 'two': 0.39;
'adding': 0.39; 'enough': 0.39; 'use': 0.39; 'date.': 0.40;
'weeks.': 0.40; 'both': 0.40; 'should': 0.40; 'gives': 0.62;
'true': 0.63; 'hours': 0.63; 'between': 0.63; 'imagine': 0.64;
'your': 0.64; 'look': 0.65; 'required': 0.65; 'day': 0.66; 'rate':
0.67; 'technical': 0.67; 'exactly': 0.68; 'clear.': 0.69;
'depending': 0.70; 'subject:have': 0.75; 'zone': 0.76; 'period':
0.81; 'acutely': 0.84; 'aware,': 0.84; 'subject:days': 0.84;
'subject:only': 0.84; 'cet': 0.91; 'clock': 0.93; 'friend,': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=FqECSAdXRkRoz3oE5wxTxv4wBH0ipA7AIFpO5CfA8ho=;
b=YCj2vu5oE0QpLrCV8mrJ07LQ4QLo+8zLT0SveR9Y8dN0I76fenolRUqyac/ZA51x5h
pwPxoL64Zj71SC2zagcyBzTiTiuY5yFoDAviOvVeUphpAPcTGE0Ae5Wq9mz6TrGPLwEL
GFxLG4soKPRD66eyBJGK5AW9C2UWAGEbUU4HjmN9TNb9P452T8QToekcaV7aaLLZqwAL
zuxBSQ+rKILEi+epeGwK0fEpJLdh3gu+Zb3Gi0+s8c4U40bfQ772VT5vE6HJiPlqNa7j
WwCJiXtoygps7HH9vq7mRbMjSUkTkzMWdnSIy5r77kwMBH8xHVrxyCj93k9tRIZVQGTA
l9pg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=FqECSAdXRkRoz3oE5wxTxv4wBH0ipA7AIFpO5CfA8ho=;
b=P/j03FDssAxo2bxEwAlkydqCgMF+hPMcrQrTDvnRseAD9DQF+uWQa88lZ0GKRqfS6T
xZJatKokx6btckgWT2nrdxxL3XkQ3XUXGUiJ2B20RdPXLyiZpp5ogOEXxKJXHLJqnLsg
pYzZA7KEcRA2ZB59VFgJ1zWh9yDV8Gq2UCdoP8ibjMpe1BDkcqXhJ2pi9rm/T6hhMY67
vnf0ts5npyHcUhuDh4eLd4iUXZFF4i1c0RyCUhu3bvL44mg+WM+n6sBNFpKxd3+Nnv3e
qPBSuU6bwnUPfQfHzaFaDeGYfFDkEhbsgPUK8ncLsj45rjqUeIFmATw3sEi7MWjBhwxH
qv/w==
X-Gm-Message-State: AOAM5313vQ90Y2uqVgwJBEBBf6fe8IXyXqs7vTPagyI9jAXwJRCy+/fA
PrUr2VTXejE+xnL8Py3dwRsOCGzKo/vrNVVhaediwc/D
X-Google-Smtp-Source: ABdhPJxPmIScLlMSiwMnWDyweypVQpAonIM74Ygt+SmUgea9W21YpR91urDXIBuBNpqiBO3jtzNbK8tesp377pD36tg=
X-Received: by 2002:a05:600c:489a:b0:38e:bb23:c7df with SMTP id
j26-20020a05600c489a00b0038ebb23c7dfmr3816489wmp.148.1650127610947; Sat, 16
Apr 2022 09:46:50 -0700 (PDT)
In-Reply-To: <20220416164408.zxnulyergevqprn7@hjp.at>
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: <CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
X-Mailman-Original-References: <87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
 by: Chris Angelico - Sat, 16 Apr 2022 16:46 UTC

On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer <hjp-python@hjp.at> wrote:
>
> On 2022-04-17 02:14:44 +1000, Chris Angelico wrote:
> > On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > > On the contrary. When a datetime is timezone aware, it must use that
> > > timezone's rules. Adding one day to a datetime just before a DST switch
> > > must add 23 or 25 hours, not 24. This is NOT naive.
> > >
> > > (There is an ambiguity, though: Should 2021-03-27T12:00 CEST -
> > > 2021-03-26T12:00 CET return 1 day or 25 hours? Both results are correct,
> > > and depending on context you might prefer one or the other).
> > >
> >
> > That's exactly the problem. A day IS 24 hours *and* it is the time
> > period required for you to get to the same clock on the following
> > date. It's fundamentally ambiguous.
> >
> > Let's take this out of Python altogether for a moment. Imagine that
> > it's 9AM Thursday. You say to your friend, hey, let's meet up again,
> > same time next week. Are you planning to meet 168 hours later, or at
> > 9AM the following Thursday?
> >
> > OF COURSE you mean 168 hours later. That's what "next week" means.
>
> Of course NOT. It means that only in 50 out of 52 weeks. A 4% error rate
> is more than enough to make me acutely aware that it isn't true in
> general. Also, won't count off 168 hours but look at my calendar/clock.
>
>
> > OF COURSE you're meeting at 9AM the following Thursday. That's what
> > "next week" means.
>
> This. Certainly when meeting a friend. Almost certainly when dealing
> with humans (if they are in a different time zone we may have to agree
> on a time zone for "same time"). For a technical process I *might*
> simplify "1 week" to "168 hours", but only if the spec gives me
> sufficient leeway.
>
>
> > And they can't both be true if DST is changing.
> >
> > So which one is it? Which one do you get when you add days=7 to a datetime?
>
> For adding a datetime and timedelta I think the answer is clear.
> But subtracting two datetimes is ambiguous.
>

But if the difference between two datetimes is a timedelta, then
surely adding a timedelta to a datetime should give the other
datetime? It's just as ambiguous.

ChrisA

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 19:50:52 +0200
Lines: 57
Message-ID: <mailman.132.1650131453.20749.python-list@python.org>
References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
<20220416175052.fbqkgjstjsxxhk72@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="tcefr6gdawov4ntc"
X-Trace: news.uni-berlin.de O6N+2Zjbe0lYxrlOeW87sAz5hmPBNmUvEbDJTDgBx8kQ==
Return-Path: <hjp-python@hjp.at>
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; '2022': 0.05; 'content-
type:multipart/signed': 0.05; 'subject:Why': 0.07; 'sun,': 0.07;
'angelico': 0.09; 'compute': 0.09; 'content-type:application/pgp-
signature': 0.09; 'datetime': 0.09; 'filename:fname piece:asc':
0.09; 'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'floating': 0.09;
'"creative': 0.16; '(so': 0.16; '__/': 0.16; 'challenge!"': 0.16;
'division': 0.16; 'from:addr:hjp-python': 0.16;
'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'gauge': 0.16; 'hjp@hjp.at': 0.16; 'holzer': 0.16; 'reality.':
0.16; 'stross,': 0.16; 'subject:does': 0.16; 'subject:seconds':
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; 'it?': 0.19; 'to:addr:python-list': 0.20; 'all,':
0.20; 'intend': 0.26; 'object': 0.26; 'chris': 0.28; 'sense':
0.28; 'think': 0.32; 'but': 0.32; 'header:In-Reply-To:1': 0.34;
'subject:skip:d 10': 0.35; 'change': 0.36; 'could': 0.38; 'two':
0.39; 'adding': 0.39; 'consistent': 0.40; 'something': 0.40;
'want': 0.40; 'should': 0.40; 'received:212': 0.62; 'between':
0.63; 'received:userid': 0.66; 'rate': 0.67; 'clear.': 0.69; 'url-
ip:212/8': 0.69; 'subject:have': 0.75; 'unit': 0.81;
'received:at': 0.84; 'subject:days': 0.84; 'subject:only': 0.84;
'property': 0.88
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
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: <20220416175052.fbqkgjstjsxxhk72@hjp.at>
X-Mailman-Original-References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
 by: Peter J. Holzer - Sat, 16 Apr 2022 17:50 UTC
Attachments: signature.asc (application/pgp-signature)

On 2022-04-17 02:46:38 +1000, Chris Angelico wrote:
> On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > On 2022-04-17 02:14:44 +1000, Chris Angelico wrote:
> > > So which one is it? Which one do you get when you add days=7 to a datetime?
> >
> > For adding a datetime and timedelta I think the answer is clear.
> > But subtracting two datetimes is ambiguous.
> >
>
> But if the difference between two datetimes is a timedelta, then
> surely adding a timedelta to a datetime should give the other
> datetime?

Not necessarily. You might compute the difference for another purpose.
If you compute a change rate from two gauge readings you would compute
something like (r1 - r0) / (t1 - t0). You don't intend to add (t1 - t0)
to any timestamp, so that property would be irrelevant. However, you do
want something which can be used in a division and which has a
consistent unit (so one could argue that you don't want a timedelta
object at all, but a floating point number).

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<slrnt5m45t.41c.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 18:53:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <slrnt5m45t.41c.jon+usenet@raven.unequivocal.eu>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<20220416152726.nayck4tihbzsnrk7@hjp.at>
<mailman.126.1650122848.20749.python-list@python.org>
Injection-Date: Sat, 16 Apr 2022 18:53:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5b0817d76f537876a52dc40a5b0887ce";
logging-data="20627"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+O6KcDH/2q8qr3r4UtJX5FnsW+z+PaN8k="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:V6jPugS9tSbmrWQ2Rgry5mIEoyg=
 by: Jon Ribbens - Sat, 16 Apr 2022 18:53 UTC

On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
> On 2022-04-16 13:47:32 -0000, Jon Ribbens via Python-list wrote:
>> That's impossible unless you redefine 'timedelta' from being, as it is
>> now, a fixed-length period of time, to instead being the difference
>> between two specific dates and times in specific timezones. Days and
>> months have different lengths depending on when and where you are.
>
> That's what I would have expected it to be. Otherwise, why bother with a
> class when a simple float suffices?
>
> Date arithmetic isn't simple. You need complex data types to implement
> it correctly.
>
>> >> It's an undocumented feature of timedelta that by 'day' it means '86400
>> >> seconds'.
>> >
>> > I'd call that a bug, not a feature:
>>
>> It's the only possible way of implementing it,
>
> It's definitely not the only possible way of implementing it.

It's the only possible way of implementing a fixed time period, which is
what timedelta is (modulo the bugs in 'datetime' I mentioned in my other
post).

>> > Python missed the switch to DST here, the timezone is wrong.
>>
>> Because you didn't let it use any timezone information.
>
> I used astimezone() and it returned something something that Python
> calls "timezone aware" containing time zone information which is
> correct for that time and my location
> (tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'CET')). Why
> should I expect a "timezone aware" datetime to not be actually timezone
> aware?

I think by "timezone aware" it doesn't mean "timezone aware", it means
"has a specified fixed offset from UTC". Yes this is distinctly sub-optimal.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sun, 17 Apr 2022 05:30:19 +1000
Lines: 33
Message-ID: <mailman.135.1650137433.20749.python-list@python.org>
References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
<20220416175052.fbqkgjstjsxxhk72@hjp.at>
<CAPTjJmoKg2fPgVECM+6e7m5KB+dXLkoAnuSonJE8FatLToztzA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de V6XNTw79/0SEOsV9shmBXgMSn3S+3jeJebaojF5hMt9A==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=dG3CoSRL;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05;
'subject:Why': 0.07; 'sun,': 0.07; 'angelico': 0.09; 'compute':
0.09; 'datetime': 0.09; 'floating': 0.09; 'though.': 0.09; '(so':
0.16; 'arithmetic': 0.16; 'chrisa': 0.16; 'division': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'gauge': 0.16; 'holzer': 0.16; 'logically,': 0.16; 'passed.':
0.16; 'subject:does': 0.16; 'subject:seconds': 0.16; 'wrote:':
0.16; 'it?': 0.19; 'to:addr:python-list': 0.20; 'all,': 0.20;
'intend': 0.26; 'object': 0.26; "isn't": 0.27; 'chris': 0.28;
'think': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
"i'm": 0.33; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'definitely': 0.35; 'subject:skip:d 10': 0.35; 'yes,': 0.35;
'from:addr:gmail.com': 0.35; 'change': 0.36; "it's": 0.37;
'received:209.85': 0.37; 'hard': 0.37; 'could': 0.38;
'received:209': 0.39; 'two': 0.39; 'changes': 0.39; 'adding':
0.39; 'consistent': 0.40; 'explain': 0.40; 'wants': 0.40;
'something': 0.40; 'want': 0.40; 'should': 0.40; 'between': 0.63;
'your': 0.64; 'rate': 0.67; 'that,': 0.67; 'clear.': 0.69;
'ignore': 0.71; 'subject:have': 0.75; 'unit': 0.81;
'subject:days': 0.84; 'subject:only': 0.84; 'property': 0.88
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=NA/T1PrqUZOX39J5suFF5D2kpSdDBI6a4SgT1kCuuws=;
b=dG3CoSRLiBHYX9pNBoAagxEnS/h7grwo/qDhD5TxKNiQ8sASQKeQibg47rQ857Q6zj
3uGiZ9L0DzwTKpbnlR7waqkYogUFwRCMsvLhlScEgGywB5hqQyvMwazeCqLUH4Jt0p1Z
fG8HHQ0TagGNyJtcCoNU0M2TUWLvjCmv6uzuEfKyFkqmHW61mG2D6umnaajRgjwcC7pE
1XsadyV+JTYILyy8W94igO6qJIJbjhL3b9gxCBmz1yAr1RhnmPBC4ioWzT4Kp3531GzW
VT/jW7qgBzWP0B7/fNVEILSXhEFsMxC8V+kbwtHQrlNxiMxkoVTB9NWB0cF10fc3LimE
UO7g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=NA/T1PrqUZOX39J5suFF5D2kpSdDBI6a4SgT1kCuuws=;
b=yY1krtHjREg5TiABotj+BV4TjxAgJnyn9D+Fa9hYfW3SJvxqv8YHvEtBmsPAahdLDJ
fB0wMgG1wkjQpbUa8hVjHyNmYAdVmMbJpp10+UiQt3L+DG57HsMT6zCL5HFdiyD9QLjv
8wjadDveGH3x0t7uviST4BPu0Ugvl1USvKkVG5dikP63iN+DG2+gc0My8dPFUrN6VThR
6zkSZSB2f6N42YgZVlgz19+lg2tDaMyduZbCwAm8cGCQTjOMQILrfBz0sNRVNteDUObb
VEnPtbD3VlS+4M6O5vYuKhCpfktGsKrLCTsMUU7HasrkY3xUHU74IvpH+6RCb/bNqMNz
aOvg==
X-Gm-Message-State: AOAM5324IPJeGeFTKvJGkxODNQHN281NIINoEmO7RYcb9L2LhNFxGpXs
0/McR8jEuMl59StXksS+IYA8rjbK/CsVVEe7caf6AB4s
X-Google-Smtp-Source: ABdhPJzlouCwIG4yfxha/D0lLFsYqw0Pvd3hXKclJ+HaC7g8kCuf2J4Isak31kG0I8OwO4ojl59A/2hguWT3/Jo8VsE=
X-Received: by 2002:a05:600c:19c6:b0:392:88e2:7426 with SMTP id
u6-20020a05600c19c600b0039288e27426mr4333055wmq.132.1650137430620; Sat, 16
Apr 2022 12:30:30 -0700 (PDT)
In-Reply-To: <20220416175052.fbqkgjstjsxxhk72@hjp.at>
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: <CAPTjJmoKg2fPgVECM+6e7m5KB+dXLkoAnuSonJE8FatLToztzA@mail.gmail.com>
X-Mailman-Original-References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
<20220416175052.fbqkgjstjsxxhk72@hjp.at>
 by: Chris Angelico - Sat, 16 Apr 2022 19:30 UTC

On Sun, 17 Apr 2022 at 03:52, Peter J. Holzer <hjp-python@hjp.at> wrote:
>
> On 2022-04-17 02:46:38 +1000, Chris Angelico wrote:
> > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > > On 2022-04-17 02:14:44 +1000, Chris Angelico wrote:
> > > > So which one is it? Which one do you get when you add days=7 to a datetime?
> > >
> > > For adding a datetime and timedelta I think the answer is clear.
> > > But subtracting two datetimes is ambiguous.
> > >
> >
> > But if the difference between two datetimes is a timedelta, then
> > surely adding a timedelta to a datetime should give the other
> > datetime?
>
> Not necessarily. You might compute the difference for another purpose.
> If you compute a change rate from two gauge readings you would compute
> something like (r1 - r0) / (t1 - t0). You don't intend to add (t1 - t0)
> to any timestamp, so that property would be irrelevant. However, you do
> want something which can be used in a division and which has a
> consistent unit (so one could argue that you don't want a timedelta
> object at all, but a floating point number).
>

True, but logically, it's hard to explain arithmetic when (x - y) + x
!= y. ( And yes, I'm aware that floats can violate that, but the
discrepancy isn't a good thing.)

Your example definitely wants to be measured in UTC, though. It wants
to ignore silly changes of clocks, and just show the amount of time
that passed.

ChrisA

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 21:32:24 +0200
Lines: 54
Message-ID: <mailman.136.1650137546.20749.python-list@python.org>
References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
<20220416193224.3btgzdmqs2gw7ocj@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="nst46wcx4vpytrk6"
X-Trace: news.uni-berlin.de 8rUBCc+HLgxDGk63nl+p8AEt06QwY/HEFsis2IQfX5eA==
Return-Path: <hjp-python@hjp.at>
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.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2022': 0.05; 'content-
type:multipart/signed': 0.05; 'subject:Why': 0.07; 'sun,': 0.07;
'angelico': 0.09; 'content-type:application/pgp-signature': 0.09;
'datetime': 0.09; 'filename:fname piece:asc': 0.09;
'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; '"creative': 0.16; '(when':
0.16; '__/': 0.16; 'challenge!"': 0.16; 'from:addr:hjp-python':
0.16; 'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'hjp@hjp.at': 0.16; 'holzer': 0.16; 'reality.': 0.16; 'stross,':
0.16; 'subject:does': 0.16; 'subject:seconds': 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; 'to:addr:python-list': 0.20; 'object': 0.26; 'chris': 0.28;
'sense': 0.28; 'think': 0.32; "doesn't": 0.32; 'question': 0.32;
'168': 0.32; 'extract': 0.32; 'skip:2 10': 0.32; 'but': 0.32;
'there': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'subject:skip:d 10': 0.35; "it's": 0.37; 'way': 0.38; 'two': 0.39;
'adding': 0.39; 'should': 0.40; 'skip:o 10': 0.61; 'received:212':
0.62; 'days': 0.62; 'between': 0.63; 'received:userid': 0.66;
'matter': 0.68; 'clear.': 0.69; 'url-ip:212/8': 0.69; 'addition':
0.71; 'subject:have': 0.75; 'extra': 0.84; 'points.': 0.84;
'received:at': 0.84; 'subject:days': 0.84; 'subject:only': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
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: <20220416193224.3btgzdmqs2gw7ocj@hjp.at>
X-Mailman-Original-References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
 by: Peter J. Holzer - Sat, 16 Apr 2022 19:32 UTC
Attachments: signature.asc (application/pgp-signature)

On 2022-04-17 02:46:38 +1000, Chris Angelico wrote:
> On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > For adding a datetime and timedelta I think the answer is clear.
> > But subtracting two datetimes is ambiguous.
> >
>
> But if the difference between two datetimes is a timedelta, then
> surely adding a timedelta to a datetime should give the other
> datetime? It's just as ambiguous.

To answer the same question in a different way:

No, because the timedelta object is overspecified when applied to a
specific datetime (when you start at 2022-04-16T21:29, it doesn't matter
whether you add 7 days or 168 hours) but that extra information matters
with different starting points. When you subtract two specific
datetimes, there is no way to extract that extra information. So
addition and subtraction are not symmetrical.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sun, 17 Apr 2022 06:10:47 +1000
Lines: 28
Message-ID: <mailman.138.1650139860.20749.python-list@python.org>
References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
<20220416193224.3btgzdmqs2gw7ocj@hjp.at>
<CAPTjJmpXwHi0+agP_j1RbtOZ4vY7O_90xmFG4cZWhsvwtrHx2A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de Icyi7x/5Q3hjP5B71XaKUwdYOB+j00cRKdNcEJIMrnWA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Iuvl+Aa5;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.052
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '2022': 0.05;
'subject:Why': 0.07; 'sun,': 0.07; 'angelico': 0.09; 'datetime':
0.09; '(when': 0.16; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'holzer': 0.16; 'subject:does':
0.16; 'subject:seconds': 0.16; 'wrote:': 0.16; 'to:addr:python-
list': 0.20; 'saying': 0.25; 'object': 0.26; 'chris': 0.28;
'think': 0.32; "doesn't": 0.32; 'question': 0.32; '168': 0.32;
'extract': 0.32; 'message-id:@mail.gmail.com': 0.32; 'skip:2 10':
0.32; 'but': 0.32; 'there': 0.33; 'same': 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'subject:skip:d 10':
0.35; 'from:addr:gmail.com': 0.35; "we're": 0.35; 'really': 0.37;
"it's": 0.37; 'received:209.85': 0.37; 'way': 0.38;
'received:209': 0.39; 'two': 0.39; 'adding': 0.39; 'should': 0.40;
'skip:o 10': 0.61; 'days': 0.62; 'between': 0.63; 'back': 0.67;
'away': 0.67; 'matter': 0.68; 'clear.': 0.69; 'addition': 0.71;
'subject:have': 0.75; 'extra': 0.84; 'points.': 0.84;
'subject:days': 0.84; 'subject:only': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=LYz4xZLRmIWP1SZalqimo0nI7tTHJgRuPdLpmAiOWaA=;
b=Iuvl+Aa5HCkUk1cgAV54dEQmNxsyA8umT8UlrGQVMdek+S63PlD63xztqqfqrrY0CU
iSKsbr1dVZTBV+ZmMGRtNlumFbDyhL7aFcatWbZEyDOClfuLa3vZIuzfUt/MyzCoHMpl
kvlY7hzRVpjmPWtOKdMeIKIKAXSLr3qZMYXUBGYFNrptq8IHMCEpXzdZQjLmz8/XlI6p
Do5c74y/6PcZ2AzjdyEv7Ory1O8K+z/XtzpXGWCMDZnHSP+s6ZMW6mglApqfKZCSQV72
DFZPwKZmidZhmSLe3UaXcdn9rxWmVDhjHgDmG0URTMY94/HSB7bO1BrT1WsPonOBmES1
0LHw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=LYz4xZLRmIWP1SZalqimo0nI7tTHJgRuPdLpmAiOWaA=;
b=bX/MIkz8vHKl1xfKtx98hnXhn6uvECz0ogUolZGPPlEkJ+6hbewHXEfTX53cLJOI7C
5yyNYPUuhKikOYu7u+SIwmhkDuoIiDYeVOsnOrKg56/baCiXwcF4mx6QShVQcDKNDo3L
ksWwhsyw+RjnpiKhHheI3F3fUf92fMX8p1H0jPtbiOI0GZp6pngqrFNltY3tkPY4kfgA
Ojd3BjxWYBlXph29iff4jiD/awJATI6La5eeRpXuw2QLhVrksN1ANGMt47NLYJm2nYLh
2VwMVfOvCW5DbC5Jtsc1Qw9upMpjA4ss6N5xoopXdoNHM7fiF5yPtyX3QHLue/TkSGSs
1k0g==
X-Gm-Message-State: AOAM531FN+BBLSpGxUedsqsZpdxAuTB18Guy3DZe01jSb0xpyDVuiElk
p3c8UDxT4j+9WmkQoNNjk+rCOxOKrBp8oTbBpOGZl3PY
X-Google-Smtp-Source: ABdhPJwf0npDVhva9HaljnI06jbLltObCEMhhSswX2OmeDT3bz0qC8GKZAQuXlNr1uH2TaLuGxMxQoMZKuR58B6l6oQ=
X-Received: by 2002:a7b:cbd3:0:b0:38e:bc95:5048 with SMTP id
n19-20020a7bcbd3000000b0038ebc955048mr4430173wmi.203.1650139858312; Sat, 16
Apr 2022 13:10:58 -0700 (PDT)
In-Reply-To: <20220416193224.3btgzdmqs2gw7ocj@hjp.at>
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: <CAPTjJmpXwHi0+agP_j1RbtOZ4vY7O_90xmFG4cZWhsvwtrHx2A@mail.gmail.com>
X-Mailman-Original-References: <mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<CAPTjJmomBW2dcrrtznqQRzz024yUSEJdrbdK7UD8_WYE3WUYnw@mail.gmail.com>
<20220416164408.zxnulyergevqprn7@hjp.at>
<CAPTjJmrTd6GigU5p+k8YiFPQu9OpMOhDOdtf4=UMy23MEJPKVA@mail.gmail.com>
<20220416193224.3btgzdmqs2gw7ocj@hjp.at>
 by: Chris Angelico - Sat, 16 Apr 2022 20:10 UTC

On Sun, 17 Apr 2022 at 05:38, Peter J. Holzer <hjp-python@hjp.at> wrote:
>
> On 2022-04-17 02:46:38 +1000, Chris Angelico wrote:
> > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer <hjp-python@hjp.at> wrote:
> > > For adding a datetime and timedelta I think the answer is clear.
> > > But subtracting two datetimes is ambiguous.
> > >
> >
> > But if the difference between two datetimes is a timedelta, then
> > surely adding a timedelta to a datetime should give the other
> > datetime? It's just as ambiguous.
>
> To answer the same question in a different way:
>
> No, because the timedelta object is overspecified when applied to a
> specific datetime (when you start at 2022-04-16T21:29, it doesn't matter
> whether you add 7 days or 168 hours) but that extra information matters
> with different starting points. When you subtract two specific
> datetimes, there is no way to extract that extra information. So
> addition and subtraction are not symmetrical.
>

Ah, that's fair. So what you're really saying is that the difference
between two datetimes *isn't* a timedelta, but when we subtract them
and get back a timedelta, we're throwing away information for
simplicity.

ChrisA

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<slrnt5ma4a.41c.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and
'seconds'?
Date: Sat, 16 Apr 2022 20:35:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 115
Message-ID: <slrnt5ma4a.41c.jon+usenet@raven.unequivocal.eu>
References: <87ilrbdbzi.fsf@hornfels.zedat.fu-berlin.de>
<87ee1zdbuh.fsf@hornfels.zedat.fu-berlin.de>
<0b6be8d41b466ddd60787ddaecd26d063e961fc0.camel@anode.ca>
<mailman.87.1649948491.20749.python-list@python.org>
<slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu>
<20220416084411.kkfjtz2bjl5wqo5o@hjp.at>
<mailman.123.1650098653.20749.python-list@python.org>
<slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu>
<slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu>
<20220416160028.tmedahn64gdpzsov@hjp.at>
<mailman.127.1650124831.20749.python-list@python.org>
Injection-Date: Sat, 16 Apr 2022 20:35:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5b0817d76f537876a52dc40a5b0887ce";
logging-data="5233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nfuDaUd819Des0yX/yPS+Ovau2Rd2b9M="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:qcI9+grna6Vic+11Ua7gBOUZsRY=
 by: Jon Ribbens - Sat, 16 Apr 2022 20:35 UTC

On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
> On 2022-04-16 14:22:04 -0000, Jon Ribbens via Python-list wrote:
>> On 2022-04-16, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
>> > On 2022-04-16, Peter J. Holzer <hjp-python@hjp.at> wrote:
>> >> Python missed the switch to DST here, the timezone is wrong.
>> >
>> > Because you didn't let it use any timezone information. You need to
>> > either use the third-party 'pytz' module, or in Python 3.9 or above,
>> > the built-in 'zoneinfo' module.
>>
>> ... although now having looked into the new 'zoneinfo' module slightly,
>> it really should have a giant red flashing notice at the top of it
>> saying "BEWARE, TIMEZONES IN PYTHON ARE UTTERLY BROKEN, NEVER USE THEM".
>>
>> Suppose we do this:
>>
>> >>> import datetime, zoneinfo
>> >>> LOS_ANGELES = zoneinfo.ZoneInfo('America/Los_Angeles')
>> >>> UTC = zoneinfo.ZoneInfo('UTC')
>> >>> d = datetime.datetime(2020, 10, 31, 12, tzinfo=LOS_ANGELES)
>> >>> print(d)
>> 2020-10-31 12:00:00-07:00
>> >>> d1 = d + datetime.timedelta(days=1)
>> >>> print(d1)
>> 2020-11-01 12:00:00-08:00
>>
>> d1 is *wrong*.
>
> No, this is correct. That's the result you want.

I can categorically guarantee you it is not. But let's put it a
different way, if you like, if I want to add 24 hours, i.e. 86,400
seconds (or indeed any other fixed time period), to a timezone-aware
datetime in Python, how do I do it? It would appear that, without
converting to UTC before doing the calculation, you can't.

> So why didn't this work for me (I also used Python 3.9)? My guess is
> that astimezone() doesn't pick the correct time zone.

astimezone() doesn't pick a time zone at all. It works out the current
local offset from UTC. It doesn't know anything about when or if that
offset ever changes.

>> timedelta(days=1) is 24 hours (as you can check by
>> calling timedelta(days=1).total_seconds() ),
>
> It shouldn't be. 1 Day is not 24 hours in the real world.

Nevertheless, timedelta is a fixed time period so that is the only
definition possible.

>> then it can pretend timezones don't exist and do 'naive' arithmetic.
>
> On the contrary. When a datetime is timezone aware, it must use that
> timezone's rules. Adding one day to a datetime just before a DST switch
> must add 23 or 25 hours, not 24. This is NOT naive.

But it is. It's adding 24 hours and while it's doing so it's naively
assuming that the UTC offset doesn't change during that period. Then
once it's got that naive result it's labelling it with what it thinks
is the timezone data at that time.

Here's another example to prove the point:

>>> LONDON = zoneinfo.ZoneInfo('Europe/London')
>>> d0 = datetime.datetime(2022, 3, 27, 0, tzinfo=LONDON)
>>> print(d0)
2022-03-27 00:00:00+00:00
>>> print(d0 + datetime.timedelta(seconds=3600+1800))
2022-03-27 01:30:00+00:00

That is impossible - 2022-03-27 01:30 is a time that *doesn't exist*
in the Europe/London timezone. At 01:00 the clocks moved instantly
to 02:00 as daylight savings kicked in. So the following is wrong too:

>>> print(d0 + datetime.timedelta(seconds=3600*2))
2022-03-27 02:00:00+01:00

That's not 2 hours after midnight, that's 1 hour after midnight.

Doing the calculations in UTC works of course:

>>> print((d0.astimezone(UTC) + datetime.timedelta(seconds=3600+1800)).astimezone(LONDON))
2022-03-27 02:30:00+01:00
>>> print((d0.astimezone(UTC) + datetime.timedelta(seconds=3600*2)).astimezone(LONDON))
2022-03-27 03:00:00+01:00

> (There is an ambiguity, though: Should 2021-03-27T12:00 CEST -
> 2021-03-26T12:00 CET return 1 day or 25 hours? Both results are correct,
> and depending on context you might prefer one or the other).

But if you're returning that result as a timedelta then only "25 hours"
is correct (or indeed "1 day 3,600 seconds"), because for a timedelta a
day is 24 hours *by definition*.

>> There is a general guideline that you should always keep and use your
>> datetimes as UTC, only ever using timezones for the purposes of display.
>> Usually this is because it keeps things simpler for the programmer, and
>> hence they are less likely to introduce bugs into their programs.
>
> While I generally do this (and often preach it to my collegues) it must
> be stated that this is only a GENERAL guide line.

Yes, that's what I just said.

>> It appears that with Python it's not so much a guideline as an
>> absolute concrete rule, and not because programmers will introduce
>> bugs, but because you need to avoid bugs in the standard library!
>
> As a programmer you must always adapt to the problem. Saying "I must do
> it the wrong way because my library is buggy" is just lazy.

I didn't say any of that. I said you must do it the conservative way,
and it's not "my library" that's buggy, it's the language's built-in
*standard library* that's buggy.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

<rtfm5hlf446gq0m1o67htu0v5i09r3532t@4ax.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 16 Apr 2022 17:22:32 -0500
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?
Date: Sat, 16 Apr 2022 18:22:31 -0400
Organization: IISS Elusive Unicorn
Message-ID: <rtfm5hlf446gq0m1o67htu0v5i09r3532t@4ax.com>
References: <mailman.87.1649948491.20749.python-list@python.org> <slrnt5gf1l.41c.jon+usenet@raven.unequivocal.eu> <20220416084411.kkfjtz2bjl5wqo5o@hjp.at> <mailman.123.1650098653.20749.python-list@python.org> <slrnt5li7k.41c.jon+usenet@raven.unequivocal.eu> <slrnt5lk8c.41c.jon+usenet@raven.unequivocal.eu> <20220416160028.tmedahn64gdpzsov@hjp.at> <mailman.127.1650124831.20749.python-list@python.org> <slrnt5ma4a.41c.jon+usenet@raven.unequivocal.eu>
User-Agent: ForteAgent/8.00.32.1272
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 28
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-kgsfRKz7IDFNgghnA+8rJM01ssXBKIs4UPp1WaBigp1oTGrxNiG2Wz7T+2KpHJr3FAV9SEnePSj7zLM!ZUHd3xB7vyS2V2Y/iLRuS4u2ANbOqd1CHmVa8if6wXSkmKvJccetD9vZf+ZcOikkxTvMZsyj
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2895
 by: Dennis Lee Bieber - Sat, 16 Apr 2022 22:22 UTC

On Sat, 16 Apr 2022 20:35:22 -0000 (UTC), Jon Ribbens
<jon+usenet@unequivocal.eu> declaimed the following:

>I can categorically guarantee you it is not. But let's put it a
>different way, if you like, if I want to add 24 hours, i.e. 86,400
>seconds (or indeed any other fixed time period), to a timezone-aware
>datetime in Python, how do I do it? It would appear that, without
>converting to UTC before doing the calculation, you can't.
>

Which is probably the recommended means to do just that. UTC is an
international standard (call it a zero-reference). All other time-zones
(and daylight savings time) tend to be local/civil time entities (even if
widely accepted), subject to change by whim of the government (consider,
just in the US alone, there are some states, or even parts of states, that
do not honor the DST change over [I really don't know how my watch would
handle some of those, since it time-syncs with WWV-B, including shifting to
DST when WWV-B includes the flag in its broadcast]). And proposals to make
DST permanent year round -- so "noon" (1200hrs) is not "noon" (sun at
zenith) pretty much anywhere.

The only thing that is most noticeable about UTC is the incorporation
of leap-seconds.

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor