def calc_sla_duration()

in server/app/plugins/jirastats.py [0:0]


    def calc_sla_duration(from_epoch, to_epoch):
        """Calculates the active SLA time (in seconds) between two durations, discounting weekends"""
        should_discount = config.reporting.jira.get("sla_discount_weekend")
        seconds_spent = to_epoch - from_epoch  # Add seconds between the two transitions
        if should_discount:
            dt_start = datetime.datetime.utcfromtimestamp(from_epoch)
            dt_end = datetime.datetime.utcfromtimestamp(to_epoch)
            total_discount = 0
            dt_temp = dt_start
            while dt_temp < dt_end and total_discount < seconds_spent:
                dt_temp += datetime.timedelta(seconds=DEFAULT_DISCOUNT_DELTA)
                if (
                    dt_temp.weekday() in [5, 6]  # Sat, Sun
                    or (dt_temp.weekday() == 4 and dt_temp.hour > 20)  # Fri after 8pm UTC
                    or (dt_temp.weekday() == 0 and dt_temp.hour < 8)  # Mon before 8am UTC
                ):
                    total_discount += DEFAULT_DISCOUNT_DELTA
            seconds_spent -= min(seconds_spent, total_discount)
        return seconds_spent