Added a new config parameter, wants_seconds, that tells stamper if it should
authorBorja Lopez <borja@codigo23.net>
Thu, 01 Feb 2018 08:24:08 +0100
changeset 67 4303a45e8a2f
parent 66 548534cb10d4
child 68 0c473bfc59f3
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)
etc/stamper.conf
stamper/stamper.py
--- a/etc/stamper.conf	Sun Jul 09 10:35:58 2017 +0200
+++ b/etc/stamper.conf	Thu Feb 01 08:24:08 2018 +0100
@@ -7,6 +7,7 @@
 date_format = %%Y-%%m-%%d
 time_format = %%H:%%M:%%S
 datetime_format = %%Y-%%m-%%d %%H:%%M
+wants_seconds = False
 
 [sum]
 hours_day = 8
--- a/stamper/stamper.py	Sun Jul 09 10:35:58 2017 +0200
+++ b/stamper/stamper.py	Thu Feb 01 08:24:08 2018 +0100
@@ -23,6 +23,7 @@
         self.date_format = self.config.get('stamps', 'date_format')
         self.time_format = self.config.get('stamps', 'time_format')
         self.datetime_format = self.config.get('stamps', 'datetime_format')
+        self.wants_seconds = self.config.get('stamps', 'wants_seconds')
         self.hours_day = int(self.config.get('sum', 'hours_day'))
         self.collector = self.config.get('collector')
         self.ensure_stamps_file()
@@ -158,9 +159,13 @@
                 if start_day not in totals:
                     totals[start_day] = 0
                 worktime = self.worktime(stamp['start'], stamp['end'])
+                str_worktime = str(timedelta(seconds=worktime))
+                if not self.wants_seconds or self.wants_seconds == 'false':
+                    # remove the seconds part from the string representation
+                    str_worktime = ':'.join(str_worktime.split(':')[:-1])
                 details[start_day].append(
                     '%(worktime)s %(customer)s %(action)s' % {
-                        'worktime': str(timedelta(seconds=worktime)),
+                        'worktime': str_worktime,
                         'customer': customer,
                         'action': stamp['action']
                     })
@@ -172,6 +177,9 @@
                 total_customer[start_day][customer] += worktime
         for day in totals:
             totals[day] = str(timedelta(seconds=totals[day]))
+            if not self.wants_seconds or self.wants_seconds == 'false':
+                # remove the seconds part from the string representation
+                totals[day] = ':'.join(totals[day].split(':')[:-1])
         return details, totals, total_customer
 
     def timeline(self, customer=None, stamp_filter=None, filter_descr=None):
@@ -272,6 +280,9 @@
                 customer_day_totals = []
                 for tc in total_customer[day]:
                     tc_total = str(timedelta(seconds=total_customer[day][tc]))
+                    if not self.wants_seconds or self.wants_seconds == 'false':
+                        # remove the seconds part from the string representation
+                        tc_total = ':'.join(tc_total.split(':')[:-1])
                     customer_day_totals.append(tc+': '+tc_total)
                 print(', '.join(customer_day_totals))
                 if len(customer_day_totals) > 1:
@@ -285,12 +296,18 @@
         if customer:
             seconds=totals.get(customer, 0)
             total = timedelta(seconds=totals.get(customer, 0))
+            if not self.wants_seconds or self.wants_seconds == 'false':
+                # remove the seconds part from the string representation
+                total = ':'.join(str(total).split(':')[:-1])
             print(' %(customer)s: %(total)s' % {'customer': customer,
                                                 'total': total})
         else:
             for c in totals:
                 seconds=totals[c]
                 total = timedelta(seconds=totals[c])
+                if not self.wants_seconds or self.wants_seconds == 'false':
+                    # remove the seconds part from the string representation
+                    total = ':'.join(str(total).split(':')[:-1])
                 print(' %(customer)s: %(total)s' % {'customer': c,
                                                     'total': total})