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

2022-04-20 Thread Loris Bennett
Dennis Lee Bieber writes: > On Tue, 19 Apr 2022 15:51:09 +0200, "Loris Bennett" > declaimed the following: > >>If I am merely trying to represent part a very large number of seconds >>as a number of years, 365 days per year does not seem that controversial > > The Explanatory Supplement

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

2022-04-20 Thread Loris Bennett
Random832 writes: > On Tue, Apr 19, 2022, at 07:11, Loris Bennett wrote: >> I now realise that timedelta is not really what I need. I am >> interested solely in pure periods, i.e. numbers of seconds, that I >> can convert back and forth from a format such as > > A timedelta *is* a pure period.

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

2022-04-19 Thread Random832
On Tue, Apr 19, 2022, at 07:11, Loris Bennett wrote: > I now realise that timedelta is not really what I need. I am interested > solely in pure periods, i.e. numbers of seconds, that I can convert back > and forth from a format such as A timedelta *is* a pure period. A timedelta of one day is

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

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Barry wrote: >> On 19 Apr 2022, at 19:38, Dennis Lee Bieber wrote: >> *I /think/ this is the year used for leap-day calculations, and >> why some leap centuries are skipped as it is really less than a >> quarter day per year, so eventually one gets to over-correcting

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

2022-04-19 Thread Barry
> On 19 Apr 2022, at 19:38, Dennis Lee Bieber wrote: > > *I /think/ this is the year used for leap-day calculations, and why some > leap centuries are skipped as it is really less than a quarter day per > year, so eventually one gets to over-correcting by a day. Leap century is skip

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

2022-04-19 Thread MRAB
On 2022-04-19 19:23, Dennis Lee Bieber wrote: On Tue, 19 Apr 2022 15:51:09 +0200, "Loris Bennett" declaimed the following: If I am merely trying to represent part a very large number of seconds as a number of years, 365 days per year does not seem that controversial The Explanatory

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

