From 875aeb4f03e087ab26390bacaea888c546bad07d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 3 Dec 2012 18:11:29 +0100 Subject: [PATCH] begin to do more clever default date selection Signed-off-by: Nico Schottelius --- lib/ctt/__init__.py | 3 +-- lib/ctt/report.py | 25 ++++++++----------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/ctt/__init__.py b/lib/ctt/__init__.py index 9a4c103..64427a9 100644 --- a/lib/ctt/__init__.py +++ b/lib/ctt/__init__.py @@ -63,8 +63,7 @@ def ctt_dir(): return ctt_dir def project_dir(project): - ctt_dir = ctt_dir() - project_dir = os.path.join(ctt_dir, project) + project_dir = os.path.join(ctt_dir(), project) return project_dir diff --git a/lib/ctt/report.py b/lib/ctt/report.py index 01675ad..7e1bb01 100755 --- a/lib/ctt/report.py +++ b/lib/ctt/report.py @@ -54,16 +54,22 @@ class Report(object): def _init_date(self, start_date, end_date): """Setup date - either default or user given values""" + + now = datetime.datetime.now() + first_day = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0) + default_end_date = first_day - datetime.timedelta(days=1) + default_start_date = default_end_date.replace(day=1) + try: if start_date: self.start_date = datetime.datetime.strptime(start_date[0], ctt.DATEFORMAT) else: - self.start_date = self.default_dates()[0] + self.start_date = default_start_date if end_date: self.end_date = datetime.datetime.strptime(end_date[0], ctt.DATEFORMAT) else: - self.end_date = self.default_dates()[1] + self.end_date = default_end_date except ValueError as e: raise ctt.Error(e) @@ -150,18 +156,3 @@ class Report(object): print("%s (%s): %s" % (start_datetime, delta, comment)) else: print("%s (%s)" % (start_datetime, delta)) - - - @staticmethod - def default_dates(): - """Return default start and end of of time - start: first of last month - end: last of last month - """ - - now = datetime.datetime.now() - first_day = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0) - end_date = first_day - datetime.timedelta(days=1) - start_date = end_date.replace(day=1) - - return (start_date, end_date)