mp-yearmonth


Namemp-yearmonth JSON
Version 0.5.0 PyPI version JSON
download
home_page
SummaryA year-month datatype for Python.
upload_time2024-03-15 01:44:15
maintainer
docs_urlNone
authorRamon Torres
requires_python>=3.7,<4.0
license
keywords year month date calendar
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mp-yearmonth",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "year,month,date,calendar",
    "author": "Ramon Torres",
    "author_email": "ramon@macropoetry.com",
    "download_url": "https://files.pythonhosted.org/packages/dd/00/e482819a6894767b9d95d4c450d93aa97be12d91b94efccf4202d66c56dd/mp_yearmonth-0.5.0.tar.gz",
    "platform": null,
    "description": "mp-yearmonth\n============\n\nA year-month datatype for Python.\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    pip install mp-yearmonth\n\n\nUsage\n-----\n\n.. code-block:: python\n\n    from mp_yearmonth import YearMonth\n\n    ym = YearMonth(2019, 1)\n    print(ym) # 2019-01\n\nGetting the current year-month\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    ym = YearMonth.current()\n\n\nYou can also specify a timezone using the `tz` argument:\n\n.. code-block:: python\n\n    import pytz\n\n    ym = YearMonth.current(tz=pytz.timezone(\"Asia/Tokyo\"))\n\n\nParsing ISO 8601 strings\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    ym = YearMonth.parse(\"2019-01\")\n\n    print(ym.year) # 2019\n    print(ym.month) # 1\n\nComparing year-months\n^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    ym1 = YearMonth(2019, 1)\n    ym2 = YearMonth(2019, 2)\n\n    print(ym1 == ym2) # False\n    print(ym1 < ym2) # True\n\nAdding or subtracting months\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    ym = YearMonth(2019, 1)\n    ym += 1\n\n    print(ym) # 2019-02\n\nIterating over a range of year-months\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    ym1 = YearMonth(2019, 1)\n    ym2 = YearMonth(2019, 3)\n\n    for ym in YearMonth.range(ym1, ym2):\n        print(ym) # 2019-01, 2019-02, 2019-03\n\nCalculating the distance between two year-months\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    ym1 = YearMonth(2019, 1)\n    ym2 = YearMonth(2019, 3)\n\n    distance = ym1.distance_to(ym2) # 2\n\nLicense\n-------\n\nmp-yearmonth is licensed under the MIT license. See `LICENSE <https://github.com/raymondjavaxx/mp-yearmonth/blob/main/LICENSE>`_ for details.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A year-month datatype for Python.",
    "version": "0.5.0",
    "project_urls": {
        "homepage": "https://github.com/raymondjavaxx/mp-yearmonth",
        "repository": "https://github.com/raymondjavaxx/mp-yearmonth",
        "tracker": "https://github.com/raymondjavaxx/mp-yearmonth/issues"
    },
    "split_keywords": [
        "year",
        "month",
        "date",
        "calendar"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "adf653629a19c7eb5081e83e5d662d7b82327801d291d7f2444dab30271346f6",
                "md5": "bc8e18079fed31d2574c6846f2c14e19",
                "sha256": "af2eadccfbc2122dece15f43773570910d76010d1ec4624670c5c0a64c06662b"
            },
            "downloads": -1,
            "filename": "mp_yearmonth-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bc8e18079fed31d2574c6846f2c14e19",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 5921,
            "upload_time": "2024-03-15T01:44:13",
            "upload_time_iso_8601": "2024-03-15T01:44:13.483254Z",
            "url": "https://files.pythonhosted.org/packages/ad/f6/53629a19c7eb5081e83e5d662d7b82327801d291d7f2444dab30271346f6/mp_yearmonth-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd00e482819a6894767b9d95d4c450d93aa97be12d91b94efccf4202d66c56dd",
                "md5": "0b18923e490c7543a7d8c9e1029ca205",
                "sha256": "79db81f5ee01039a8ca9979a1ba98a3e66cab7b5012d3ab138a0b132bfcaa23d"
            },
            "downloads": -1,
            "filename": "mp_yearmonth-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0b18923e490c7543a7d8c9e1029ca205",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 4192,
            "upload_time": "2024-03-15T01:44:15",
            "upload_time_iso_8601": "2024-03-15T01:44:15.100863Z",
            "url": "https://files.pythonhosted.org/packages/dd/00/e482819a6894767b9d95d4c450d93aa97be12d91b94efccf4202d66c56dd/mp_yearmonth-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-15 01:44:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "raymondjavaxx",
    "github_project": "mp-yearmonth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mp-yearmonth"
}
        
Elapsed time: 0.47957s