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.9",
"maintainer_email": null,
"keywords": "Jalali implementation of Python datetime",
"author": "Milad Rastian",
"author_email": "eslashmili@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6e/9d/5ed59c36f3cbc68c01fab6442e6efb6d35a484ba4eec4f790264fce39f6c/jdatetime-5.2.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.2.0",
"project_urls": {
"Homepage": "https://github.com/slashmili/python-jalali"
},
"split_keywords": [
"jalali",
"implementation",
"of",
"python",
"datetime"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "16390dd2676d08468692606645db5ea40091290dc20747ff59636c21c0567d3c",
"md5": "3ce8b980811c4a9987dfb897118f5044",
"sha256": "d4aa73543e4e6c0e6122b58743773168edee5efe5c5acf05d1dc8c90524ca71c"
},
"downloads": -1,
"filename": "jdatetime-5.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3ce8b980811c4a9987dfb897118f5044",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 12199,
"upload_time": "2025-01-26T09:29:15",
"upload_time_iso_8601": "2025-01-26T09:29:15.038306Z",
"url": "https://files.pythonhosted.org/packages/16/39/0dd2676d08468692606645db5ea40091290dc20747ff59636c21c0567d3c/jdatetime-5.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "6e9d5ed59c36f3cbc68c01fab6442e6efb6d35a484ba4eec4f790264fce39f6c",
"md5": "7df62858c834b8bd379f67e8ce1aaac4",
"sha256": "c81d5898717b82b609a3ce2a73f8b8d3230b0c757e5c0de9d6b1acfdc224f551"
},
"downloads": -1,
"filename": "jdatetime-5.2.0.tar.gz",
"has_sig": false,
"md5_digest": "7df62858c834b8bd379f67e8ce1aaac4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 21663,
"upload_time": "2025-01-26T09:29:16",
"upload_time_iso_8601": "2025-01-26T09:29:16.802862Z",
"url": "https://files.pythonhosted.org/packages/6e/9d/5ed59c36f3cbc68c01fab6442e6efb6d35a484ba4eec4f790264fce39f6c/jdatetime-5.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-26 09:29:16",
"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"
}