Skip to main content

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.

Release files for timecalculator 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timecalculator 1.2.1
File Size Uploaded
timecalculator-1.2.1.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for timecalculator 1.2.1
File Interpreter ABI Platform
timecalculator-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / timecalculator-1.2.1.tar.gz

Download URL timecalculator-1.2.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1d18524b1b819c7bdabbf89eb68c2dc6ecf9baf16615c8c4ac5892dca1b4b70f
BLAKE2b-256 checksum
How to use checksums
eb8951119e01e35dfbe023cc10bce0fde19fdfb7b405bfedc365b691a7d708fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / timecalculator-1.2.1-py3-none-any.whl

Download URL timecalculator-1.2.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d5808f71b24af8fc3709ad1b83608dbf48fbd15323e6b2112d645952eeadac4
BLAKE2b-256 checksum
How to use checksums
ef816b7f69da3d5938c7bbd7dc2970e0876a46fc4a017fdd6e91898e3907c60f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.9

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page