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 to

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
t; et.normalize(et.localize(datetime.datetime(2022,3,12,12,0,0)) + >>> datetime.timedelta(days=1)) datetime.datetime(2022, 3, 13, 13, 0, tzinfo=) you can see here that 2022-03-12T12:00-0500 + timedelta(days=1) correctly becomes 2022-03-13T13:00-0400, 24 hours later. As far as I know, Python doesn&#x

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 unless

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 S

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 15.

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 has

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 gi

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 bac

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 >> >> 11-

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 that

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 is.

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

2022-04-19 Thread Loris Bennett
> >> >> >> >>> import datetime, zoneinfo >> >> >>> LOS_ANGELES = zoneinfo.ZoneInfo('America/Los_Angeles') >> >> >>> UTC = zoneinfo.ZoneInfo('UTC') >> >> >>> d = datetime.datetime(2020, 1

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

2022-04-17 Thread Peter J. Holzer
;> >>> LOS_ANGELES = zoneinfo.ZoneInfo('America/Los_Angeles') > >> >>> UTC = zoneinfo.ZoneInfo('UTC') > >> >>> d = datetime.datetime(2020, 10, 31, 12, tzinfo=LOS_ANGELES) > >> >>> print(d) > >> 20

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 tim

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 noo

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 Py

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

2022-04-16 Thread Jon Ribbens via Python-list
, zoneinfo >> >>> LOS_ANGELES = zoneinfo.ZoneInfo('America/Los_Angeles') >> >>> UTC = zoneinfo.ZoneInfo('UTC') >> >>> d = datetime.datetime(2020, 10, 31, 12, tzinfo=LOS_ANGELES) >> >>> print(d) >> 20

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
er 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 zo

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 a

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 jus

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
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)) > >

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

2022-04-16 Thread Peter J. Holzer
gt;>> 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) >

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

2022-04-16 Thread Peter J. Holzer
> > > 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, to

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

2022-04-16 Thread Jon Ribbens via Python-list
HEM". 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) >>> pri

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

2022-04-16 Thread Jon Ribbens via Python-list
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, &g

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

2022-04-16 Thread Peter J. Holzer
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() >>>

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 app

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, minu

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 delta

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 irre

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 argu

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

2022-04-14 Thread Lars Liedtke
in the Earth's rotation. On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote: "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.timedelt

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

2022-04-14 Thread Paul Bryan
wrote: > "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.t

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, > se

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.minu

Re: Datetime.timedelta

2011-05-17 Thread Gabriel Genellina
En Tue, 17 May 2011 07:44:08 -0300, Tsolmon Narantsogt escribió: I'm using datetime.timedelta and i have a problem delta = 1 day, 2:30:00 hours = delta.days * 8 how to add 8 + 2:30:00 Just operate with it as it were a number. The timedelta class implements all "sane&quo

Datetime.timedelta

2011-05-17 Thread Tsolmon Narantsogt
Hi list I'm using datetime.timedelta and i have a problem delta = 1 day, 2:30:00 hours = delta.days * 8 how to add 8 + 2:30:00 Regards Tsolmon. -- http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class

2011-05-15 Thread Jorge Romero
On Sun, May 15, 2011 at 11:50 PM, Chris Angelico wrote: > On Mon, May 16, 2011 at 10:42 AM, Jorge Romero > wrote: > > Hi Pythonists, > > I'm retrieving some time data from a MySQL database using Python's > MySQLdb > > library. Here's the situation, I got a time field on MySQL given in > seconds,

Re: MySQLdb SEC_TO_TIME function returns datetime.timedelta class

2011-05-15 Thread Chris Angelico
On Mon, May 16, 2011 at 10:42 AM, Jorge Romero wrote: > Hi Pythonists, > I'm retrieving some time data from a MySQL database using Python's MySQLdb > library. Here's the situation, I got a time field on MySQL given in seconds, > I need it on HH:MM:SS format, so I'm SELECTING that field with SEC_TO

MySQLdb SEC_TO_TIME function returns datetime.timedelta class

2011-05-15 Thread Jorge Romero
is: query = "SELECT SEC_TO_TIME(SUM(seconds)) FROM table" fetched = cursor.execute(query) return fetched[0] The result of the query is given to me as *datetime.timedelta *type, which has an undesired print behavior for my purposes: >>> query = "SELECT SEC_TO_TIME(SUM(seconds)) FR

Re: datetime.timedelta division confusion

2007-09-01 Thread Skip Montanaro
> Try d // 2 ? > It may be that v2.6 considers / as __truediv__ and not __div__. Ah, right you are. Thanks... Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime.timedelta division confusion

2007-09-01 Thread Arnaud Delobelle
On Sep 1, 7:28 pm, [EMAIL PROTECTED] wrote: > Running from Subversion, I see confusing (to me) behavior related to > division of datetime.timedelta objects by integers: > > % python > Python 2.6a0 (trunk:57277:57280M, Aug 28 2007, 17:44:49) > [GCC 4.0.1 (Apple Compute

datetime.timedelta division confusion

2007-09-01 Thread skip
Running from Subversion, I see confusing (to me) behavior related to division of datetime.timedelta objects by integers: % python Python 2.6a0 (trunk:57277:57280M, Aug 28 2007, 17:44:49) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyr

Re: How to get hours and minutes from 'datetime.timedelta' object?

2006-08-07 Thread John Machin
Ant wrote: > John Machin wrote: > ... > > 1. If that's what he wanted, it was a very peculiar way of asking. Do > > you suspect that he needs to be shown how to conver 877.7... minutes > > into hours, minutes and seconds??? > > Chill dude, It wasn't an attack :-) I didn't think it was. > > The d

Re: How to get hours and minutes from 'datetime.timedelta' object?

2006-08-07 Thread Ant
John Machin wrote: ... > 1. If that's what he wanted, it was a very peculiar way of asking. Do > you suspect that he needs to be shown how to conver 877.7... minutes > into hours, minutes and seconds??? Chill dude, It wasn't an attack :-) The datetime class has hour, minute and second attributes

Re: How to get hours and minutes from 'datetime.timedelta' object?

2006-08-07 Thread John Machin
Ant wrote: > John Machin wrote: > > Lad wrote: > > > Hello, > > > what is the best /easest way how to get number of hours and minutes > > > from a timedelta object? > ... > > >>> diff.days > > 0 > > >>> diff.seconds > > 52662 > > >>> diff.microseconds > > 922000 > > >>> minutes = (diff.seconds +

Re: How to get hours and minutes from 'datetime.timedelta' object?

2006-08-07 Thread Ant
John Machin wrote: > Lad wrote: > > Hello, > > what is the best /easest way how to get number of hours and minutes > > from a timedelta object? ... > >>> diff.days > 0 > >>> diff.seconds > 52662 > >>> diff.microseconds > 922000 > >>> minutes = (diff.seconds + diff.microseconds / 100.0) / 60.0

Re: How to get hours and minutes from 'datetime.timedelta' object?

2006-08-07 Thread John Machin
Lad wrote: > Hello, > what is the best /easest way how to get number of hours and minutes > from a timedelta object? > Let's say we have > aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000) > bb=datetime.datetime(2006, 8, 3, 17, 59, 36, 46000) > so > c=bb-aa >

How to get hours and minutes from 'datetime.timedelta' object?

2006-08-07 Thread Lad
Hello, what is the best /easest way how to get number of hours and minutes from a timedelta object? Let's say we have aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000) bb=datetime.datetime(2006, 8, 3, 17, 59, 36, 46000) so c=bb-aa will be datetime.timedelta(5, 6339, 437000) I can easil