This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pure python version of calendar.weekday
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: fdrake, gvanrossum, hyeshik.chang, rhettinger
Priority: normal Keywords: patch

Created on 2001-11-20 17:42 by hyeshik.chang, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
calendar.txt hyeshik.chang, 2001-11-20 17:43 patch to calendar.py
calendar.txt hyeshik.chang, 2001-11-20 17:49 patch to calendar.py
calendar.py.diff hyeshik.chang, 2002-06-18 02:01 (revised) patch for Lib/calendar.py
libcalendar.tex.diff hyeshik.chang, 2002-06-18 02:02 (revised) patch for Doc/lib/libcalendar.tex
test_calendar.py.diff hyeshik.chang, 2002-06-18 02:03 (revised) patch for Lib/test/test_calendar.py
verify_calendar.py hyeshik.chang, 2002-06-18 02:04 (revised) sanity verifyier with FreeBSD ncal(1)
weekday.diff rhettinger, 2002-06-18 20:54 Revised patch to calendar.py
Messages (8)
msg38197 - (view) Author: Hyeshik Chang (hyeshik.chang) * (Python committer) Date: 2001-11-20 17:42
this version can handle past of 1970, and PURE.
but this is not too slower than old one.


NetBSD machine on Pentium 90MHz:

$ python wday.py 1000
Time Module: 0.641623973846
Pure Python: 0.724056005478

$ python wday.py 10000
Time Module: 6.77021896839
Pure Python: 7.34891104698


Linux machine on Pentium III 800MHz:

$ python wday.py 10000
Time Module: 0.611389994621
Pure Python: 0.833150982857

$ python wday.py 100000
Time Module: 6.12289500237
Pure Python: 8.36460494995
msg38198 - (view) Author: Hyeshik Chang (hyeshik.chang) * (Python committer) Date: 2001-11-20 17:51
Logged In: YES 
user_id=55188

upper one of two patches is using if - if.
another is using and - or.
msg38199 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-05-08 06:14
Logged In: YES 
user_id=80475

Thanks for the patch.  Here are a few suggestions:

- Use diff -c for your patch

- Update the patch to diff from the current version, 1.27.

- Also change the library reference which specifies 1970.

- Expand test_calendar.py to include your expanded range.

- Add a range check to weekday() to raise an Error if date 
is before 1752 (this will be a common error if the century 
is omitted in a call).  The current treat is to raise 
ValueError: year out of range.

- Eliminate the comment # Importing add from operator

- Change the multi-line style away from using \ which 
relies on there being no extra spaces at the end of a 
line.  Instead write:
sum = a +
      b -
      c

- Revise the doc string to specify "Accurate for date from 
September 14, 1752".  As specified now, it implies accuracy 
to the beginning of that year.

- Create a special case for monthcalendar() to handle 
September 1752

- Submit a separate Python program that runs every possible 
monthcalendar from 1752 and compares the result to the Unix 
cal program.  I checked your logic and it looks fine, but a 
comprehensive compare will be doubly persuasive.  Some 
similar proof of daygap() would be helpful.

- Either add daygap() to the docs or incorporate it 
directly inside weekday().
msg38200 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2002-06-17 21:24
Logged In: YES 
user_id=3066

As Raymond noted, this patch is out of date.  Please provide
an updated patch, addressing the concerns already noted.

Assigned to Raymond since he's demonstrated an interest, and
marked pending so it doesn't annoy him until there's a new
patch.
msg38201 - (view) Author: Hyeshik Chang (hyeshik.chang) * (Python committer) Date: 2002-06-18 02:25
Logged In: YES 
user_id=55188

Thanks, all!
How do you feel with revised patches and verifyier?

I can get Okay from FreeBSD ncal(1).

home(perky):~/cvs/python/Lib% python verify_calendar.py
test_daygap (__main__.CalendarUnixVerifyCase) ... ok
test_weekday (__main__.CalendarUnixVerifyCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 5.027s

OK
msg38202 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-06-18 18:18
Logged In: YES 
user_id=6380

I'm against all maintenance on the calendar module.

Fred Drake & I are (slowly) working on a new datetime
module, in the nondist/sandbox/datetime/ part of the
Python CVS tree.  This will support a much larger
range of dates.  It will be in Python 2.3.
msg38203 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-06-18 20:54
Logged In: YES 
user_id=80475

In case this ever gets revived, a revised patch is attached 
which is faster, avoids reduce(), and avoids operator.add.

The core concept of the perky's patch is a good idea.  This 
current implementation is only good for a 68 year time 
period from 1970 to 2037.  Also, the daygap() function is 
especially useful for financial calculations.
msg38204 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-06-18 21:14
Logged In: YES 
user_id=6380

Don't waste your time on this.  The datetime code already
contains all the calendrical calculations you could possibly
need for business time computations.
History
Date User Action Args
2022-04-10 16:04:39adminsetgithub: 35555
2001-11-20 17:42:58hyeshik.changcreate