Changeset 67:4303a45e8a2f in stamper


Ignore:
Timestamp:
Feb 1, 2018, 8:24:08 AM (7 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Added a new config parameter, wants_seconds, that tells stamper if it should
show seconds in the reports or not. Defaults to False (do not show seconds)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • etc/stamper.conf

    r60 r67  
    88time_format = %%H:%%M:%%S
    99datetime_format = %%Y-%%m-%%d %%H:%%M
     10wants_seconds = False
    1011
    1112[sum]
  • stamper/stamper.py

    r63 r67  
    2424        self.time_format = self.config.get('stamps', 'time_format')
    2525        self.datetime_format = self.config.get('stamps', 'datetime_format')
     26        self.wants_seconds = self.config.get('stamps', 'wants_seconds')
    2627        self.hours_day = int(self.config.get('sum', 'hours_day'))
    2728        self.collector = self.config.get('collector')
     
    159160                    totals[start_day] = 0
    160161                worktime = self.worktime(stamp['start'], stamp['end'])
     162                str_worktime = str(timedelta(seconds=worktime))
     163                if not self.wants_seconds or self.wants_seconds == 'false':
     164                    # remove the seconds part from the string representation
     165                    str_worktime = ':'.join(str_worktime.split(':')[:-1])
    161166                details[start_day].append(
    162167                    '%(worktime)s %(customer)s %(action)s' % {
    163                         'worktime': str(timedelta(seconds=worktime)),
     168                        'worktime': str_worktime,
    164169                        'customer': customer,
    165170                        'action': stamp['action']
     
    173178        for day in totals:
    174179            totals[day] = str(timedelta(seconds=totals[day]))
     180            if not self.wants_seconds or self.wants_seconds == 'false':
     181                # remove the seconds part from the string representation
     182                totals[day] = ':'.join(totals[day].split(':')[:-1])
    175183        return details, totals, total_customer
    176184
     
    273281                for tc in total_customer[day]:
    274282                    tc_total = str(timedelta(seconds=total_customer[day][tc]))
     283                    if not self.wants_seconds or self.wants_seconds == 'false':
     284                        # remove the seconds part from the string representation
     285                        tc_total = ':'.join(tc_total.split(':')[:-1])
    275286                    customer_day_totals.append(tc+': '+tc_total)
    276287                print(', '.join(customer_day_totals))
     
    286297            seconds=totals.get(customer, 0)
    287298            total = timedelta(seconds=totals.get(customer, 0))
     299            if not self.wants_seconds or self.wants_seconds == 'false':
     300                # remove the seconds part from the string representation
     301                total = ':'.join(str(total).split(':')[:-1])
    288302            print(' %(customer)s: %(total)s' % {'customer': customer,
    289303                                                'total': total})
     
    292306                seconds=totals[c]
    293307                total = timedelta(seconds=totals[c])
     308                if not self.wants_seconds or self.wants_seconds == 'false':
     309                    # remove the seconds part from the string representation
     310                    total = ':'.join(str(total).split(':')[:-1])
    294311                print(' %(customer)s: %(total)s' % {'customer': c,
    295312                                                    'total': total})
Note: See TracChangeset for help on using the changeset viewer.