Skip to main content

Simple SLA Calculator

Project description

Simple SLA Calculator

A very simple and rudimentary SLA timeframe calculator.

Installation

pip install SimpleSLACalc

Usage

To calculate an SLA you need to provide a minimum set of parameters.

  • start_time (datetime | pendulum.DateTime | str): Start of sla time calculation(IE: "2023-10-01") or a datetime object
  • open_hour (int): Start of business hour(24h format)
  • open_minute (int): Start of business minute
  • close_hour (int): End of business hour(24h format)
  • close_minute (int): End of business minute
  • time_zone (str): Timezone in which to process calculation
  • sla_hours (Optional[int], optional): Provide hours to calculate SLA in hours. Defaults to None.
  • sla_days (Optional[int], optional): Provide days to calculate SLA in days. Defaults to None.
  • sla_weeks (Optional[int], optional): Provide weeks to calculate SLA in weeks. Defaults to None.

NOTE: Only provide one sla_hours, sla_days, or sla_weeks. Do not combine

Additionally you can provide a number of optional parameters to fine tune your SLA calculations. Most notable here is skip_business_hours. By default business hours are ignored. It will return only the raw SLA calculation including weekends, and holidays. To only calculate business hours SLA's, set to False.

  • skip_business_hours (Optional[bool]): When True, skips business hours, and just calculates raw SLA. Defaults to True.
  • excluded_dates (Optional[list[str]], optional): Provide a list of dates in string format(IE: ["2023-10-1", 2023-10-02"]). Defaults to None.
  • holiday_country (Optional[str], optional): Two character country code for holiday parsing. Required for holiday date SLA exclusion. Defaults to None.
  • holiday_state (Optional[str], optional): Optional two character state for holiday date SLA exclusion. Defaults to None.
  • holiday_province (Optional[str], optional): Optional two character province for holiday date SLA exclusion. Defaults to None.
from SimpleSLACalc import SLACalculator

my_sla_cal = SLACalculator()
sla_values = my_sla_cal.calculate(
    start_time="2023-10-18 01:27",
    open_hour=9,
    open_minute=0
    close_hour=17,
    close_minute=0,
    sla_hours=6,
    time_zone="America/Chicago",
    skip_business_hours=False
)

print(sla_values.sla_expiration_time)

The output of the above code snippet looks as follows.

❯ python tests/test.py
2023-10-18 15:00:00-05:00

The output object is a class object named SLAItem with a range of values available for use. It appears like this in code.

@dataclass(frozen=True, order=False)
class SLAItem:
    """Class based SLA results item for user return

    Returns:
        cls: Class Object populated with SLA results calculations
    """

    start_time: pendulum.DateTime
    open_time: pendulum.DateTime | None
    close_time: pendulum.DateTime | None
    sla_expiration_time: pendulum.DateTime

    def sla_exp_hour(self) -> int:
        return self.sla_expiration_time.hour

    def sla_exp_min(self) -> int:
        return self.sla_expiration_time.minute

    def sla_exp_day(self) -> int:
        return self.sla_expiration_time.day

    def sla_exp_date(self) -> pendulum.Date:
        return self.sla_expiration_time.date()

    def __repr__(self) -> str:
        return str(self.sla_expiration_time)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpleslacalc-0.0.62.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

simpleslacalc-0.0.62-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file simpleslacalc-0.0.62.tar.gz.

File metadata

  • Download URL: simpleslacalc-0.0.62.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.1

File hashes

Hashes for simpleslacalc-0.0.62.tar.gz
Algorithm Hash digest
SHA256 1d269d688a3bf1e63e18b443406c99e5febe4c01fd62c151ab4880891295b695
MD5 b23edb249197099310e6c18450b10495
BLAKE2b-256 5d658fc1fe434d7c32014116b08683037f78ed7f088b4ffb776510da28e8af89

See more details on using hashes here.

File details

Details for the file simpleslacalc-0.0.62-py3-none-any.whl.

File metadata

File hashes

Hashes for simpleslacalc-0.0.62-py3-none-any.whl
Algorithm Hash digest
SHA256 73bc4eae134584c77f97e60a03067e735486255b684940632a7736e6bbe2dddd
MD5 571c658c9224657dba7675fd74713922
BLAKE2b-256 85163863605d7a94098613d28e4740cbbaefe7ab9720a2373309c5103d4289e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page