Re: Subtract n months from datetime

2022-06-27 Thread Peter J. Holzer
On 2022-06-21 05:29:52 +0100, Paulo da Silva wrote: > I implemented a part of a script to subtract n months from datetime. > Basically I subtracted n%12 from year and n//12 from the month adding 12 > months when it goes<=0. Then used try when converting to datetime again. So, > if

Aw: Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Karsten Hilbert
> What makes sense depends on where you're looking from. > > It's 28 February, you need to keep it for 5 years, therefore you could > reason that you can dispose of it on 28 February, 5 years hence. > > However, that happens to be a leap year. > > Should you still have it on 29 February? Nope beca

Re: Subtract n months from datetime

2022-06-22 Thread Paulo da Silva
Às 19:47 de 22/06/22, Marco Sulla escreveu: The package arrow has a simple shift method for months, weeks etc https://arrow.readthedocs.io/en/latest/#replace-shift At first look it seems pretty good! I didn't know it. Thank you Marco. Paulo -- https://mail.python.org/mailman/listinfo/python-l

Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Paulo da Silva
Às 20:25 de 22/06/22, Barry Scott escreveu: On 22 Jun 2022, at 17:59, Paulo da Silva wrote: Às 05:29 de 21/06/22, Paulo da Silva escreveu: As a general response to some comments ... Suppose we need to delete records from a database older than ... Today, it's usual to specify days. For exa

Re: Subtract n months from datetime [Why?]

2022-06-22 Thread MRAB
On 2022-06-22 20:25, Barry Scott wrote: On 22 Jun 2022, at 17:59, Paulo da Silva wrote: Às 05:29 de 21/06/22, Paulo da Silva escreveu: As a general response to some comments ... Suppose we need to delete records from a database older than ... Today, it's usual to specify days. For example

Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Barry Scott
> On 22 Jun 2022, at 17:59, Paulo da Silva > wrote: > > Às 05:29 de 21/06/22, Paulo da Silva escreveu: > > As a general response to some comments ... > > Suppose we need to delete records from a database older than ... > Today, it's usual to specify days. For example you have to keep some go

Re: Subtract n months from datetime

2022-06-22 Thread Marco Sulla
The package arrow has a simple shift method for months, weeks etc https://arrow.readthedocs.io/en/latest/#replace-shift -- https://mail.python.org/mailman/listinfo/python-list

Re: Subtract n months from datetime [Why?]

2022-06-22 Thread MRAB
On 2022-06-22 17:59, Paulo da Silva wrote: Às 05:29 de 21/06/22, Paulo da Silva escreveu: As a general response to some comments ... Suppose we need to delete records from a database older than ... Today, it's usual to specify days. For example you have to keep some gov papers for 90 days. This

Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Paulo da Silva
Às 05:29 de 21/06/22, Paulo da Silva escreveu: As a general response to some comments ... Suppose we need to delete records from a database older than ... Today, it's usual to specify days. For example you have to keep some gov papers for 90 days. This seems to come from computers era. In our m

Re: Subtract n months from datetime

2022-06-21 Thread Cameron Simpson
On 21Jun2022 17:02, Paulo da Silva wrote: >I have a datetime, not a date. Then you need a date. I would break the datetime into a date and a time, then do the months stuff to the date, then compose a new datetime from the result. >Anyway, the use of calendar.monthrange simplifies the

Re: Subtract n months from datetime

2022-06-21 Thread Paulo da Silva
month = (value.month - 1 + n) % 12 + 1   day = min(value.day, calendar.monthrange(year, month)[1])   return date(year, month, day) Paul I have a datetime, not a date. Anyway, the use of calendar.monthrange simplifies the task a lot. Assuming dtnow has the current datetime and dtn the number of m

Re: Subtract n months from datetime

2022-06-21 Thread Dan Stromberg
On Mon, Jun 20, 2022 at 9:45 PM Paul Bryan wrote: > Here's how my code does it: > > > import calendar > > def add_months(value: date, n: int): > """Return a date value with n months added (or subtracted if > negative).""" > year = value.year + (value.month - 1 + n) // 12 > month = (value.mo

Re: Subtract n months from datetime

2022-06-21 Thread Richard Damon
On 6/21/22 12:29 AM, Paulo da Silva wrote: Hi! I implemented a part of a script to subtract n months from datetime. Basically I subtracted n%12 from year and n//12 from the month adding 12 months when it goes<=0. Then used try when converting to datetime again. So, if the day is for exam

