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

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.1.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.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_hour-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 23e2ece543d9cff687957a4ed81c8e1e360494e338b045518472943d6973ac58
MD5 16e92ff6ad37210734a6d13551ac1fa6
BLAKE2b-256 37aa1770eca0408da851aa775e9021831c3309b2ad09367b12aca9ef917749ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_hour-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eeb93056ed7a63ec7afa28f5bcdd6b39b1e56ba201ab770cdeccefda74b46f82
MD5 a04d5272d53c35a3b07aa63a92444f23
BLAKE2b-256 5e0071aa2a61c0b4680fb0b1b3426eadb0b7e835113f09099babd158e13989b1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

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