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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: timecalculator-1.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 1d18524b1b819c7bdabbf89eb68c2dc6ecf9baf16615c8c4ac5892dca1b4b70f
MD5 1a17af779cf5a0abe14be4ddfdb4abcb
BLAKE2b-256 eb8951119e01e35dfbe023cc10bce0fde19fdfb7b405bfedc365b691a7d708fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for timecalculator-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d5808f71b24af8fc3709ad1b83608dbf48fbd15323e6b2112d645952eeadac4
MD5 478bce764e948ec070aac8de905f6113
BLAKE2b-256 ef816b7f69da3d5938c7bbd7dc2970e0876a46fc4a017fdd6e91898e3907c60f

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