jdatetime


Namejdatetime JSON
Version 5.0.0 PyPI version JSON
download
home_pagehttps://github.com/slashmili/python-jalali
SummaryJalali datetime binding for python
upload_time2024-03-26 09:52:33
maintainerNone
docs_urlhttps://pythonhosted.org/jdatetime/
authorMilad Rastian
requires_python>=3.8
licensePython Software Foundation License
keywords jalali implementation of python datetime
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            jdatetime
=========

jdatetime is Jalali_ implementation of Python's datetime module

Status
------

.. image:: https://github.com/slashmili/python-jalali/workflows/Tests/badge.svg?branch=main
   :target: https://github.com/slashmili/python-jalali/actions


.. image:: https://ci.appveyor.com/api/projects/status/ge5rk703ydx649a6?svg=true
   :target: https://ci.appveyor.com/project/slashmili/python-jalali

.. image:: https://img.shields.io/pypi/v/jdatetime.svg
   :target: https://pypi.python.org/pypi/jdatetime

.. image:: https://img.shields.io/pypi/pyversions/jdatetime.svg
   :target: https://pypi.python.org/pypi/jdatetime

Install
-------
``pip install jdatetime``

Documents
---------
This module exactly follows Python Standard datetime module's methods http://docs.python.org/release/3.7.1/library/datetime.html

Also these methods are added to jdatetime.date and jdatetime.datetime :


.. code-block:: python

    fromgregorian(**kw)
        Convert gregorian to jalali and return jdatetime.date
        jdatetime.date.fromgregorian(day=X,month=X,year=X)
        jdatetime.date.fromgregorian(date=datetime.date)
        jdatetime.datetime.fromgregorian(datetime=datetime.datetime)
    togregorian(self)
        Convert current jalali date to gregorian and return datetime.date
    isleap(self)
        check if year is leap year
        algortim is based on http://en.wikipedia.org/wiki/Leap_year


Example
-------

.. code-block:: shell

    >>> import jdatetime
    >>> jdatetime.datetime.now()
    jdatetime.datetime(1394, 12, 4, 8, 37, 31, 855729)
    >>> jdatetime.date.today()
    jdatetime.date(1394, 12, 4)


Locale
------
In order to get the date string in farsi you need to set the locale to `jdatetime.FA_LOCALE`. The locale
could be specified explicitly upon instantiation of `date`/`datetime` instances, or by
setting a default locale.

Instance locales is *named argument only*:

.. code-block:: python

    import jdatetime
    fa_date = jdatetime.date(1397, 4, 23, locale=jdatetime.FA_LOCALE)
    fa_datetime = jdatetime.datetime(1397, 4, 23, 11, 40, 30, locale=jdatetime.FA_LOCALE)


`date` and `datetime` instances provide the method `aslocale()` to return a clone of the instance
with the same timestamp, in a different locale.


Default Locale
~~~~~~~~~~~~~~
It's possible to set the default locale, so all new instances created afterwards would use
the desired locale, unless explicitly specified otherwise.

.. code-block:: shell

    >>> import locale
    >>> import jdatetime
    >> jdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")
    u'Wed, 08 Ord 1395 20:47:32'
    >>> locale.setlocale(locale.LC_ALL, jdatetime.FA_LOCALE)
    'fa_IR'
    >>> jdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")
    u'\u0686\u0647\u0627\u0631\u0634\u0646\u0628\u0647, 08 \u0627\u0631\u062f\u06cc\u0628\u0647\u0634\u062a 1395 20:47:56'


If your requirements demand to support different locales withing the same process,
you could set the default locale per thread. New `date` and `datetime` instances
created in each thread, will use the specified locale by default.
This supports both Python threads, and greenlets.


.. code-block:: python

    import jdatetime
    jdatetime.set_locale(jdatetime.FA_LOCALE)
    jdatetime.datetime.now().strftime('%A %B')
    # u'\u062f\u0648\u0634\u0646\u0628\u0647 \u062e\u0631\u062f\u0627\u062f'

Development
-----------

You can contribute to this project forking it from GitHub and sending pull requests.

First fork_ the repository_ and then clone it:

.. code:: shell

    $ git clone git@github.com:<you>/python-jalali.git

Before committing, you can run all the above tests against all supported Python versions with tox.
You need to install tox first:

.. code:: shell

    $ pip install tox

And then you can run all tests:

