shdatetime
==========
``shdatetime`` `Solar Hijri`_ implementation of Python's `datetime`_ module.
Installation
------------
``pip install shdatetime``
Usage
-----
This module exactly follows Python Standard datetime module's methods https://docs.python.org/3/library/datetime.html
Also these methods are added to ``shdatetime.date`` and ``shdatetime.datetime`` :
.. code-block:: python
fromgregorian(**kw)
Convert gregorian to jalali and return shdatetime.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 shdatetime
>>> shdatetime.datetime.now()
shdatetime.datetime(1394, 12, 4, 8, 37, 31, 855729)
>>> shdatetime.date.today()
shdatetime.date(1394, 12, 4)
Locale
------
In order to get the date string in farsi you need to set the locale to `shdatetime.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 shdatetime
fa_date = shdatetime.date(1397, 4, 23, locale=shdatetime.FA_LOCALE)
fa_datetime = shdatetime.datetime(1397, 4, 23, 11, 40, 30, locale=shdatetime.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 shdatetime
>> shdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")
u'Wed, 08 Ord 1395 20:47:32'
>>> locale.setlocale(locale.LC_ALL, shdatetime.FA_LOCALE)
'fa_IR'
>>> shdatetime.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 shdatetime
shdatetime.set_locale(shdatetime.FA_LOCALE)
shdatetime.datetime.now().strftime('%A %B')
# u'\u062f\u0648\u0634\u0646\u0628\u0647 \u062e\u0631\u062f\u0627\u062f'
Fork of jdatetime
-----------------
``shdatetime`` is a fork of `jdatetime`_.
Main differences:
- ``shdatetime`` is released under the terms of GPL-v3 license.
- Instead of relying on `jalali-core`_, ``shdatetime`` uses `gshconveter`_ which is fully compatible with ``jalali-core`` and is thoroughly tested. It's also faster!
- ``shdatetime`` requires Python 3.12+.
.. _Solar Hijri: https://en.wikipedia.org/wiki/Solar_Hijri_calendar
.. _datetime: https://docs.python.org/3/library/datetime.html
.. _jdatetime: https://github.com/slashmili/python-jalali
.. _jalali-core: https://github.com/slashmili/jalali-core
.. _PSFL: https://en.wikipedia.org/wiki/Python_Software_Foundation_License
.. _fork: https://help.github.com/en/articles/fork-a-repo
.. _repository: https://github.com/slashmili/python-jalali
.. _gshconveter: https://github.com/5j9/gshconverter
Raw data
{
"_id": null,
"home_page": null,
"name": "shdatetime",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "shdatetime, datetime, Solar Hijri, calendar",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/39/e9/86e5d3bc9df1aaddc40d8667b063edfd749bd3e1f8a4f2f366a53383e833/shdatetime-0.1.0.tar.gz",
"platform": null,
"description": "shdatetime\n==========\n\n``shdatetime`` `Solar Hijri`_ implementation of Python's `datetime`_ module.\n\nInstallation\n------------\n``pip install shdatetime``\n\nUsage\n-----\nThis module exactly follows Python Standard datetime module's methods https://docs.python.org/3/library/datetime.html\n\nAlso these methods are added to ``shdatetime.date`` and ``shdatetime.datetime`` :\n\n\n.. code-block:: python\n\n fromgregorian(**kw)\n Convert gregorian to jalali and return shdatetime.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 shdatetime\n >>> shdatetime.datetime.now()\n shdatetime.datetime(1394, 12, 4, 8, 37, 31, 855729)\n >>> shdatetime.date.today()\n shdatetime.date(1394, 12, 4)\n\n\nLocale\n------\nIn order to get the date string in farsi you need to set the locale to `shdatetime.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 shdatetime\n fa_date = shdatetime.date(1397, 4, 23, locale=shdatetime.FA_LOCALE)\n fa_datetime = shdatetime.datetime(1397, 4, 23, 11, 40, 30, locale=shdatetime.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 shdatetime\n >> shdatetime.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, shdatetime.FA_LOCALE)\n 'fa_IR'\n >>> shdatetime.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 shdatetime\n shdatetime.set_locale(shdatetime.FA_LOCALE)\n shdatetime.datetime.now().strftime('%A %B')\n # u'\\u062f\\u0648\\u0634\\u0646\\u0628\\u0647 \\u062e\\u0631\\u062f\\u0627\\u062f'\n\nFork of jdatetime\n-----------------\n``shdatetime`` is a fork of `jdatetime`_.\n\nMain differences:\n\n- ``shdatetime`` is released under the terms of GPL-v3 license.\n- Instead of relying on `jalali-core`_, ``shdatetime`` uses `gshconveter`_ which is fully compatible with ``jalali-core`` and is thoroughly tested. It's also faster!\n- ``shdatetime`` requires Python 3.12+.\n\n\n.. _Solar Hijri: https://en.wikipedia.org/wiki/Solar_Hijri_calendar\n.. _datetime: https://docs.python.org/3/library/datetime.html\n.. _jdatetime: https://github.com/slashmili/python-jalali\n.. _jalali-core: https://github.com/slashmili/jalali-core\n.. _PSFL: https://en.wikipedia.org/wiki/Python_Software_Foundation_License\n.. _fork: https://help.github.com/en/articles/fork-a-repo\n.. _repository: https://github.com/slashmili/python-jalali\n.. _gshconveter: https://github.com/5j9/gshconverter\n",
"bugtrack_url": null,
"license": null,
"summary": "Solar Hijri datetime for Python",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/5j9/shdatetime"
},
"split_keywords": [
"shdatetime",
" datetime",
" solar hijri",
" calendar"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "3e97c115c412bda0a6fcaea44d6be2ddf19d5bd6c90ac8815376fb8c23744261",
"md5": "0c69fc6f5877f8e4d58b811c8d28e9a3",
"sha256": "961f8194ea16ca1758a1ef3601a576e9b6e9dd59e297ca9c45cf102181739da5"
},
"downloads": -1,
"filename": "shdatetime-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c69fc6f5877f8e4d58b811c8d28e9a3",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.12",
"size": 23351,
"upload_time": "2024-03-28T17:31:31",
"upload_time_iso_8601": "2024-03-28T17:31:31.767066Z",
"url": "https://files.pythonhosted.org/packages/3e/97/c115c412bda0a6fcaea44d6be2ddf19d5bd6c90ac8815376fb8c23744261/shdatetime-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "39e986e5d3bc9df1aaddc40d8667b063edfd749bd3e1f8a4f2f366a53383e833",
"md5": "457960d104f545859ee4879b042f9886",
"sha256": "e6f4233c1b8eb08f45e15d75fae185e74908fc30406c595651a5ba4768dda2db"
},
"downloads": -1,
"filename": "shdatetime-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "457960d104f545859ee4879b042f9886",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 24186,
"upload_time": "2024-03-28T17:31:35",
"upload_time_iso_8601": "2024-03-28T17:31:35.442305Z",
"url": "https://files.pythonhosted.org/packages/39/e9/86e5d3bc9df1aaddc40d8667b063edfd749bd3e1f8a4f2f366a53383e833/shdatetime-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-28 17:31:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "5j9",
"github_project": "shdatetime",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "shdatetime"
}