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.63.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for simpleslacalc-0.0.63.tar.gz
Algorithm Hash digest
SHA256 eb55bfc45154d8e891c409e49bf27324067653804c5130b9899020e70cb3fb53
MD5 18d6890cbb0fcd14ae5f57822c121dde
BLAKE2b-256 29557ad370813c418f57eb5e3017518463a24d56a8e3762ffc76217baf51f552

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simpleslacalc-0.0.63-py3-none-any.whl
Algorithm Hash digest
SHA256 da36cdbe87ce26b1e85cd45c91760298dd678ac6ea3c138c9b9772a3f568ca45
MD5 4f3376338b68e6fcb20aefb0b9c35797
BLAKE2b-256 accd94420569b45e93fd39b045face37b5bcfc7a1709696dbd3e92798d6ea95a

See more details on using hashes here.

Supported by

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