2022-04-19 Thread Dennis Lee Bieber
On Tue, 19 Apr 2022 15:51:09 +0200, "Loris Bennett" declaimed the following: >If I am merely trying to represent part a very large number of seconds >as a number of years, 365 days per year does not seem that controversial The Explanatory Supplement to the Astronomical Almanac (table

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

2022-04-19 Thread Chris Angelico
On Wed, 20 Apr 2022 at 02:16, Loris Bennett wrote: > I now realise that timedelta is not really what I need. I am interested > solely in pure periods, i.e. numbers of seconds, that I can convert back > and forth from a format such as > > 11-22::44:55 > > (These are the lengths of time a job

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

2022-04-19 Thread Loris Bennett
Jon Ribbens writes: > On 2022-04-19, Loris Bennett wrote: >> If I am merely trying to represent part a very large number of seconds >> as a number of years, 365 days per year does not seem that controversial >> to me. Obviously there are issues if you expect all periods of an >> integer number

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

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > If I am merely trying to represent part a very large number of seconds > as a number of years, 365 days per year does not seem that controversial > to me. Obviously there are issues if you expect all periods of an > integer number of years which start on a

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

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > Jon Ribbens writes: >> On 2022-04-19, Loris Bennett wrote: >>> I now realise that timedelta is not really what I need. I am interested >>> solely in pure periods, i.e. numbers of seconds, >> >> That's exactly what timedelta is. >> >>> that I can convert

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

2022-04-19 Thread Loris Bennett
Jon Ribbens writes: > On 2022-04-19, Loris Bennett wrote: >> I now realise that timedelta is not really what I need. I am interested >> solely in pure periods, i.e. numbers of seconds, > > That's exactly what timedelta is. > >> that I can convert back and forth from a format such as >> >>

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

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > I now realise that timedelta is not really what I need. I am interested > solely in pure periods, i.e. numbers of seconds, That's exactly what timedelta is. > that I can convert back and forth from a format such as > > 11-22::44:55 I don't recognise

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

2022-04-19 Thread Loris Bennett
Jon Ribbens writes: > On 2022-04-19, Loris Bennett wrote: >> Jon Ribbens writes: >>> On 2022-04-19, Loris Bennett wrote: I now realise that timedelta is not really what I need. I am interested solely in pure periods, i.e. numbers of seconds, >>> >>> That's exactly what timedelta

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

2022-04-19 Thread Loris Bennett
"Peter J. Holzer" writes: > On 2022-04-16 20:35:22 -, Jon Ribbens via Python-list wrote: >> On 2022-04-16, Peter J. Holzer wrote: >> > On 2022-04-16 14:22:04 -, Jon Ribbens via Python-list wrote: >> >> ... although now having looked into the new 'zoneinfo' module slightly, >> >> it

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

2022-04-17 Thread Peter J. Holzer
On 2022-04-16 20:35:22 -, Jon Ribbens via Python-list wrote: > On 2022-04-16, Peter J. Holzer wrote: > > On 2022-04-16 14:22:04 -, Jon Ribbens via Python-list wrote: > >> ... although now having looked into the new 'zoneinfo' module slightly, > >> it really should have a giant red

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

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Dennis Lee Bieber wrote: > On Sat, 16 Apr 2022 20:35:22 - (UTC), Jon Ribbens > 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

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 08:37, Dennis Lee Bieber wrote: > And proposals to make > DST permanent year round -- so "noon" (1200hrs) is not "noon" (sun at > zenith) pretty much anywhere. > Noon isn't precisely zenith anyway, for several reasons: 1) Time zones synchronize their clocks on the mean

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

2022-04-16 Thread Dennis Lee Bieber
On Sat, 16 Apr 2022 20:35:22 - (UTC), Jon Ribbens 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

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

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Peter J. Holzer wrote: > On 2022-04-16 14:22:04 -, Jon Ribbens via Python-list wrote: >> On 2022-04-16, Jon Ribbens wrote: >> > On 2022-04-16, Peter J. Holzer wrote: >> >> Python missed the switch to DST here, the timezone is wrong. >> > >> > Because you didn't let it use any

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 05:38, Peter J. Holzer wrote: > > On 2022-04-17 02:46:38 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer wrote: > > > For adding a datetime and timedelta I think the answer is clear. > > > But subtracting two datetimes is ambiguous. > > > > >

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

2022-04-16 Thread Peter J. Holzer
On 2022-04-17 02:46:38 +1000, Chris Angelico wrote: > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer 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

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

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Peter J. Holzer wrote: > On 2022-04-16 13:47:32 -, 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

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 03:52, Peter J. Holzer wrote: > > On 2022-04-17 02:46:38 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer 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

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

2022-04-16 Thread Peter J. Holzer
On 2022-04-17 02:46:38 +1000, Chris Angelico wrote: > On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer 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

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 02:45, Peter J. Holzer wrote: > > On 2022-04-17 02:14:44 +1000, Chris Angelico wrote: > > On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer wrote: > > > On the contrary. When a datetime is timezone aware, it must use that > > > timezone's rules. Adding one day to a datetime

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

2022-04-16 Thread Peter J. Holzer
On 2022-04-17 02:14:44 +1000, Chris Angelico wrote: > On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer 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

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

2022-04-16 Thread Chris Angelico
On Sun, 17 Apr 2022 at 02:03, Peter J. Holzer wrote: > > On 2022-04-16 14:22:04 -, 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

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

2022-04-16 Thread Peter J. Holzer
On 2022-04-16 14:22:04 -, Jon Ribbens via Python-list wrote: > On 2022-04-16, Jon Ribbens wrote: > > On 2022-04-16, Peter J. Holzer 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

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

2022-04-16 Thread Peter J. Holzer
On 2022-04-16 13:47:32 -, Jon Ribbens via Python-list wrote: > On 2022-04-16, Peter J. Holzer wrote: > > On 2022-04-14 15:22:29 -, Jon Ribbens via Python-list wrote: > >> On 2022-04-14, Paul Bryan wrote: > >> > I think because minutes and hours can easily be composed by multiplying > >>

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

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Jon Ribbens wrote: > On 2022-04-16, Peter J. Holzer 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

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

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Peter J. Holzer wrote: > On 2022-04-14 15:22:29 -, Jon Ribbens via Python-list wrote: >> On 2022-04-14, Paul Bryan wrote: >> > I think because minutes and hours can easily be composed by multiplying >> > seconds. days is separate because you cannot compose days from seconds;

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

2022-04-16 Thread Peter J. Holzer
On 2022-04-14 15:22:29 -, Jon Ribbens via Python-list wrote: > On 2022-04-14, Paul Bryan 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

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

2022-04-14 Thread Jon Ribbens via Python-list
On 2022-04-14, MRAB wrote: > On 2022-04-14 16:22, Jon Ribbens via Python-list wrote: >> On 2022-04-14, Paul Bryan 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

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

2022-04-14 Thread Chris Angelico
On Fri, 15 Apr 2022 at 00:54, Loris Bennett 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 >

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

2022-04-14 Thread Chris Angelico
On Fri, 15 Apr 2022 at 03:45, Marco Sulla wrote: > > On Thu, 14 Apr 2022 at 19:16, MRAB 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

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

2022-04-14 Thread Marco Sulla
On Thu, 14 Apr 2022 at 19:16, MRAB 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

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

2022-04-14 Thread MRAB
On 2022-04-14 16:22, Jon Ribbens via Python-list wrote: On 2022-04-14, Paul Bryan 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

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

2022-04-14 Thread Jon Ribbens via Python-list
On 2022-04-14, Paul Bryan 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

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

2022-04-14 Thread Lars Liedtke
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

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

2022-04-14 Thread 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:

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

2022-04-14 Thread Loris Bennett
"Loris Bennett" 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

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

2022-04-14 Thread Loris Bennett
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: