[Python-Dev] datetime.fromisocalendar (original) (raw)
Ivan Pozdeev vano at mail.mipt.ru
Mon Apr 29 16:56:08 EDT 2019
- Previous message (by thread): [Python-Dev] datetime.fromisocalendar
- Next message (by thread): [Python-Dev] git history conundrum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 29.04.2019 16:30, Victor Stinner wrote:
I reviewed and merged Paul's PR. I concur with Guido, the new constructor perfectly makes sense and is useful.
About the implementation: date and time are crazy beasts. Extract of the code: if not 0 < week < 53:_ _outofrange = True_ _if week == 53:_ _# ISO years have 53 weeks in them on years starting with a_ _# Thursday and leap years starting on a Wednesday_ _firstweekday = ymd2ord(year, 1, 1) % 7_ _if (firstweekday == 4 or (firstweekday == 3 and_ _isleap(year))):_ _outofrange = False_ _if outofrange:_ _raise ValueError(f"Invalid week: {week}")_ _"ISO years have 53 weeks in them on years starting with a Thursday and_ _leap years starting on a Wednesday" !?!_ https://www.staff.science.uu.nl/~gent0113/calendar/isocalendar.htm , linked from https://docs.python.org/3/library/datetime.html?highlight=isocalendar#datetime.date.isocalendar _Victor_ _Le sam. 27 avr. 2019 à 22:37, Guido van Rossum <guido at python.org> a écrit : I think it’s a good idea. >> On Sat, Apr 27, 2019 at 11:43 AM Paul Ganssle <paul at ganssle.io> wrote: > Greetings, >>>> Some time ago, I proposed adding a
.fromisocalendar
alternate constructor todatetime
(bpo-36004), with a corresponding implementation (PR #11888). I advertised it on datetime-SIG some time ago but haven't seen much discussion there, so I'd like to bring it to python-dev's attention as we near the cut-off for new Python 3.8 features. >>>> Other than the fact that I've needed this functionality in the past, I also think a good general principle for the datetime module is that when a class (time, date, datetime) has a "serialization" method (.strftime, .timestamp, .isoformat, .isocalendar, etc), there should be a corresponding deserialization method (.strptime, .fromtimestamp, .fromisoformat) that constructs a datetime from the output. Now thatfromisoformat
was introduced in Python 3.7, I thinkisocalendar
is the only remaining method without an inverse. Do people agree with this principle? Should we add thefromisocalendar
method? >>>> Thanks, > Paul >>>> _________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org -- --Guido (mobile) _________________________ Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/vstinner%40redhat.comRegards, Ivan
- Previous message (by thread): [Python-Dev] datetime.fromisocalendar
- Next message (by thread): [Python-Dev] git history conundrum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]