Skip to main content

Jalali datetime binding for python

Project description

jdatetime is Jalali implementation of Python’s datetime module

Status

https://github.com/slashmili/python-jalali/workflows/Tests/badge.svg?branch=main https://ci.appveyor.com/api/projects/status/ge5rk703ydx649a6?svg=true https://img.shields.io/pypi/v/jdatetime.svg https://img.shields.io/pypi/pyversions/jdatetime.svg

Install

pip install jdatetime

Documents

This module exactly follows Python Standard datetime module’s methods http://docs.python.org/release/2.7.1/library/datetime.html

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

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

$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 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 fa_IR. The locale could be specified explicitly upon instantiation of date/datetime instances, or by setting a default locale.

Instance locales is named argument only:

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

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.

$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 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, "fa_IR")
'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.

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

Release Steps

  • Bump the version setup.py

  • Add release notes in CHANGELOG.md

  • Commit and create a tag with a name like v3.5.9

  • python setup.py sdist bdist_wheel

  • twine upload –repository testpypi dist/jdatetime-3.5.9.tar.gz

  • verify the version in testpypi: https://test.pypi.org/project/jdatetime/

  • twine upload dist/jdatetime-3.5.9.tar.gz

  • verify the version in pypi: https://pypi.org/project/jdatetime/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jdatetime-3.7.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

jdatetime-3.7.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file jdatetime-3.7.0.tar.gz.

File metadata

  • Download URL: jdatetime-3.7.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for jdatetime-3.7.0.tar.gz
Algorithm Hash digest
SHA256 f06876c926b8cf88b2f0f68d6cda2b0ff86002385877c9867970e1d017ef82a8
MD5 8ee0d84aaf1b5aac229ca4025cbd6d1a
BLAKE2b-256 604523da32418f9d29d60f7ca712ac72b08ae9c1dd6d316f623779119ffc2d9c

See more details on using hashes here.

File details

Details for the file jdatetime-3.7.0-py3-none-any.whl.

File metadata

  • Download URL: jdatetime-3.7.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for jdatetime-3.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0db40227962b55bf57ab91cd4c9c0b322dc7bd2204d8decc069e419e2ce35508
MD5 880a5a4c483e1811163ed76a5f350e93
BLAKE2b-256 19ba15074013cf921a4000acf6979d2431e0685ec388b0c564fae4707e46d8c1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page