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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: simpleslacalc-0.0.61.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.61.tar.gz
Algorithm Hash digest
SHA256 bc8d8c8895ad54806d8d0d529d32196198b05b6d9e6f166112044c6579d7cd1f
MD5 cec813b4c4575895fb302b0a98d05a2d
BLAKE2b-256 5648e0262299e947139f8bfd83b289a8c925441cd65111d3e971939ddc738a50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simpleslacalc-0.0.61-py3-none-any.whl
Algorithm Hash digest
SHA256 6c628a845fe3092edc742615ea0bdfc4ec05c313d68ebb38b4050d34e781c63b
MD5 e4b47de664b59ff8ea1a3a5b6cede6f8
BLAKE2b-256 521b3bcb5e19cd67c3c53042b06d301ef9461ecb3d4497f63fd026d922d0e5ca

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