Skip to main content

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)

Source distribution for mp-yearmonth 0.5.0
File Size Uploaded
mp_yearmonth-0.5.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mp-yearmonth 0.5.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page