help with dates

Pierre Quentel quentel.pierre at wanadoo.fr
Sat Mar 31 23:51:27 CEST 2007


> Four groups of firefighters (group1, group2, group3, group4). Each
> group works a 24 hr shift. So group1 works April 1, group2 works April
> 2, group3 works April 3, group4 works April 4, group 1 works April 5,
> etc. It just keeps rolling like this forever into next year, etc.
>
> I need to come up with a methodology for the following:
>
> If given a date, find out what group is working on that date.
>
Hello,

You can use method datetime.date.toordinal() :

from datetime import date
start = date(2007,4,1) # Arpil 1, 2007

def group(_date):
    return (date.toordinal(_date)-date.toordinal(start)) % 4

print group(date(2007,4,15))

Regards,
Pierre




More information about the Python-list mailing list