From 426557ad35bf7357f030ae55f00118e6c2a2654f Mon Sep 17 00:00:00 2001 From: "cjhopman@chromium.org" Date: Mon, 22 Oct 2012 20:18:52 +0000 Subject: [PATCH] Fix week_of, quarter_of, year_of calculation These calculations were not dropping the time from the provided date. And so a week would be Monday 11AM to Monday 11AM when run at 11AM. BUG= Review URL: https://chromiumcodereview.appspot.com/11233041 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@163360 0039d316-1c4b-4281-b951-d872f2087c98 --- my_activity.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/my_activity.py b/my_activity.py index 66b5c2da7e..540af78d18 100755 --- a/my_activity.py +++ b/my_activity.py @@ -142,18 +142,25 @@ def username(email): return email and email.split('@', 1)[0] +def datetime_to_midnight(date): + return date - timedelta(hours=date.hour, minutes=date.minute, + seconds=date.second, microseconds=date.microsecond) + + def get_quarter_of(date): - begin = date - relativedelta(months=(date.month % 3) - 1, days=(date.day - 1)) + begin = (datetime_to_midnight(date) - + relativedelta(months=(date.month % 3) - 1, days=(date.day - 1))) return begin, begin + relativedelta(months=3) def get_year_of(date): - begin = date - relativedelta(months=(date.month - 1), days=(date.day - 1)) + begin = (datetime_to_midnight(date) - + relativedelta(months=(date.month - 1), days=(date.day - 1))) return begin, begin + relativedelta(years=1) def get_week_of(date): - begin = date - timedelta(days=date.weekday()) + begin = (datetime_to_midnight(date) - timedelta(days=date.weekday())) return begin, begin + timedelta(days=7)