comparison graph.py @ 11:e1bec6dfd524

Improve start/end/days handling
author Daniel O'Connor <darius@dons.net.au>
date Fri, 22 Dec 2017 13:19:43 +0100
parents 3f5b617b4715
children 2b115732f4bc
comparison
equal deleted inserted replaced
10:3f5b617b4715 11:e1bec6dfd524
65 if args.days is not None and args.days < 0: 65 if args.days is not None and args.days < 0:
66 parser.error('days must be non-negative') 66 parser.error('days must be non-negative')
67 67
68 # Can specify.. 68 # Can specify..
69 # Start and end 69 # Start and end
70 # Start and days 70 # Start and days or Start
71 # End and days 71 # End and days or End
72 # Nothing 72 # Nothing
73 # Want to end up with a start & end 73 # Want to end up with a start & end
74 if args.start is not None and args.end is not None: 74 selector = [args.start is not None, args.end is not None, args.days is not None]
75 if selector == [True, True, False]:
75 pass 76 pass
76 elif args.start is not None and args.days is not None: 77 elif selector == [True, False, True] or selector == [True, False, False]:
78 if args.days == None:
79 args.days = 1
77 args.end = args.start + datetime.timedelta(days = args.days) 80 args.end = args.start + datetime.timedelta(days = args.days)
78 elif args.end is not None and args.days is not None: 81 elif selector == [False, True, True] or selector == [False, True, False]:
82 if args.days == None:
83 args.days = 1
79 args.start = args.end - datetime.timedelta(days = args.days) 84 args.start = args.end - datetime.timedelta(days = args.days)
80 elif args.start is None and args.end is None and args.days is None: 85 elif selector == [False, False, True]:
81 end = datetime.date.today() 86 end = datetime.date.today()
82 end = datetime.datetime(start.year, start.month, start.day) 87 end = datetime.datetime(start.year, start.month, start.day)
83 args.start = args.end - datetime.timedelta(days = args.days) 88 args.start = args.end - datetime.timedelta(days = args.days)
84 else: 89 else:
85 parser.error('can\'t specify days, start and end simultaneously') 90 parser.error('can\'t specify days, start and end simultaneously')