def show(self, args): if '--all' not in args and self.start is None: return print '* %s' % self.name if len(self.tags) > 0: print ' [%s]' % self.joined_tags() if self.start is not None: date_format = '%A %d, %H.%M' start, now, delta = self.current_delta() print ' since %s' % start.strftime(date_format) print ' ongoing for %s' % parse_delta(delta) if len(self.previous) > 0: print ' has %d previous tracks.' % len(self.previous) tracked_times = [] for previous_track in self.previous: start = to_datetime(previous_track['start']) end = to_datetime(previous_track['end']) delta = end - start if '-v' in args: # Show each previous track with its tags. msg = ' * %s' % parse_delta(delta) if len(previous_track['tags']) > 0: msg = ' '.join([msg, '[%s]' % ', '.join(previous_track['tags']) ]) print msg tracked_times.append(delta) delta = reduce(lambda x, y: x + y, tracked_times) if self.start is not None: delta += self.current_delta()[2] print ' %s total.' % parse_delta(delta)
def current_delta(self): start = to_datetime(self.start) now = datetime.now() delta = datetime.now() - start return start, now, delta