A year-month datatype for Python.
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mp_yearmonth-0.5.0.tar.gz
(4.2 kB
view details)
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 mp_yearmonth-0.5.0.tar.gz.
File metadata
- Download URL: mp_yearmonth-0.5.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79db81f5ee01039a8ca9979a1ba98a3e66cab7b5012d3ab138a0b132bfcaa23d
|
|
| MD5 |
0b18923e490c7543a7d8c9e1029ca205
|
|
| BLAKE2b-256 |
dd00e482819a6894767b9d95d4c450d93aa97be12d91b94efccf4202d66c56dd
|
File details
Details for the file mp_yearmonth-0.5.0-py3-none-any.whl.
File metadata
- Download URL: mp_yearmonth-0.5.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af2eadccfbc2122dece15f43773570910d76010d1ec4624670c5c0a64c06662b
|
|
| MD5 |
bc8e18079fed31d2574c6846f2c14e19
|
|
| BLAKE2b-256 |
adf653629a19c7eb5081e83e5d662d7b82327801d291d7f2444dab30271346f6
|