improve custom formatter example

This commit is contained in:
Abraham Toriz 2021-09-08 10:06:36 -05:00
parent ad7a95b2f2
commit d28f425c7e
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 7 additions and 6 deletions

View File

@ -228,19 +228,20 @@ reader = csv.DictReader(
total = timedelta(seconds=0)
for line in reader:
if not line['end']:
continue
start = datetime.strptime(line['start'], '%Y-%m-%dT%H:%M:%S.%fZ')
end = datetime.strptime(line['end'], '%Y-%m-%dT%H:%M:%S.%fZ')
if not line['end']:
end = datetime.utcnow()
else:
end = datetime.strptime(line['end'], '%Y-%m-%dT%H:%M:%S.%fZ')
total += end - start
hours = ceil(total.total_seconds() / (3600))
hours = total.total_seconds() / 3600
earnings = hours * config['hourly_rate']
currency = config['currency']
print(f'You have earned: {earnings} {currency}')
print(f'You have earned: ${earnings:.2f} {currency}')
```
Now if you run `t display -f earnings` you will get something like: