A Persian Date & Time (aka: Jalali Calendar) library with timezone, DST (daylight-saving), full formatting & parsing support for python 2.x & 3.x.
GPL-3.0 License
.. image:: http://img.shields.io/pypi/v/khayyam.svg :target: https://pypi.python.org/pypi/khayyam
.. image:: https://travis-ci.org/pylover/khayyam.svg?branch=master :target: https://travis-ci.org/pylover/khayyam
.. image:: https://coveralls.io/repos/github/pylover/khayyam/badge.svg?branch=master :target: https://coveralls.io/github/pylover/khayyam?branch=master
.. image:: https://img.shields.io/badge/license-GPLv3-brightgreen.svg :target: https://github.com/pylover/khayyam/blob/master/LICENSE
.. image:: https://pepy.tech/badge/khayyam :target: https://pepy.tech/project/khayyam
.. image:: https://pepy.tech/badge/khayyam/month :target: https://pepy.tech/project/khayyam
.. image:: https://pepy.tech/badge/khayyam/week :target: https://pepy.tech/project/khayyam
Jump To: ^^^^^^^^
Documentation <http://khayyam.dobisel.com>
_Python package index <https://pypi.python.org/pypi/khayyam>
_Source on github <https://github.com/pylover/khayyam>
_Downloads <https://pypi.python.org/pypi/Khayyam#downloads>
_Basic Usage ^^^^^^^^^^^
>>> from khayyam import *
>>> JalaliDate(1346, 12, 30)
khayyam.JalaliDate(1346, 12, 30, Chaharshanbeh)
>>> JalaliDatetime(989, 3, 25, 10, 43, 23, 345453)
khayyam.JalaliDatetime(989, 3, 25, 10, 43, 23, 345453, Seshanbeh)
Current date and time ^^^^^^^^^^^^^^^^^^^^^
>>> print(JalaliDatetime.now())
khayyam.JalaliDatetime(1394, 5, 18, 16, 4, 48, 628383, Yekshanbeh)
>>> print(JalaliDatetime.now(TehranTimezone()) - timedelta(days=6*30))
1393-11-02 20:01:11.663719+03:30
>>> print(JalaliDate.today())
1394-4-30
Parsing & Formatting ^^^^^^^^^^^^^^^^^^^^
>>> print(JalaliDatetime.now().strftime('%C'))
شنبه ۳ مرداد ۱۳۹۴ ۰۲:۳۷:۵۲ ب.ظ
>>> JalaliDatetime.strptime(u'چهارشنبه ۳۱ تیر ۱۳۹۴ ۰۵:۴۵:۴۰ ب.ظ', '%C')
khayyam.JalaliDatetime(1394, 4, 31, 17, 45, 40, 0, Chaharshanbeh)
Converting ^^^^^^^^^^
>>> from datetime import date, datetime
>>> JalaliDate(1394, 4, 31).todate()
datetime.date(2015, 7, 22)
>>> now = JalaliDatetime(1394, 4, 31, 15, 38, 6, 37269)
>>> now.todate()
datetime.date(2015, 7, 22)
>>> now.todatetime()
datetime.datetime(2015, 7, 22, 15, 38, 6, 37269)
>>> JalaliDatetime(datetime(2015, 7, 22, 14, 47, 9, 821830))
khayyam.JalaliDatetime(1394, 4, 31, 14, 47, 9, 821830, Chaharshanbeh)
>>> JalaliDatetime(datetime(2015, 7, 22, 14, 47, 9, 821830, TehranTimezone()))
khayyam.JalaliDatetime(1394, 4, 31, 14, 47, 9, 821830, tzinfo=+03:30 dst:60, Chaharshanbeh)
>>> JalaliDate(date(2015, 7, 22))
khayyam.JalaliDate(1394, 4, 31, Chaharshanbeh)
Arithmetics & Operators ^^^^^^^^^^^^^^^^^^^^^^^
>>> from datetime import timedelta
>>> from khayyam import JalaliDate, JalaliDatetime
>>> now = JalaliDatetime(1394, 4, 31, 16, 17, 31, 374398)
>>> now + timedelta(days=1)
khayyam.JalaliDatetime(1394, 5, 1, 16, 17, 31, 374398, Panjshanbeh)
>>> now + timedelta(seconds=3600)
khayyam.JalaliDatetime(1394, 4, 31, 17, 17, 31, 374398, Chaharshanbeh)
>>> now - timedelta(seconds=3600)
khayyam.JalaliDatetime(1394, 4, 31, 15, 17, 31, 374398, Chaharshanbeh)
>>> yesterday = now - timedelta(1)
>>> yesterday
khayyam.JalaliDatetime(1394, 4, 30, 16, 17, 31, 374398, Seshanbeh)
>>> now - yesterday
datetime.timedelta(1)
>>> JalaliDatetime.now() - now
datetime.timedelta(0, 478, 328833) # 478 seconds taken to writing this section
Comparison ^^^^^^^^^^
>>> now > yesterday
True
>>> now != yesterday
True
>>> now.todate() == yesterday.todate()
False
Change Log ^^^^^^^^^^
3.0.15:
from sphinx.util import inspect
from jalali_datetime.py.3.0.11
3.0.10
3.0.9
3.0.0
2.11.0
2.10.0
2.9.8
2.9.7
2.9.3
2.9.1
2.9.1b2
2.9.1b1 (2015-07-30)
2.9.1b0 (2015-07-30)
2.9.0b0 (2015-07-30)
2.8.0b1 (2015-07-28)
Jalalidate.timetuple
method implemented from scratch including unit test.JalaliDate.*_ascii
to JalaliDate.*ascii
2.7.0b2 (2015-07-26)
2.7.0-beta (2015-07-25)
Jalalidate.fromdate
removed. use constructor instead: JalaliDate(date)
Jalalidate.fromjulianday
removed. use constructor instead: JalaliDate(julian_days=..)
Jalalidate.fromdatetime
removed. use constructor instead: JalaliDatetime(datetime)
2.6.0-beta (2015-07-25)
khayyam.formatting.tests
package.JalaliDate.from_julian_days
renamed to JalaliDate.fromjuliandays
JalaliDate.from_julian_days
renamed to JalaliDate.fromjuliandays
JalaliDate.days_in_month
renamed to JalaliDate.daysinmonth
JalaliDate.is_leap
renamed to JalaliDate.isleap
JalaliDatetime
Modern properties.2.5.0-beta (2015-07-23)
2.4.0-beta (2015-07-22)
2.3.0-alpha (2015-07-22)
jalaliDate.todate
, jalaliDate.fromdate
, jalaliDatetime.todatetime
and jalaliDatetime.fromdatetime
jalaliDate.to_date
, jalaliDate.from_date
, jalaliDatetime.to_datetime
and jalaliDatetime.fromdate_time
2.2.1-alpha (2015-07-21)
sphinx/conf.py
2.2.0-alpha (2015-07-21)
2.1.0-alpha (2015-07-20)
JalaliDatetime
and JalaliDate
representation(repr).2.0.0-alpha (2015-07-19) Incompatible with < 2.0.0
localformat
renamed to localdateformat
.localformat
renamed to localdatetimeformat
.localshortformat_ascii
renamed to localshortformatascii
.localdatetimeformat_ascii
renamed to localdatetimeformatascii
.ampm_ascii
renamed to ampmascii
.datetime.date
& datetime.datetime
1.1.0 (2015-07-17)