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.
- Author: LluisE
- Website: https://kitsune.cat
- Source: https://github.com/lluises/hour
- Licence: https://www.mozilla.org/en-US/MPL/2.0/
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
683081af373cb4aafd6823114afeebb8686c3690dcc76166aeab8849224b600f
|
|
| MD5 |
6f25393caadf70f062b6807f0f29d180
|
|
| BLAKE2b-256 |
38186e94e4f37bc199baa3c36be9bc7881c4a67b74d9d982b92345e2d6b09de3
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df659b117507bcccc931c70974b0e1be628f20b112dfb73b320225e2f9620bfd
|
|
| MD5 |
6fc9774ddb1d3288b6a9884d64fb34b5
|
|
| BLAKE2b-256 |
35a136a156fd46f1b5c34539dd69dcf9430c5cb94480821b4b2880615eb9dda9
|