Skip to main content

Jalali datetime binding for python

Project description

jdatetime is Jalali implementation of Python’s datetime module

Status

https://travis-ci.org/slashmili/python-jalali.svg?branch=master https://ci.appveyor.com/api/projects/status/ge5rk703ydx649a6?svg=true https://img.shields.io/pypi/v/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 addedd 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.date.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

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

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-2.2.0.tar.gz (9.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: jdatetime-2.2.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jdatetime-2.2.0.tar.gz
Algorithm Hash digest
SHA256 0c5983ef1a36b5d98d2b20c16f1d26a52452043d84f3ff1bf8f37e46bc314874
MD5 45cd83ba9f4a8b5ecd466e2492c47f47
BLAKE2b-256 9ebcb658f99cc393694a9982264752b0887db304b3e04c98555c7a26bcf3a1f9

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