Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: my_activity.py

Issue 11233041: Fix week_of, quarter_of, year_of calculation in my_activity.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: my_activity.py
diff --git a/my_activity.py b/my_activity.py
index 66b5c2da7e2520b8462550675382e03ebdea119d..540af78d18bf89ea0af1c4ba8abcb834611ad105 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) -
M-A Ruel 2012/10/22 18:43:14 Why not date.date() or simply use datetime.date th
cjhopman 2012/10/22 18:56:21 I didn't use date.date() here because later on we
M-A Ruel 2012/10/22 19:09:09 I prefer simple code to simple fixes. Also I don'
+ 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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698