Re: Subtract n months from datetime

2022-06-20 Thread Paul Bryan
min(value.day, calendar.monthrange(year, month)[1])   return date(year, month, day) Paul On Tue, 2022-06-21 at 05:29 +0100, Paulo da Silva wrote: > Hi! > > I implemented a part of a script to subtract n months from datetime. > Basically I subtracted n%12 from year and n//12 from the mo

Subtract n months from datetime

2022-06-20 Thread Paulo da Silva
Hi! I implemented a part of a script to subtract n months from datetime. Basically I subtracted n%12 from year and n//12 from the month adding 12 months when it goes<=0. Then used try when converting to datetime again. So, if the day is for example 31 for a 30 days month it raises a ValuEr

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cameron Simpson
h a nightmare, and programmes working with datetime as their primary structure are fragile (hmm, is this _naive_ (untimezoned) datetime in local time? What _is_ local time? Was the naive datetime obtained correctly? etc). Hence the common recommendation to work in seconds since an epoch (on U

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread sjeik_appie
On 16 Oct 2020 12:50, Eryk Sun wrote: On 10/16/20, Steve wrote: > -Original Message- > From: Python-list On > Behalf Of Frank Millman > Sent: Friday, October 16, 2020 4:34 AM > To: python-list@python.org > Subject: Re: How do

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cousin Stanley
psychology, to they cancel > each other out? > > -- py> py> import datetime as dt py> py> d = dt.datetime.now().strftime( '%Y-%m-%d %H:%M' ) py> py> print( '\n ' , d ) 2020-10-16 07:22 -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Eryk Sun
On 10/16/20, Steve wrote: > -Original Message- > From: Python-list On > Behalf Of Frank Millman > Sent: Friday, October 16, 2020 4:34 AM > To: python-list@python.org > Subject: Re: How do I get datetime to stop showing seconds? > > On 2020-10-16 9:4

RE: How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
Right on target, Many Thanks FootNote: If money does not grow on trees, then why do banks have branches? -Original Message- From: Python-list On Behalf Of Frank Millman Sent: Friday, October 16, 2020 4:34 AM To: python-list@python.org Subject: Re: How do I get datetime to stop

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Marco Sulla
Another way is: '{:%Y-%m-%d %H:%M}'.format(d2) -- https://mail.python.org/mailman/listinfo/python-list

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Frank Millman
On 2020-10-16 9:42 AM, Steve wrote: d2 = datetime.datetime.now() #Time Right now Show this: 2020-10-16 02:53 and not this: 2020-10-16 02:53:48.585865 >>> >>> str(d2) '2020-10-16 10:29:38.423371' >>> >>> d2.strftime('%Y-%m-%d %H:%M') '2020-10-16 10:29' >>> Frank Millman -- https://mail.pyt

How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
d2 = datetime.datetime.now() #Time Right now Show this: 2020-10-16 02:53 and not this: 2020-10-16 02:53:48.585865 == Footnote: If you double major in psychology and reverse psychology, to they cancel each other out? -- -- https://m

Re: What might cause my sample program to forget that already imported datetime?

2020-10-13 Thread Chris Angelico
r just import the objects that you need; > > from datetime import datetime, SYMBOL, etc... > > I use Decimal a lot. I would hate to have to write "decimal.Decimal(str)" > for example. > > Whichever method you use the most important thing is to be consistent as > much as

Re: What might cause my sample program to forget that already imported datetime?

2020-10-13 Thread D'Arcy Cain
On 10/12/20 7:20 AM, Chris Angelico wrote: > This is yet another reason that "from MODULE import *" is a bad idea. > Instead, just import the module itself, and take whatever you need. Or just import the objects that you need; from datetime import datetime, SYMBOL, etc... I u

Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread dn via Python-list
On 13/10/2020 06:47, Steve wrote: Thank you, those two fixes took care of the problem. At the top of my sample program, I have: import datetime from datetime import * ... These are incompatible with each other, so you're going to get issues. I'd recommend doing just the first one

RE: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Steve
: Re: What might cause my sample program to forget that already imported datetime? On Mon, Oct 12, 2020 at 9:14 PM Steve wrote: > > At the top of my sample program, I have: > > import datetime > from datetime import * > > But import datetime also has to be entered on line 21 a

Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Richard Damon
On 10/12/20 7:20 AM, Chris Angelico wrote: > On Mon, Oct 12, 2020 at 9:58 PM Abdur-Rahmaan Janhangeer > wrote: >> Btw why a datetime in datetime? >> >> It causes much confusion. I dont know >> the design decision behind, if someone knows, it might be good to expl

Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Chris Angelico
On Mon, Oct 12, 2020 at 9:58 PM Abdur-Rahmaan Janhangeer wrote: > > Btw why a datetime in datetime? > > It causes much confusion. I dont know > the design decision behind, if someone knows, it might be good to explain > There are quite a few modules that have one "most o

Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Abdur-Rahmaan Janhangeer
Btw why a datetime in datetime? It causes much confusion. I dont know the design decision behind, if someone knows, it might be good to explain I dont expect it to change anytime soon due to backward compatibility, but just for knowledge. Kind Regards, Abdur-Rahmaan Janhangeer https

Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Chris Angelico
On Mon, Oct 12, 2020 at 9:14 PM Steve wrote: > > At the top of my sample program, I have: > > import datetime > from datetime import * > > But import datetime also has to be entered on line 21 as shown. > The error is printed at the bottom of the code. > Why does the

Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Joel Goldstick
On Mon, Oct 12, 2020 at 6:14 AM Steve wrote: > > At the top of my sample program, I have: > > import datetime > from datetime import * This second import tramples on the first. What happens if you remove it? > > But import datetime also has to be entered on line 21 as

What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Steve
At the top of my sample program, I have: import datetime from datetime import * But import datetime also has to be entered on line 21 as shown. The error is printed at the bottom of the code. Why does the code seem to forget that I have already imported datetime

Re: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread Cameron Simpson
On 11Oct2020 20:39, Steve wrote: >Still, I enjoyed the kluge I created making it work based on discovery... Poking around in the datetime module will definitely make you aware of its power, and its pitfalls. Well worth doing. At the very least you'll usually want it when printing times

RE: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread Steve
Thanks for the responses. Somehow, all of my python messages were shifted into the deleted folder so I missed all of them until I caught the one from MRAB. I will sift through them and probably update my technique to use seconds as suggested. Still, I enjoyed the kluge I created making it work b

Re: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread MRAB
On 2020-10-11 20:25, Steve wrote: Thanks for the response. I must have spent hours looking on-line for a method to treat datetime variables yet not one site mentioned the "pickle" module you indicatged. I did, however solve my problem. It may be a kluge but it seems to work. I lear

RE: Problem saving datetime to file and reading it back for a calculation

2020-10-11 Thread Steve
Thanks for the response. I must have spent hours looking on-line for a method to treat datetime variables yet not one site mentioned the "pickle" module you indicatged. I did, however solve my problem. It may be a kluge but it seems to work. I learned that I cannot use print() to d

Re: Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Chris Angelico
On Sun, Oct 11, 2020 at 12:57 PM Cameron Simpson wrote: > Personally I strongly dislike using datetimes for computation or as the > basis for time record keeping, essentially because of the timezone issue > but also because the human calendar is a complex disaster of illfitting > units (days in a

Re: Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Cameron Simpson
d2 to the file only if I convert it to string and, at a later >date, it gets read back in as d1 as string. That is the nature of text files. >The variable d1 as string will >not work in the HoursDiff statement. Because it is a string. Peter has described a way to transcribe a datetime i

Re: Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Peter Pearson
On Sat, 10 Oct 2020 18:17:26 -0400, Steve wrote: > I would like to use the line: > HoursDiff = int((d2-d1).total_seconds()/3600) > to determine the difference in hours between two timedate entries. > > The variable d2 is from datetime.now() > and d1 is read from a text file. > > I can save d2 to t

Problem saving datetime to file and reading it back for a calculation

2020-10-10 Thread Steve
I would like to use the line: HoursDiff = int((d2-d1).total_seconds()/3600) to determine the difference in hours between two timedate entries. The variable d2 is from datetime.now() and d1 is read from a text file. I can save d2 to the file only if I convert it to string and, at a later date, it

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread DL Neil via Python-list
On 13/02/20 9:17 AM, Michael Torrie wrote: On 2/12/20 7:44 AM, Ethan Furman wrote: On 02/11/2020 04:38 PM, Michael Torrie wrote: ... True. Costs can be calculated and planned for. But Technical debt is often impossible to quantify in a real, meaningful, business sense, other than the that we

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Michael Torrie
On 2/12/20 7:44 AM, Ethan Furman wrote: > On 02/11/2020 04:38 PM, Michael Torrie wrote: > >> It's all just different ways of accounting for the same things. In >> the olden days before the term "technical debt" was invented, we >> called this "total cost of ownership." > > TCO is not a fixed numb

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Rhodri James
On 12/02/2020 17:46, Python wrote: On Wed, Feb 12, 2020 at 01:16:03PM +, Rhodri James wrote: On 12/02/2020 00:53, Python wrote: In pretty much every job I've ever worked at, funding work (e.g. with humans to do it) with exactly and precisely the resources required is basically impossible, a

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Python
On Wed, Feb 12, 2020 at 01:16:03PM +, Rhodri James wrote: > On 12/02/2020 00:53, Python wrote: > > In pretty much every job I've ever worked at, funding work (e.g. with > > humans to do it) with exactly and precisely the resources required is > > basically impossible, and management prefers to

RE: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Avi Gross via Python-list
t: Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them) On 12/02/2020 00:53, Python wrote: > In pretty much every job I've ever worked at, funding work (e.g. with > humans to do it) with exactly and precisely the resources required is > basica

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Ethan Furman
On 02/11/2020 04:38 PM, Michael Torrie wrote: It's all just different ways of accounting for the same things. In the olden days before the term "technical debt" was invented, we called this "total cost of ownership." TCO is not a fixed number. For example, if a loan is taken to help fund a pr

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Rhodri James
On 12/02/2020 00:53, Python wrote: In pretty much every job I've ever worked at, funding work (e.g. with humans to do it) with exactly and precisely the resources required is basically impossible, and management prefers to underfund the work than to overfund it, for cost-savings reasons. This ba

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Jon Ribbens via Python-list
On 2020-02-12, Chris Angelico wrote: > But you CAN rewrite code such that it reduces technical debt. You can > refactor code to make it more logical. ... but if doing so costs more than the debt, you shouldn't do it. -- https://mail.python.org/mailman/listinfo/python-list

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 12:32 PM Michael Torrie wrote: > > On 2/11/20 6:15 PM, Chris Angelico wrote: > > On Wed, Feb 12, 2020 at 12:13 PM Michael Torrie wrote: > >> > >> On 2/11/20 5:55 PM, Chris Angelico wrote: > >>> But you CAN rewrite code such that it reduces technical debt. You can > >>> ref

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 6:15 PM, Chris Angelico wrote: > On Wed, Feb 12, 2020 at 12:13 PM Michael Torrie wrote: >> >> On 2/11/20 5:55 PM, Chris Angelico wrote: >>> But you CAN rewrite code such that it reduces technical debt. You can >>> refactor code to make it more logical. You can update things to use >>> i

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 5:53 PM, Python wrote: > If your hypothetical project was implemented perfectly from the > beginning, in Python2.x, it may never need updating, and therefore > there may well never be any reason to port it to python3. So doing so > would be neither "debt" nor "cost" but rather "waste."

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 12:13 PM Michael Torrie wrote: > > On 2/11/20 5:55 PM, Chris Angelico wrote: > > But you CAN rewrite code such that it reduces technical debt. You can > > refactor code to make it more logical. You can update things to use > > idioms that better express the concepts you're

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 5:55 PM, Chris Angelico wrote: > But you CAN rewrite code such that it reduces technical debt. You can > refactor code to make it more logical. You can update things to use > idioms that better express the concepts you're trying to represent > (maybe because those idioms require syntacti

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 12:00 PM Michael Torrie wrote: > > On 2/11/20 5:42 PM, Chris Angelico wrote: > > Yes, if you consider the term to be synonymous with TCO, then > > naturally you'll see it as useless. But it isn't. Technical debt is a > > very specific thing and it CAN be paid off. > > We'll

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Terry Reedy
On 2/11/2020 3:09 PM, Chris Angelico wrote: What you're talking about is costs in general, but "debt" is a very specific term. You accrue technical debt whenever you "borrow" time from the future - doing something that's less effort now at the expense of being worse in the future. A prime examp

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 11:48 AM Michael Torrie wrote: > > On 2/11/20 5:37 PM, Chris Angelico wrote: > > On Wed, Feb 12, 2020 at 11:32 AM Michael Torrie wrote: > >> > >> On 2/11/20 2:25 PM, Barry Scott wrote: > >>> At Chris said moving to python3 will *reduce* your technical debt. > >>> You are p

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 5:42 PM, Chris Angelico wrote: > Yes, if you consider the term to be synonymous with TCO, then > naturally you'll see it as useless. But it isn't. Technical debt is a > very specific thing and it CAN be paid off. We'll agree to disagree on the last bit. And I'm not the only one that bel

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Python
On Wed, Feb 12, 2020 at 07:09:12AM +1100, Chris Angelico wrote: > On Wed, Feb 12, 2020 at 7:03 AM Michael Torrie wrote: > > Speaking about technical debt is certainly fashionable these days. As > > if we've somehow discovered a brand new way of looking at things. But > > it doesn't matter what y

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 5:37 PM, Chris Angelico wrote: > On Wed, Feb 12, 2020 at 11:32 AM Michael Torrie wrote: >> >> On 2/11/20 2:25 PM, Barry Scott wrote: >>> At Chris said moving to python3 will *reduce* your technical debt. >>> You are paying off the debt. >> >> While at the same time incurring new debt. >

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 11:39 AM Michael Torrie wrote: > > On 2/11/20 1:09 PM, Chris Angelico wrote: > > What you're talking about is costs in general, but "debt" is a very > > specific term. You accrue technical debt whenever you "borrow" time > > from the future - doing something that's less eff

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 1:09 PM, Chris Angelico wrote: > What you're talking about is costs in general, but "debt" is a very > specific term. You accrue technical debt whenever you "borrow" time > from the future - doing something that's less effort now at the > expense of being worse in the future. You pay off

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 11:32 AM Michael Torrie wrote: > > On 2/11/20 2:25 PM, Barry Scott wrote: > > At Chris said moving to python3 will *reduce* your technical debt. > > You are paying off the debt. > > While at the same time incurring new debt. That's not an intrinsic part of the rewrite, and

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 2:25 PM, Barry Scott wrote: > At Chris said moving to python3 will *reduce* your technical debt. > You are paying off the debt. While at the same time incurring new debt. > Not to mention that its harder to hire people to work on tech-debt legacy > code. > > Given the choice between

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Barry Scott
> On 11 Feb 2020, at 20:01, Michael Torrie wrote: > > On 2/11/20 4:05 AM, Chris Angelico wrote: >> Or just the recognition that, eventually, technical debt has to be >> paid. > > Speaking about technical debt is certainly fashionable these days. As > if we've somehow discovered a brand new

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Barry Scott
> On 10 Feb 2020, at 23:01, Python wrote: > > As best I can tell, Python has no means to make use of the system's > timezone info. In order to make datetime "timezone aware", you need > to manually create a subclass of datetime.tzinfo, whose methods retur

Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 7:03 AM Michael Torrie wrote: > > On 2/11/20 4:05 AM, Chris Angelico wrote: > > Or just the recognition that, eventually, technical debt has to be > > paid. > > Speaking about technical debt is certainly fashionable these days. As > if we've somehow discovered a brand new

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 6:45 AM Python wrote: > > On Wed, Feb 12, 2020 at 05:38:38AM +1100, Chris Angelico wrote: > > > > Isn't it time to stop going to great effort to support Python > > > > > > If you live in a world where you get to decide that, sure. Not > > > everyone does. > > > > > > > Eve

Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Michael Torrie
On 2/11/20 4:05 AM, Chris Angelico wrote: > Or just the recognition that, eventually, technical debt has to be > paid. Speaking about technical debt is certainly fashionable these days. As if we've somehow discovered a brand new way of looking at things. But it doesn't matter what you do, there

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Python
On Wed, Feb 12, 2020 at 05:38:38AM +1100, Chris Angelico wrote: > > > Isn't it time to stop going to great effort to support Python > > > > If you live in a world where you get to decide that, sure. Not > > everyone does. > > > > Everyone gets to decide how much time and effort they put into > su

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
On Wed, Feb 12, 2020 at 3:57 AM Python wrote: > > On Tue, Feb 11, 2020 at 12:42:26PM +1100, Chris Angelico wrote: > > > > I've been using the timestamp() method: > > > > > > That's the key piece of info. This does appear to work, though still > > > not on python2. That, as you say, is my problem

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Python
On Tue, Feb 11, 2020 at 12:42:26PM +1100, Chris Angelico wrote: > > > I've been using the timestamp() method: > > > > That's the key piece of info. This does appear to work, though still > > not on python2. That, as you say, is my problem. But thankfully Jon > > Ribbens has the save: > > Isn't

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Jon Ribbens via Python-list
On 2020-02-11, Chris Angelico wrote: > On Tue, Feb 11, 2020 at 10:01 PM Jon Ribbens via Python-list > wrote: >> So while it's been about 6 years since anyone should have been >> starting any new projects using Python 2, there are plenty of >> projects that are older than that and still need suppor

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Chris Angelico
Jon > >> Ribbens has the save: > > > > Isn't it time to stop going to great effort to support Python 2? > > That depends on what existing systems people need to support. The main > project I work on pre-dates the existence of Python's 'datetime' > module, let

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-11 Thread Jon Ribbens via Python-list
support Python 2? That depends on what existing systems people need to support. The main project I work on pre-dates the existence of Python's 'datetime' module, let alone Python 3. It still generally uses 1 and 0 for True and False because True and False didn't exist when we starte

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Chris Angelico
On Tue, Feb 11, 2020 at 12:31 PM Python wrote: > > On Tue, Feb 11, 2020 at 11:33:54AM +1100, Chris Angelico wrote: > > [...] instead of using the undocumented and unsupported strftime %s > > format code > > I'm not sure this characterization is accurate... the docs (for both > Python 2 and 3) say:

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Python
On Tue, Feb 11, 2020 at 11:33:54AM +1100, Chris Angelico wrote: > [...] instead of using the undocumented and unsupported strftime %s > format code I'm not sure this characterization is accurate... the docs (for both Python 2 and 3) say: The full set of format codes supported varies across pl

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Jon Ribbens via Python-list
x27;1580434245' If you need to know the seconds since the epoch then in Python 3.3+ you can do that with dt.timestamp(). In Python 2.7 you can use the UTC class you created: (dt - datetime(1970, 1, 1, 0, 0, 0, 0, GMT())).total_seconds() -- https://mail.python.org/mailman/listinfo/python-list

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Chris Angelico
instance of this class as the tzinfo argument to the > > > constructor. Also no problem: > > > > Rather than try to create your own GMT() object, have you considered > > using datetime.timezone.utc ? I tested it in your examples and it > > works just

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Python
tor. Also no problem: > > Rather than try to create your own GMT() object, have you considered > using datetime.timezone.utc ? I tested it in your examples and it > works just fine. Not here it doesn't: >>> import datetime >>> dt = datetime.datetime(20

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Chris Angelico
On Tue, Feb 11, 2020 at 10:42 AM Python wrote: > > As best I can tell, Python has no means to make use of the system's > timezone info. In order to make datetime "timezone aware", you need > to manually create a subclass of datetime.tzinfo, whose methods return &

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Python
On Mon, Feb 10, 2020 at 05:52:59PM -0600, Skip Montanaro wrote: > > As best I can tell, Python has no means to make use of the system's > > timezone info. In order to make datetime "timezone aware", you need > > to manually create a subclass of datetime.tzi

Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Skip Montanaro
> As best I can tell, Python has no means to make use of the system's > timezone info. In order to make datetime "timezone aware", you need > to manually create a subclass of datetime.tzinfo, whose methods return > the correct values for the timezone you care about. &g

datetime seems to be broken WRT timezones (even when you add them)

2020-02-10 Thread Python
As best I can tell, Python has no means to make use of the system's timezone info. In order to make datetime "timezone aware", you need to manually create a subclass of datetime.tzinfo, whose methods return the correct values for the timezone you care about. In the general cas

Re: datetime gotcha

2019-12-12 Thread Frank Millman
On 2019-12-11 10:51 PM, Skip Montanaro wrote: Why is a dtm instance also an instance of dt? The datetime type is, in fact, a subclass of the date type: import datetime datetime.date.__bases__ (,) datetime.datetime.__bases__ (,) datetime.time.__bases__ (,) Skip Thanks for that. I

Re: datetime gotcha

2019-12-11 Thread Skip Montanaro
> Why is a dtm instance also an instance of dt? The datetime type is, in fact, a subclass of the date type: >>> import datetime >>> datetime.date.__bases__ (,) >>> datetime.datetime.__bases__ (,) >>> datetime.time.__bases__ (,) Skip -- https://mail.python.org/mailman/listinfo/python-list

datetime gotcha

2019-12-10 Thread Frank Millman
Hi all It took me a while to track down a bug that stemmed from this - >>> from datetime import date as dt, time as tm, datetime as dtm >>> x = dt.today() >>> isinstance(x, dt) True >>> isinstance(x, dtm) False >>

Re: Logging module and datetime - oil & water for some reason?

2019-04-02 Thread DL Neil
ot;thin wrapper" (and most of the provided 'convenience functions') to disappear in your rear-view mirror! I stole a custom formatter class from a StackOverflow thread and am now back in business (milliseconds *and* timezones, yay!). Still, peeking at the 2.7 documentation, I see t

Logging module and datetime - oil & water for some reason?

2019-04-01 Thread Skip Montanaro
zones, and sometimes need subsecond time resolution for quick-n-dirty analysis. I stole a custom formatter class from a StackOverflow thread and am now back in business (milliseconds *and* timezones, yay!). Still, peeking at the 2.7 documentation, I see that both the logging package and the dat

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-26 Thread vergos . nikolas
Actually i just found it has a directive: dictrows: Whether or not to support dict-like access to row objects (default: True). so i just did: plugin = bottle_pymysql.Plugin( dbuser='nikos', dbpass='*', dbname='counters', dictrows=False ) and now it works with indexes as integers not as st

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-26 Thread vergos . nikolas
len( newdata ) - 1 # Save index (for > 'newdata') of this row > else: # This row is a duplicate row with a different > referrer & visit datetime & torrent download > rowindex = seen[key] >

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-26 Thread vergos . nikolas
data.append( [ [host], [ref], location, useros, browser, [visits], hits, [downloads], authuser ] ) seen[key] = len( newdata ) - 1 # Save index (for 'newdata') of this row else: # This row is a duplicate row with a different refer

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-25 Thread DL Neil
On 26/02/19 7:47 AM, Dennis Lee Bieber wrote: On Mon, 25 Feb 2019 13:00:03 -0500, Dennis Lee Bieber declaimed the following: My apologies for the mis-attribution -- due to spam, I tend to filter out @gmail.com posts (the one flaw with Forte Agent -- it only filters news groups on subje

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread DL Neil
if key not in seen: newdata.append( [ [host], [ref], location, useros, browser, [visits], hits, [downloads], authuser ] ) seen[key] = len( newdata ) - 1 # Save index (for 'newda

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread vergos . nikolas
want an html row for every unique combination of > (host) and that hits should be summed together > key = host > if key not in seen: > newdata.append( [ [host], [ref], location, > useros, browser,

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread vergos . nikolas
nd that hits should be summed together key = host if key not in seen: newdata.append( [ [host], [ref], location, useros, browser, [visits], hits, [downloads], authuser ] ) seen[key] = len( n

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread DL Neil
Vergos, Please provide more information and show how you've debugged the code so far... On 25/02/19 7:03 AM, vergos.niko...@gmail.com wrote: pymydb.execute( '''SELECT host, ref, location, useros, browser, visits, hits, downloads, authuser FROM guests

How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread vergos . nikolas
pymydb.execute( '''SELECT host, ref, location, useros, browser, visits, hits, downloads, authuser FROM guests WHERE pagesID = (SELECT ID FROM pages WHERE url = %s) ORDER BY visits DESC''', page ) data = pymydb.fetchall() for visit in visits:

Re: defaultdict and datetime

2018-08-18 Thread MRAB
On 2018-08-18 16:43, Jason Friedman wrote: $ python3 Python 3.6.1 (default, Apr 8 2017, 09:56:20) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. import collections, datetime x = collectio

defaultdict and datetime

2018-08-18 Thread Jason Friedman
$ python3 Python 3.6.1 (default, Apr 8 2017, 09:56:20) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import collections, datetime >>> x = collections.defaultdict(int) >>>

  1   2   3   4   5   6   7   8   9   10   >