473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

calendar (date) iterator?

Hi,

I'm looking for useful starting points, suggestions, and sample code,
to implement a calendar iterator. Simply, the iterator is seeded with
an initial calendar date, e.g., "03-12-2006", and then subsequent
calls to next return subsequent dates. The seed could be a standard
calendar/datetime object.
iter = calendarIterator("03-12-2006")
print iter.next()
03-12-2006

A useful extension would be to allow specifiation of iter intervals,
e.g.,
iter = calendarIterator("03-12-2006 01:00:00", "minutes")
print iter.next()
03-12-2006 01:01:00

Thanks in advance for pointers and suggestions!

Mar 6 '07 #1
4 2192
Oops-- the iter needs to work better than I do! :)
iter = calendarIterator("03-12-2006")
print iter.next()

03-12-2006
^^^^^^^^^^
03-13-2006

iter = calendarIterator("03-12-2006 01:00:00", "minutes")
print iter.next()

03-12-2006 01:01:00
^^^^^^^^^^
03-13-2006

Mar 6 '07 #2

MarcusI'm looking for useful starting points, suggestions, and sample
Marcuscode, to implement a calendar iterator.

Have you looked at dateutil?

http://labix.org/python-dateutil
>>from dateutil.rrule import rrule, DAILY
from dateutil.parser import parse
rule = rrule(DAILY, count=5, dtstart=parse("2006-03-12"))
for d in rule:
... print d
...
2006-03-12 00:00:00
2006-03-13 00:00:00
2006-03-14 00:00:00
2006-03-15 00:00:00
2006-03-16 00:00:00

Skip
Mar 6 '07 #3
On Mar 6, 3:19 pm, s...@pobox.com wrote:
MarcusI'm looking for useful starting points, suggestions, and sample
Marcuscode, to implement a calendar iterator.

Have you looked at dateutil?

http://labix.org/python-dateutil
>>from dateutil.rrule import rrule, DAILY
>>from dateutil.parser import parse
>>rule = rrule(DAILY, count=5, dtstart=parse("2006-03-12"))
>>for d in rule:
... print d
...
2006-03-12 00:00:00
2006-03-13 00:00:00
2006-03-14 00:00:00
2006-03-15 00:00:00
2006-03-16 00:00:00

Skip

This is exactly what I was looking for! Thanks so much!!

Mar 6 '07 #4
[Marcus]
I'm looking for useful starting points, suggestions, and sample code,
to implement a calendar iterator. Simply, the iterator is seeded with
an initial calendar date, e.g., "03-12-2006", and then subsequent
calls to next return subsequent dates. The seed could be a standard
calendar/datetime object.
iter = calendarIterator("03-12-2006")
print iter.next()

03-12-2006
import datetime, time

def calendarIterator(start, fmt='%m-%d-%Y'):
curr = datetime.date(*time.strptime(start, fmt)[:3])
one = datetime.timedelta(1)
while 1:
curr += one
yield curr

if __name__ == '__main__':
iter = calendarIterator('3-12-2006')
print iter.next()
print iter.next()

Mar 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format...
4
by: Michele Simionato | last post by:
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 ...
10
by: vinu | last post by:
I have a javascript file named select.js. This is a file which is use to pop up a calendar, when clicked on a calendar icon in an ASP file. have a close button in the calendar. When i click on the...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
3
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
0
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.