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/hour

You can install it in your machine by just doing:

pip install hour

Usage

from 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 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 hour import Hour

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


Negative hours are possible:

```python
from 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/.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_hour-1.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_hour-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_hour-1.0.0.tar.gz.

File metadata

  • Download URL: simple_hour-1.0.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for simple_hour-1.0.0.tar.gz
Algorithm Hash digest
SHA256 683081af373cb4aafd6823114afeebb8686c3690dcc76166aeab8849224b600f
MD5 6f25393caadf70f062b6807f0f29d180
BLAKE2b-256 38186e94e4f37bc199baa3c36be9bc7881c4a67b74d9d982b92345e2d6b09de3

See more details on using hashes here.

File details

Details for the file simple_hour-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: simple_hour-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for simple_hour-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df659b117507bcccc931c70974b0e1be628f20b112dfb73b320225e2f9620bfd
MD5 6fc9774ddb1d3288b6a9884d64fb34b5
BLAKE2b-256 35a136a156fd46f1b5c34539dd69dcf9430c5cb94480821b4b2880615eb9dda9

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page