2013-10-17 00:12:30 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
2016-01-24 03:56:05 +01:00
|
|
|
from __future__ import division
|
2013-10-17 00:12:30 +02:00
|
|
|
|
2013-10-18 17:40:16 +02:00
|
|
|
from zerver.models import UserProfile, UserActivity, UserActivityInterval, Message
|
2013-10-17 00:12:30 +02:00
|
|
|
|
|
|
|
from django.utils.timezone import utc
|
2016-06-27 14:33:29 +02:00
|
|
|
from typing import Any, Dict, List, Sequence, Set
|
2016-03-22 06:52:36 +01:00
|
|
|
|
|
|
|
from datetime import datetime, timedelta
|
2013-10-17 00:12:30 +02:00
|
|
|
|
|
|
|
# Return the amount of Zulip usage for this user between the two
|
|
|
|
# given dates
|
|
|
|
def seconds_usage_between(user_profile, begin, end):
|
2016-03-22 06:52:36 +01:00
|
|
|
# type: (UserProfile, datetime, datetime) -> timedelta
|
2013-10-17 00:12:30 +02:00
|
|
|
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
|