Skip to main content

A Python package for converting time units to seconds

Project description

TimeCalculator

The TimeCalculator package is a Python package for converting time units to seconds. It provides a TimeCalculator class that can be used to convert any time unit to seconds, not just the predefined time units.

Features

The TimeCalculator package provides the following features:

  • Conversion of any time unit to seconds using the TimeCalculator class
  • Predefined time units for convenience, including:
    • MINUTE: number of seconds in a minute
    • HOUR: number of seconds in an hour
    • DAY: number of seconds in a day
    • WEEKEND: number of seconds in a weekend (2 days)
    • WORK_WEEK: number of seconds in a work week (5 days)
    • WEEK: number of seconds in a week
    • MONTH: number of seconds in a month (30 days)
    • YEAR: number of seconds in a year (365 days)

Installation

The TimeCalculator package can be installed via pip:

pip install timecalculator

Usage

To use the TimeCalculator package, you first need to create a TimeCalculator object:


from timecalculator import TimeCalculator
tc = TimeCalculator()

Once you have a TimeCalculator object, you can use the to_seconds method to convert any time unit to seconds. The to_seconds method takes two arguments: time_value and time_unit. The time_value argument is the value you want to convert, and the time_unit argument is the unit of the value, expressed in seconds.

Here's a simple example of how to use the to_seconds method to convert 5 minutes to seconds:


minutes = 5 total_seconds = tc.to_seconds(minutes, tc.MINUTE)
print(f"{minutes} minutes is {total_seconds} seconds")

In this example, we pass the value 5 and the MINUTE constant to the to_seconds method to convert the time to seconds. The resulting value is stored in the total_seconds variable. Finally, we print out the result.

The output of this code will be:

5 minutes is 300 seconds

API Reference

The TimeCalculator class provides the following methods and attributes:

to_seconds(time_value: float, time_unit: int) -> float

Convert a time value from one unit to another.

  • time_value (float): The value to convert.
  • time_unit (int): The unit of the value, in seconds.

Returns:

  • float: The converted value, in seconds.

Predefined Time Units

The TimeCalculator class provides the following predefined time units for convenience:

  • MINUTE (int): Number of seconds in a minute.
  • HOUR (int): Number of seconds in an hour.
  • DAY (int): Number of seconds in a day.
  • WEEKEND (int): Number of seconds in a weekend (2 days).
  • WORK_WEEK (int): Number of seconds in a work week (5 days).
  • WEEK (int): Number of seconds in a week.
  • MONTH (int): Number of seconds in a month (30 days).
  • YEAR (int): Number of seconds in a year (365 days).

Contributions

Contributions to the TimeCalculator package are welcome.

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

timecalculator-1.2.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

timecalculator-1.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file timecalculator-1.2.0.tar.gz.

File metadata

  • Download URL: timecalculator-1.2.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for timecalculator-1.2.0.tar.gz
Algorithm Hash digest
SHA256 1dc954feeb67426c9ee7bf2ad4098ba2b5b15fb8bfc846feeaa7b701c97e17e9
MD5 f8eed58b4ad7883a0b12062dc05c23e5
BLAKE2b-256 d179dab6b8a97673ec2e7f9e2f9c9579b4b6f7920b75047cb23ea51c9c094e37

See more details on using hashes here.

File details

Details for the file timecalculator-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for timecalculator-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60d57fc0edff4c47a9eaad8e90f1c9ce627f178505c870bc0b57d0c69f3f1434
MD5 aae8837521c555d1160b531a06ddb888
BLAKE2b-256 01a1c5c57dec69ba494ffb38a7230de574a3b9e50cf8d4297158b8a3e5107f4f

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