Changeset 75:957d4b9c06eb in stamper


Ignore:
Timestamp:
Feb 24, 2020, 8:27:01 AM (5 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Tags:
tip
Message:

Ensure totals are shown in hours:minutes:seconds when they are over 24 hours

File:
1 edited

Legend:

Unmodified
Added
Removed
  • stamper/stamper.py

    r74 r75  
    1111from .config import Config
    1212from .filters import DateFilter
     13
     14
     15def timedelta_to_hms(value):
     16    """
     17    Return hours, minutes, seconds from a timedelta object
     18    """
     19    hours, remainder = divmod(int(value.total_seconds()), 3600)
     20    minutes, seconds = divmod(remainder, 60)
     21    return hours, minutes, seconds
    1322
    1423
     
    299308            seconds=totals.get(customer, 0)
    300309            total = timedelta(seconds=totals.get(customer, 0))
     310            h, m, s = timedelta_to_hms(total)
     311            total = ':'.join(
     312                [str(h).zfill(2), str(m).zfill(2), str(s).zfill(2)])
    301313            if not self.wants_seconds or self.wants_seconds == 'false':
    302314                # remove the seconds part from the string representation
     
    308320                seconds=totals[c]
    309321                total = timedelta(seconds=totals[c])
     322                h, m, s = timedelta_to_hms(total)
     323                total = ':'.join(
     324                    [str(h).zfill(2), str(m).zfill(2), str(s).zfill(2)])
    310325                if not self.wants_seconds or self.wants_seconds == 'false':
    311326                    # remove the seconds part from the string representation
Note: See TracChangeset for help on using the changeset viewer.