datetime, calendar, time intervals

M

Michele Simionato

Strangely enough, I never needed the datetime and calendar module
before,
so I just looked at them today. I am surprised I don't easily find an
interval
function such this:

import datetime

def interval(day, lastday, step): # not necessarely restricted to days
while day < lastday:
yield day
day += step

firstday = datetime.date(2004, 05, 01)
lastday = datetime.date(2004, 06, 01)
oneday = datetime.timedelta(1)
for day in interval(firstday, lastday, oneday):
print day

Did I overlook something? Has an iterator over time intervals been
taken in consideration for addition in the standard library? (or maybe
is already
there ...)
Also, the calendar module seems to be giving just the Unix "cal"
functionality
which is a bit poor, I would have expected more ...

Just curious,

Michele Simionato
 
D

David Eppstein

Strangely enough, I never needed the datetime and calendar module
before, so I just looked at them today.

Me too. datetime was exactly what I wanted. Until I realized that it
wasn't available in the 2.2.3 installation I needed my code to run in...
 
J

John Roth

David Eppstein said:
Me too. datetime was exactly what I wanted. Until I realized that it
wasn't available in the 2.2.3 installation I needed my code to run in...

Yeah, that's a problem. I've been avoiding putting a date type adapter
in the Python version of FIT for exactly that reason. Which brought up
the question of whether it would be possible to back-port it, and I
found that it was a C language module. Sigh.

John Roth
 
N

NewToPython

Yeah, that's a problem. I've been avoiding putting a date type adapter
in the Python version of FIT for exactly that reason. Which brought up
the question of whether it would be possible to back-port it, and I
found that it was a C language module. Sigh.

Sorry, I am new to Python, but I have a requirement for date
manipulation in an app that will need to run in 2.2, so I am
interested in the data functions of the latest release as well. When
you say that it was a C module, are you saying the library of date
functions in the latest version are written in C? Does this somehow
stop us from back-porting it to 2.2 or 2.1 python? I would be very
interested in seeing the C source code for the date routines, along
with the routine descriptions - where can I find that?

- Chris
John Roth
 
P

Peter Otten

NewToPython said:
interested in the data functions of the latest release as well. When
you say that it was a C module, are you saying the library of date
functions in the latest version are written in C? Does this somehow
stop us from back-porting it to 2.2 or 2.1 python? I would be very

Nobody would stop someone willing to do the work :)
interested in seeing the C source code for the date routines, along
with the routine descriptions - where can I find that?

You can find the source distribution of the current version at the usual
place:

http://www.python.org/download/

A good starting point for a (future) developer would be

http://www.python.org/dev/

If you are only interested in one module, you can browse the CVS tree (see
"Outside Links" on the above page). The datetime implementation is here:

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Modules/datetimemodule.c

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top