~taskcoach-developers/taskcoach/trunk

« back to all changes in this revision

Viewing changes to taskcoachlib/render.py

  • Committer: fraca7
  • Date: 2014-03-29 17:17:22 UTC
  • Revision ID: svn-v4:1bde7e76-c350-445e-a5b0-d0792d1e7eef:trunk/taskcoach:6450
Merge with release 1.3 branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    return sign + days + hours_and_minutes
57
57
 
58
58
 
59
 
def timeSpent(timeSpent, showSeconds=True):
 
59
def timeSpent(timeSpent, showSeconds=True, decimal=False):
60
60
    ''' Render time spent (of type date.TimeDelta) as
61
61
        "<hours>:<minutes>:<seconds>" or "<hours>:<minutes>" '''
 
62
    if decimal:
 
63
        return timeSpentDecimal(timeSpent)
 
64
 
62
65
    zero = datemodule.TimeDelta()
63
66
    if timeSpent == zero:
64
67
        return ''
68
71
        return sign + '%d:%02d' % (hours, minutes) + \
69
72
               (':%02d' % seconds if showSeconds else '')
70
73
 
 
74
def timeSpentDecimal(timeSpent):
 
75
    ''' Render time spent (of type date.TimeDelta) as
 
76
        "<hours>.<fractional hours> '''
 
77
    zero = datemodule.TimeDelta()
 
78
    if timeSpent == zero:
 
79
        return ''
 
80
    else:
 
81
        sign = '-' if timeSpent < zero else ''
 
82
        hours, minutes, seconds = timeSpent.hoursMinutesSeconds()
 
83
        decimalHours = hours + minutes/60.0 + seconds/3600.0
 
84
        return sign + '%.2f' % (decimalHours)
71
85
 
72
86
def recurrence(recurrence):
73
87
    ''' Render the recurrence as a short string describing the frequency of