A year-month datatype for Python.
Installation
pip install mp-yearmonth
Usage
from mp_yearmonth import YearMonth
ym = YearMonth(2019, 1)
print(ym) # 2019-01
Getting the current year-month
ym = YearMonth.current()
You can also specify a timezone using the tz argument:
import pytz
ym = YearMonth.current(tz=pytz.timezone("Asia/Tokyo"))
Parsing ISO 8601 strings
ym = YearMonth.parse("2019-01")
print(ym.year) # 2019
print(ym.month) # 1
Comparing year-months
ym1 = YearMonth(2019, 1)
ym2 = YearMonth(2019, 2)
print(ym1 == ym2) # False
print(ym1 < ym2) # True
Adding or subtracting months
ym = YearMonth(2019, 1)
ym += 1
print(ym) # 2019-02
Iterating over a range of year-months
ym1 = YearMonth(2019, 1)
ym2 = YearMonth(2019, 3)
for ym in YearMonth.range(ym1, ym2):
print(ym) # 2019-01, 2019-02, 2019-03
Calculating the distance between two year-months
ym1 = YearMonth(2019, 1)
ym2 = YearMonth(2019, 3)
distance = ym1.distance_to(ym2) # 2
License
mp-yearmonth is licensed under the MIT license. See LICENSE for details.
Release files for mp-yearmonth 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mp_yearmonth-0.5.0.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mp_yearmonth-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / mp_yearmonth-0.5.0.tar.gz
| Download URL | mp_yearmonth-0.5.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
79db81f5ee01039a8ca9979a1ba98a3e66cab7b5012d3ab138a0b132bfcaa23d
|
|
BLAKE2b-256 checksum How to use checksums |
dd00e482819a6894767b9d95d4c450d93aa97be12d91b94efccf4202d66c56dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / mp_yearmonth-0.5.0-py3-none-any.whl
| Download URL | mp_yearmonth-0.5.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af2eadccfbc2122dece15f43773570910d76010d1ec4624670c5c0a64c06662b
|
|
BLAKE2b-256 checksum How to use checksums |
adf653629a19c7eb5081e83e5d662d7b82327801d291d7f2444dab30271346f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|