improve custom formatter example
This commit is contained in:
parent
ad7a95b2f2
commit
d28f425c7e
11
README.md
11
README.md
|
@ -228,19 +228,20 @@ reader = csv.DictReader(
|
||||||
total = timedelta(seconds=0)
|
total = timedelta(seconds=0)
|
||||||
|
|
||||||
for line in reader:
|
for line in reader:
|
||||||
if not line['end']:
|
|
||||||
continue
|
|
||||||
|
|
||||||
start = datetime.strptime(line['start'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
start = datetime.strptime(line['start'], '%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')
|
end = datetime.strptime(line['end'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
|
||||||
total += end - start
|
total += end - start
|
||||||
|
|
||||||
hours = ceil(total.total_seconds() / (3600))
|
hours = total.total_seconds() / 3600
|
||||||
earnings = hours * config['hourly_rate']
|
earnings = hours * config['hourly_rate']
|
||||||
currency = config['currency']
|
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:
|
Now if you run `t display -f earnings` you will get something like:
|
||||||
|
|
Loading…
Reference in New Issue