changeset 14:aa18210c2703

Improve start/end/days handling - Allow the user to specify nothing to graph todays data. - Fix bug when only specifying days. - When specifying days finish at the end of today.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 11 Jan 2018 08:43:40 +1030
parents 3f22fa1f32d5
children c04c75360a3b
files graph.py
diffstat 1 files changed, 10 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graph.py	Fri Dec 22 16:30:45 2017 +0100
+++ b/graph.py	Thu Jan 11 08:43:40 2018 +1030
@@ -66,27 +66,25 @@
     if args.days is not None and args.days < 0:
         parser.error('days must be non-negative')
 
-    # Can specify..
-    # Start and end
-    # Start and days or Start
-    # End and days or End
-    # Nothing
-    # Want to end up with a start & end
     selector = [args.start is not None, args.end is not None, args.days is not None]
-    if selector == [True, True, False]:
+    if selector == [True, True, False]: # Start and end
         pass
-    elif selector == [True, False, True] or selector == [True, False, False]:
+    elif selector == [True, False, True] or selector == [True, False, False]: # Start and days or start
         if args.days == None:
             args.days = 1
         args.end = args.start + datetime.timedelta(days = args.days)
-    elif selector == [False, True, True] or selector == [False, True, False]:
+    elif selector == [False, True, True] or selector == [False, True, False]: # End and days or end
         if args.days == None:
             args.days = 1
         args.start = args.end - datetime.timedelta(days = args.days)
-    elif selector == [False, False, True]:
-        end = datetime.date.today()
-        end = datetime.datetime(start.year, start.month, start.day)
+    elif selector == [False, False, True]: # Days
+        args.end = datetime.date.today() + datetime.timedelta(days = 1)
+        args.end = datetime.datetime(args.end.year, args.end.month, args.end.day)
         args.start = args.end - datetime.timedelta(days = args.days)
+    elif selector == [False, False, False]: # Nothing
+        args.start = datetime.date.today()
+        args.start = datetime.datetime(args.start.year, args.start.month, args.start.day)
+        args.end = args.start + datetime.timedelta(days = 1)
     else:
         parser.error('can\'t specify days, start and end simultaneously')