Skip to main content

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/3.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

>>> 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:

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.

>>> 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.

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:

$ 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:

$ pip install tox

And then you can run all tests:

$ tox

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

$ tox -e py39

Release Steps

  • Bump the __VERSION__ in 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.

Release files for jdatetime 6.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jdatetime 6.1.0
File Size Uploaded
jdatetime-6.1.0.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jdatetime 6.1.0
File Interpreter ABI Platform
jdatetime-6.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.3 kB

Release files / jdatetime-6.1.0.tar.gz

Download URL jdatetime-6.1.0.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e5812d7ebf4c6609a554230cc07defc89d9c113424350fe2d5b7ed7dc50d3097
BLAKE2b-256 checksum
How to use checksums
e2b38195d5bf80f00cf5f8cd3ae74c083cc483c2a4b72fc86ab3f035b7787bed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / jdatetime-6.1.0-py3-none-any.whl

Download URL jdatetime-6.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68798192dd65daf6f40797a654000411446a4390ad44c331ba8c0e1d9ba8146f
BLAKE2b-256 checksum
How to use checksums
f004ae3d7810795405eb992f027416498a48d539ae1d57f812c16e5097d69ceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

6.1.0 This release

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.3.0

2 release files

5.2.0

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.8.2

2 release files

3.8.1

2 release files

3.8.0

2 release files

3.7.0

2 release files

3.6.4

2 release files

3.6.2

1 release file

3.6.1

1 release file

3.6.0

1 release file

3.5.0

1 release file

3.4.0

1 release file

3.3.0

1 release file

3.2.0

1 release file

3.1.0

1 release file

3.0.2

1 release file

3.0.0

1 release file

2.2.1

1 release file

2.2.0

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.9.1

1 release file

1.9.0

1 release file

1.8.2

1 release file

1.8.1

1 release file

1.8.0

1 release file

1.7.5

1 release file

1.7.4

1 release file

1.7.3

1 release file

1.7.2

1 release file

1.7.1

1 release file

1.7

1 release file

1.6

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page