Skip to main content

month

https://img.shields.io/pypi/v/datetime-month.svg https://github.com/yitistica/month/actions/workflows/pre-release-test.yml/badge.svg Documentation Status

A package that handles calendar months and arithmetic operation of months.

The package comprises two modules: month and x_month. month module provides the base classes for manipulating month-level time. x_month module extends the base classes from the month module to include additional functionalities.

Installation

pip install datetime-month

Features & Usage

To construct a month object:

from month import Month
from month import XMonth  # extended month;

m = Month(2020, 4)
xm = XMonth(2020, 4)

Additional construction methods below can be used to translate a tuple (year, month), a isoformat string, an ordinal int and month-format string into a Month object.

# constructed from a (year, month) tuple:
m = Month.fromtuple((2019, 11))

# isoformat is defined as a str in "year-month" format:
m = Month.fromisoformat('2019-12')

# ordinal (as in date units):
m = Month.fromordinal(737390)

# using string format like datetime:
m = Month.strptime('2019/1', '%Y/%m')

For the representation of the difference between two months, we can use Mdelta (similar to timedelta in datetime modules). To construct:

from month import MDelta
delta = Mdelta(2)  # Mdelta(months), months: int;

Mdelta supports comparisons using operators. It also supports some arithmetic operations (addition, subtraction, and multiplication) among Mdelta objects or with Month objects or int objects.

Mdelta(2) < Mdelta(3)  # returns bool;
Mdelta(2) - Mdelta(3)  # returns Mdelta(-1);
Mdelta(2) * 2 # returns Mdelta(4);

Some arithmetic operations and comparisons are also supported for Month objects.

Month(2019, 11).add(MDelta(2)) # returns Month(2020, 1);
Month(2020, 04) + Mdelta(2)  # returns Month(2020, 6);
Month(2020, 1) - 2  # returns Month(2019, 11);
Month(2020, 04) <= Month(2020, 06)  # returns True;

XMonth is an extended version of Month by including some convenient manipulation and sub-level operations.

xm = XMonth(2019, 11)

xm.days()  # returns total days in the month;

xm.first_date()  # returns date(2019,11,1)

# iterate dates within the month in increment by step days:
xm.dates(step=2)

# iterate months in a given range:
XMonth.range(starting_month, ending_month, step=1)

License

  • Free software: MIT license

Credits

The repo was initiated using audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2020-03-21)

  • First release on PyPI.

1.0.3 (2022-10-11)

  • FIX: Fix wrong package metadata in setup - #2.

1.0.4 (2022-11-10)

  • FIX: Fix arithmetic operation on XMonth returning base class Month object instead of XMonth - #8. Contributed by @ramwin. Thank you!

1.0.5 (2024-02-15)

  • Add compatibility with Python 3.11 & 3.12.

1.0.6 (2024-02-15)

  • Fix ReadMe note.

Metadata

Release files for datetime-month 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datetime-month 1.0.6
File Size Uploaded Provenance Actions
datetime-month-1.0.6.tar.gz 16.2 kB Without provenance Details for datetime-month-1.0.6.tar.gz

Release files / datetime-month-1.0.6.tar.gz

Download URL datetime-month-1.0.6.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
72660fddf59b168c5161e24afe757bfa71d702efa1004af1f628a8d0f350b4b6
BLAKE2b-256 checksum
How to use checksums
7e93cb848b6806837b0eb98db3dece687b9280672a55e7aeace71244c63bba9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Security for datetime-month 1.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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