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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Get stats about your activity. 6 """Get stats about your activity.
7 7
8 Example: 8 Example:
9 - my_activity.py for stats for the current week (last week on mondays). 9 - my_activity.py for stats for the current week (last week on mondays).
10 - my_activity.py -Q for stats for last quarter. 10 - my_activity.py -Q for stats for last quarter.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 error = e 135 error = e
136 136
137 raise error 137 raise error
138 138
139 139
140 def username(email): 140 def username(email):
141 """Keeps the username of an email address.""" 141 """Keeps the username of an email address."""
142 return email and email.split('@', 1)[0] 142 return email and email.split('@', 1)[0]
143 143
144 144
145 def datetime_to_midnight(date):
146 return date - timedelta(hours=date.hour, minutes=date.minute,
147 seconds=date.second, microseconds=date.microsecond)
148
149
145 def get_quarter_of(date): 150 def get_quarter_of(date):
146 begin = date - relativedelta(months=(date.month % 3) - 1, days=(date.day - 1)) 151 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'
152 relativedelta(months=(date.month % 3) - 1, days=(date.day - 1)))
147 return begin, begin + relativedelta(months=3) 153 return begin, begin + relativedelta(months=3)
148 154
149 155
150 def get_year_of(date): 156 def get_year_of(date):
151 begin = date - relativedelta(months=(date.month - 1), days=(date.day - 1)) 157 begin = (datetime_to_midnight(date) -
158 relativedelta(months=(date.month - 1), days=(date.day - 1)))
152 return begin, begin + relativedelta(years=1) 159 return begin, begin + relativedelta(years=1)
153 160
154 161
155 def get_week_of(date): 162 def get_week_of(date):
156 begin = date - timedelta(days=date.weekday()) 163 begin = (datetime_to_midnight(date) - timedelta(days=date.weekday()))
157 return begin, begin + timedelta(days=7) 164 return begin, begin + timedelta(days=7)
158 165
159 166
160 def get_yes_or_no(msg): 167 def get_yes_or_no(msg):
161 while True: 168 while True:
162 response = raw_input(msg + ' yes/no [no] ') 169 response = raw_input(msg + ' yes/no [no] ')
163 if response == 'y' or response == 'yes': 170 if response == 'y' or response == 'yes':
164 return True 171 return True
165 elif not response or response == 'n' or response == 'no': 172 elif not response or response == 'n' or response == 'no':
166 return False 173 return False
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 print '\n\n\n' 660 print '\n\n\n'
654 661
655 my_activity.print_changes() 662 my_activity.print_changes()
656 my_activity.print_reviews() 663 my_activity.print_reviews()
657 my_activity.print_issues() 664 my_activity.print_issues()
658 return 0 665 return 0
659 666
660 667
661 if __name__ == '__main__': 668 if __name__ == '__main__':
662 sys.exit(main()) 669 sys.exit(main())
OLDNEW
« 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