calendar by week

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GuineaPig

    calendar by week

    Hello gurus,

    Does anybody know of a function/module that can help me with the
    following problem:

    In my app the user can encode the starting and ending hours of his
    workdays. The app calculates the time the user worked (per week) and
    the user's overtime. The results are exported to an excel-sheet for
    printing.

    One thing that I would like to accomplish is that the user has to only
    give in the weeknumber of the year. The app should then write the dates
    in this week to the excel-sheet. I've been looking at the calendar and
    time modules but I don't quite see a solution there (maybe there is
    though, maybe I'm just too much of a newbie.)

    Tnx a lot!

    Tom
  • Peter Otten

    #2
    Re: calendar by week

    GuineaPig wrote:
    [color=blue]
    > One thing that I would like to accomplish is that the user has to only
    > give in the weeknumber of the year. The app should then write the dates
    > in this week to the excel-sheet. I've been looking at the calendar and
    > time modules but I don't quite see a solution there (maybe there is
    > though, maybe I'm just too much of a newbie.)[/color]

    import datetime

    def daysOfWeek(year , week):
    day = datetime.date(y ear, 2, 1)
    year, weekBase, dayBase = day.isocalendar ()
    day += datetime.timede lta(1 - dayBase + (week - weekBase)*7)
    delta = datetime.timede lta(1)
    for i in range(6):
    yield day
    day += delta
    yield day

    Try it:
    [color=blue][color=green][color=darkred]
    >>> from daysofweek import daysOfWeek
    >>> for d in daysOfWeek(2004 , 1):[/color][/color][/color]
    .... print d
    ....
    2003-12-29
    2003-12-30
    2003-12-31
    2004-01-01
    2004-01-02
    2004-01-03
    2004-01-04

    Peter

    Comment

    • GuineaPig

      #3
      Re: calendar by week

      Peter Otten wrote:
      [color=blue]
      > GuineaPig wrote:
      >
      >[color=green]
      >>One thing that I would like to accomplish is that the user has to only
      >>give in the weeknumber of the year. The app should then write the dates
      >>in this week to the excel-sheet. I've been looking at the calendar and
      >>time modules but I don't quite see a solution there (maybe there is
      >>though, maybe I'm just too much of a newbie.)[/color]
      >
      >
      > import datetime
      >
      > def daysOfWeek(year , week):
      > day = datetime.date(y ear, 2, 1)
      > year, weekBase, dayBase = day.isocalendar ()
      > day += datetime.timede lta(1 - dayBase + (week - weekBase)*7)
      > delta = datetime.timede lta(1)
      > for i in range(6):
      > yield day
      > day += delta
      > yield day
      >
      > Try it:
      >
      >[color=green][color=darkred]
      >>>>from daysofweek import daysOfWeek
      >>>>for d in daysOfWeek(2004 , 1):[/color][/color]
      >
      > ... print d
      > ...
      > 2003-12-29
      > 2003-12-30
      > 2003-12-31
      > 2004-01-01
      > 2004-01-02
      > 2004-01-03
      > 2004-01-04
      >
      > Peter
      >[/color]

      Thanks Peter,

      This works great!

      Tom

      Comment

      Working...