Skip to main content

Hour

Simple python library to do hour and minutes mathematical operations. It consists of a class Hour(HH, MM) that can be operated and compared with other Hour instances.

Installation

This project is available in PyPI: https://pypi.org/project/simple_hour

You can install it in your machine by just doing:

pip install simple_hour

Usage

from simple_hour import Hour

a = Hour(12, 30)  # 12h and 30min
b = Hour(8, 25)   # 8h and 25min

c = a + b  # c will be Hour(20, 55)
print(c)   # Prints "20:55"

d = a - b # d will be Hour(4, 5)
print(d)          # Prints "04:05"
print(d.hours)    # Prints "4"
print(d.minutes)  # Prints "5"
print(d.absolute_minutes())  # Prints "245"
print(d.absolute_hours())    # Prints "4.083333333333333"

print(Hour(0, 125))  # 125min gets converted to Hour(2, 5)
print(Hour(1.5, 0))  # 1.5h gets converted to Hour(1, 30)

Notes

You can have over 24 hours. This library does not handle days

from simple_hour import Hour

a = Hour(32, 25)  # 32h and 25min
print(a)          # Prints "32:25"

You can always obtain a 24h Hour by using the mod % operator:

from simple_hour import Hour

a = Hour(32, 25)
b = a % Hour(24)
print(b)  # Prints "08:25"

Negative hours are possible:

from simple_hour import Hour

a = Hour(-2, 10)  # -2h + 10min
b = Hour(3)       # 3h
print(a + b)      # Prints "01:10"

print(-a)         # Prints "01:50"
print(abs(a.absolute_minutes()) == ((-a).absolute_minutes())) # True

The operation bool(Hour(...)) always returns True regardless of the hours and minutes.

LICENSE

This project is licenced under the Mozilla Public License version 2.0. You may obtain a copy of the licence at the LICENCE file in this repository, or online at https://www.mozilla.org/en-US/MPL/2.0/.

Metadata

Release files for simple-hour 1.0.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 simple-hour 1.0.1
File Size Uploaded Provenance Actions
simple_hour-1.0.1.tar.gz 8.2 kB Without provenance Details for simple_hour-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-hour 1.0.1
File Interpreter ABI Platform Actions
simple_hour-1.0.1-py3-none-any.whl Python 3 none any Details for simple_hour-1.0.1-py3-none-any.whl

Total release size: 16.8 kB

Release files / simple_hour-1.0.1.tar.gz

Download URL simple_hour-1.0.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
23e2ece543d9cff687957a4ed81c8e1e360494e338b045518472943d6973ac58
BLAKE2b-256 checksum
How to use checksums
37aa1770eca0408da851aa775e9021831c3309b2ad09367b12aca9ef917749ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / simple_hour-1.0.1-py3-none-any.whl

Download URL simple_hour-1.0.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eeb93056ed7a63ec7afa28f5bcdd6b39b1e56ba201ab770cdeccefda74b46f82
BLAKE2b-256 checksum
How to use checksums
5e0071aa2a61c0b4680fb0b1b3426eadb0b7e835113f09099babd158e13989b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for simple-hour 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

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