Commit 426557ad authored by cjhopman@chromium.org's avatar cjhopman@chromium.org

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
parent 370a623c
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment