mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Generated by `pyupgrade --py3-plus --keep-percent-format` on all our Python code except `zthumbor` and `zulip-ec2-configure-interfaces`, followed by manual indentation fixes. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
17 lines
691 B
Python
17 lines
691 B
Python
from zerver.models import UserProfile, UserActivityInterval
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
# 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
|