Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to reST #13

Merged
merged 3 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 0 additions & 39 deletions CHANGELOG.md

This file was deleted.

31 changes: 31 additions & 0 deletions CHANGELOG.rst
@@ -0,0 +1,31 @@
Changelog
=========

All notable changes to this project will be documented in this file.

v0.4.0
------

- ``YearMonth.current()`` now accepts a ``tz`` argument to specify the timezone.
- Made ``YearMonth`` instances immutable.

v0.3.1
------

- Use ``__slots__`` to optimize memory usage.

v0.3.0
------

- Added ``YearMonth.distance_to()`` method for calculating the distance between two ``YearMonth`` instances.

v0.2.0
------

- Added support for membership test operators (`in` and `not in`) for checking if a `date` or `datetime` falls within a `YearMonth`.
- Improved ``YearMonth.parse()`` performance.

v0.1.0
------

- Initial release.
83 changes: 0 additions & 83 deletions README.md

This file was deleted.

96 changes: 96 additions & 0 deletions README.rst
@@ -0,0 +1,96 @@
mp-yearmonth
============

A year-month datatype for Python.

Installation
------------

.. code-block:: bash

pip install mp-yearmonth


Usage
-----

.. code-block:: python

from mp_yearmonth import YearMonth

ym = YearMonth(2019, 1)
print(ym) # 2019-01

Getting the current year-month
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

ym = YearMonth.current()


You can also specify a timezone using the `tz` argument:

.. code-block:: python

import pytz

ym = YearMonth.current(tz=pytz.timezone("Asia/Tokyo"))


Parsing ISO 8601 strings
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

ym = YearMonth.parse("2019-01")

print(ym.year) # 2019
print(ym.month) # 1

Comparing year-months
^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

ym1 = YearMonth(2019, 1)
ym2 = YearMonth(2019, 2)

print(ym1 == ym2) # False
print(ym1 < ym2) # True

Adding or subtracting months
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

ym = YearMonth(2019, 1)
ym += 1

print(ym) # 2019-02

Iterating over a range of year-months
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

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 <https://github.com/raymondjavaxx/mp-yearmonth/blob/main/LICENSE>`_ for details.
4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -4,8 +4,8 @@ version = "0.4.0"
description = "A year-month datatype for Python."
keywords = ["year", "month", "date", "calendar"]
authors = ["Ramon Torres <ramon@macropoetry.com>"]
readme = "README.md"
include = ["LICENSE", "CHANGELOG.md"]
readme = "README.rst"
include = ["LICENSE", "CHANGELOG.rst"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand Down