2016-03-22 06:52:36 +01:00
|
|
|
from datetime import datetime, timedelta
|
2013-10-17 00:12:30 +02:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import UserActivityInterval, UserProfile
|
|
|
|
|
|
|
|
|
2013-10-17 00:12:30 +02:00
|
|
|
# Return the amount of Zulip usage for this user between the two
|
|
|
|
# given dates
|
2017-11-27 05:27:04 +01:00
|
|
|
def seconds_usage_between(user_profile: UserProfile, begin: datetime, end: datetime) -> timedelta:
|
2017-11-10 03:34:13 +01:00
|
|
|
intervals = UserActivityInterval.objects.filter(user_profile=user_profile,
|
|
|
|
end__gte=begin,
|
|
|
|
start__lte=end)
|
2013-10-17 00:12:30 +02:00
|
|
|
duration = timedelta(0)
|
|
|
|
for interval in intervals:
|
|
|
|
start = max(begin, interval.start)
|
|
|
|
finish = min(end, interval.end)
|
|
|
|
duration += finish-start
|
|
|
|
return duration
|