mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
18 lines
692 B
Python
18 lines
692 B
Python
from datetime import datetime, timedelta
|
|
|
|
from zerver.models import UserActivityInterval, UserProfile
|
|
|
|
|
|
# Return the amount of Zulip usage for this user between the two
|
|
# given dates
|
|
def seconds_usage_between(user_profile: UserProfile, begin: datetime, end: datetime) -> timedelta:
|
|
intervals = UserActivityInterval.objects.filter(user_profile=user_profile,
|
|
end__gte=begin,
|
|
start__lte=end)
|
|
duration = timedelta(0)
|
|
for interval in intervals:
|
|
start = max(begin, interval.start)
|
|
finish = min(end, interval.end)
|
|
duration += finish-start
|
|
return duration
|