.. code:: shell

    $ tox

If you wish to limit the testing to specific Python version, you can parametrize the tox run:

.. code:: shell

    $ tox -e py39

Release Steps
~~~~~~~~~~~~~~
* Bump the version in ``setup.py`` and ``jdatetime/__init__.py``. We are using Semantic Versioning.
* Add release notes in CHANGELOG.md
* Commit and push the changes. Create a PR
* After the PR is merged, create a release with a tag name like `v<version>`
* Github Action creates the package and deploys it to pypi.

.. _Jalali: http://en.wikipedia.org/wiki/Iranian_calendar
.. _fork: https://help.github.com/en/articles/fork-a-repo
.. _repository: https://github.com/slashmili/python-jalali

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/slashmili/python-jalali",
    "name": "jdatetime",
    "maintainer": null,
    "docs_url": "https://pythonhosted.org/jdatetime/",
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "Jalali implementation of Python datetime",
    "author": "Milad Rastian",
    "author_email": "eslashmili@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1f/6e/bed5a262bf9a80b4e45507757ae65fb141377eb3800b522eedeed782d865/jdatetime-5.0.0.tar.gz",
    "platform": "any",
    "description": "jdatetime\n=========\n\njdatetime is Jalali_ implementation of Python's datetime module\n\nStatus\n------\n\n.. image:: https://github.com/slashmili/python-jalali/workflows/Tests/badge.svg?branch=main\n   :target: https://github.com/slashmili/python-jalali/actions\n\n\n.. image:: https://ci.appveyor.com/api/projects/status/ge5rk703ydx649a6?svg=true\n   :target: https://ci.appveyor.com/project/slashmili/python-jalali\n\n.. image:: https://img.shields.io/pypi/v/jdatetime.svg\n   :target: https://pypi.python.org/pypi/jdatetime\n\n.. image:: https://img.shields.io/pypi/pyversions/jdatetime.svg\n   :target: https://pypi.python.org/pypi/jdatetime\n\nInstall\n-------\n``pip install jdatetime``\n\nDocuments\n---------\nThis module exactly follows Python Standard datetime module's methods http://docs.python.org/release/3.7.1/library/datetime.html\n\nAlso these methods are added to jdatetime.date and jdatetime.datetime :\n\n\n.. code-block:: python\n\n    fromgregorian(**kw)\n        Convert gregorian to jalali and return jdatetime.date\n        jdatetime.date.fromgregorian(day=X,month=X,year=X)\n        jdatetime.date.fromgregorian(date=datetime.date)\n        jdatetime.datetime.fromgregorian(datetime=datetime.datetime)\n    togregorian(self)\n        Convert current jalali date to gregorian and return datetime.date\n    isleap(self)\n        check if year is leap year\n        algortim is based on http://en.wikipedia.org/wiki/Leap_year\n\n\nExample\n-------\n\n.. code-block:: shell\n\n    >>> import jdatetime\n    >>> jdatetime.datetime.now()\n    jdatetime.datetime(1394, 12, 4, 8, 37, 31, 855729)\n    >>> jdatetime.date.today()\n    jdatetime.date(1394, 12, 4)\n\n\nLocale\n------\nIn order to get the date string in farsi you need to set the locale to `jdatetime.FA_LOCALE`. The locale\ncould be specified explicitly upon instantiation of `date`/`datetime` instances, or by\nsetting a default locale.\n\nInstance locales is *named argument only*:\n\n.. code-block:: python\n\n    import jdatetime\n    fa_date = jdatetime.date(1397, 4, 23, locale=jdatetime.FA_LOCALE)\n    fa_datetime = jdatetime.datetime(1397, 4, 23, 11, 40, 30, locale=jdatetime.FA_LOCALE)\n\n\n`date` and `datetime` instances provide the method `aslocale()` to return a clone of the instance\nwith the same timestamp, in a different locale.\n\n\nDefault Locale\n~~~~~~~~~~~~~~\nIt's possible to set the default locale, so all new instances created afterwards would use\nthe desired locale, unless explicitly specified otherwise.\n\n.. code-block:: shell\n\n    >>> import locale\n    >>> import jdatetime\n    >> jdatetime.datetime.now().strftime(\"%a, %d %b %Y %H:%M:%S\")\n    u'Wed, 08 Ord 1395 20:47:32'\n    >>> locale.setlocale(locale.LC_ALL, jdatetime.FA_LOCALE)\n    'fa_IR'\n    >>> jdatetime.datetime.now().strftime(\"%a, %d %b %Y %H:%M:%S\")\n    u'\\u0686\\u0647\\u0627\\u0631\\u0634\\u0646\\u0628\\u0647, 08 \\u0627\\u0631\\u062f\\u06cc\\u0628\\u0647\\u0634\\u062a 1395 20:47:56'\n\n\nIf your requirements demand to support different locales withing the same process,\nyou could set the default locale per thread. New `date` and `datetime` instances\ncreated in each thread, will use the specified locale by default.\nThis supports both Python threads, and greenlets.\n\n\n.. code-block:: python\n\n    import jdatetime\n    jdatetime.set_locale(jdatetime.FA_LOCALE)\n    jdatetime.datetime.now().strftime('%A %B')\n    # u'\\u062f\\u0648\\u0634\\u0646\\u0628\\u0647 \\u062e\\u0631\\u062f\\u0627\\u062f'\n\nDevelopment\n-----------\n\nYou can contribute to this project forking it from GitHub and sending pull requests.\n\nFirst fork_ the repository_ and then clone it:\n\n.. code:: shell\n\n    $ git clone git@github.com:<you>/python-jalali.git\n\nBefore committing, you can run all the above tests against all supported Python versions with tox.\nYou need to install tox first:\n\n.. code:: shell\n\n    $ pip install tox\n\nAnd then you can run all tests:\n\n.. code:: shell\n\n    $ tox\n\nIf you wish to limit the testing to specific Python version, you can parametrize the tox run:\n\n.. code:: shell\n\n    $ tox -e py39\n\nRelease Steps\n~~~~~~~~~~~~~~\n* Bump the version in ``setup.py`` and ``jdatetime/__init__.py``. We are using Semantic Versioning.\n* Add release notes in CHANGELOG.md\n* Commit and push the changes. Create a PR\n* After the PR is merged, create a release with a tag name like `v<version>`\n* Github Action creates the package and deploys it to pypi.\n\n.. _Jalali: http://en.wikipedia.org/wiki/Iranian_calendar\n.. _fork: https://help.github.com/en/articles/fork-a-repo\n.. _repository: https://github.com/slashmili/python-jalali\n",
    "bugtrack_url": null,
    "license": "Python Software Foundation License",
    "summary": "Jalali datetime binding for python",
    "version": "5.0.0",
    "project_urls": {
        "Homepage": "https://github.com/slashmili/python-jalali"
    },
    "split_keywords": [
        "jalali",
        "implementation",
        "of",
        "python",
        "datetime"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "64e6919b41f6c818dfc47838d0becfd96edac91e4b3d5a76cf73fefce53d88c0",
                "md5": "50810ffc653451d850c9e2f039a3e916",
                "sha256": "37e23c710d7e9bde7c37d0cc3ff9e273323889790e902a1ef3ad99148f094fb9"
            },
            "downloads": -1,
            "filename": "jdatetime-5.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "50810ffc653451d850c9e2f039a3e916",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12243,
            "upload_time": "2024-03-26T09:52:31",
            "upload_time_iso_8601": "2024-03-26T09:52:31.581706Z",
            "url": "https://files.pythonhosted.org/packages/64/e6/919b41f6c818dfc47838d0becfd96edac91e4b3d5a76cf73fefce53d88c0/jdatetime-5.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f6ebed5a262bf9a80b4e45507757ae65fb141377eb3800b522eedeed782d865",
                "md5": "c96a5413a1f3f64f405c1be585d6b538",
                "sha256": "2cc603d913c0d8e328928454d3d295261cb037e9950227f67c9629ab4710fdf9"
            },
            "downloads": -1,
            "filename": "jdatetime-5.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c96a5413a1f3f64f405c1be585d6b538",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21227,
            "upload_time": "2024-03-26T09:52:33",
            "upload_time_iso_8601": "2024-03-26T09:52:33.522038Z",
            "url": "https://files.pythonhosted.org/packages/1f/6e/bed5a262bf9a80b4e45507757ae65fb141377eb3800b522eedeed782d865/jdatetime-5.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 09:52:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "slashmili",
    "github_project": "python-jalali",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "appveyor": true,
    "tox": true,
    "lcname": "jdatetime"
}
        
Elapsed time: 0.19013s