From d28f425c7e9cfd57dfe596e005be3093c76780c5 Mon Sep 17 00:00:00 2001 From: Abraham Toriz Date: Wed, 8 Sep 2021 10:06:36 -0500 Subject: [PATCH] improve custom formatter example --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e6cac66..67fe626 100644 --- a/README.md +++ b/README.md @@ -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: