# HG changeset patch # User Björn Ricks # Date 1358419296 -3600 # Node ID 64624032611dad1187053c93b2a2adfc68e7c98b # Parent 4f1c53bd8ba1f8e94e06b981524120ab783a6531 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. diff -r 4f1c53bd8ba1 -r 64624032611d getan/contrib/zeiterfassung.py --- 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