Mercurial > getan
changeset 191:64624032611d
Add function to convert from iso to unix week
For evaluation we use the iso week as week parameter which is commonly known in
europe. But SQLite internally uses unix weeks which may differ. Therefore
convert the iso week to the unix week.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 17 Jan 2013 11:41:36 +0100 |
parents | 4f1c53bd8ba1 |
children | 9bb175cfaca3 |
files | getan/contrib/zeiterfassung.py |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/getan/contrib/zeiterfassung.py Thu Jan 17 11:39:52 2013 +0100 +++ b/getan/contrib/zeiterfassung.py Thu Jan 17 11:41:36 2013 +0100 @@ -114,6 +114,23 @@ description IS NOT NULL AND length(description) > 0 ''' +def unix_week(week, year=None): + """Convert iso week to unix week + + For unix week see man date "%W" + Args: + week: Week number as int to convert + year: Year as int. If year is none the current year is used. + """ + if not year: + year = datetime.now().year + firstday = date(year, 1, 4) + isoweek = firstday.isocalendar()[1] + unixweek = int(firstday.strftime("%W")) + diff = isoweek - unixweek + return week - diff + + def human_time(s): h = s / 3600 m = (s % 3600) / 60