Skip to main content

A cythonic and fast Persian Date & Time library (aka: Jalali Calendar) with timezone, DST(daylight-saving), full formatting & parsing support for python 2 & 3.

Project description

Jump To:

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

  • 2.9.3
    • setup.py for windows

  • 2.9.1
    • Release !

  • 2.9.1b2
    • encoding all __repr__ functions

  • 2.9.1b1 (2015-07-30)
    • Fixing setup.py bug

  • 2.9.1b0 (2015-07-30)
    • Using any available C compiler if cython is not available.

    • Using pure python if any error raised on installation with extension.

  • 2.9.0b0 (2015-07-30)
    • All algorithms reimplemented using cython and static typing, so the calculation

      with new C extension is very faster than python pure algorithm implementation.

    • Fallback switch to pure python algorithm implementation, if compiled binaries not available.

    • Test case(s) for algorithms(C & Python).

  • 2.8.0b1 (2015-07-28)
    • Jalalidate.timetuple method implemented from scratch including unit test.

    • Some methods with underscore renamed: JalaliDate.*_ascii to JalaliDate.*ascii

  • 2.7.0b2 (2015-07-26)
    • README.rst

  • 2.7.0-beta (2015-07-25)
    • some bug fixes.

    • method Jalalidate.fromdate removed. use constructor instead: JalaliDate(date)

    • method Jalalidate.fromjulianday removed. use constructor instead: JalaliDate(julian_days=..)

    • method Jalalidate.fromdatetime removed. use constructor instead: JalaliDatetime(datetime)

  • 2.6.0-beta (2015-07-25)
    • All possible formatting directives(a-z, A-Z) are supported, except: T

    • All format directives are tested.

    • Formatting and parsing test cases moved to khayyam.formatting.tests package.

    • In project: docs/html

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

    • README.md updated

  • 2.5.0-beta (2015-07-23)
    • Doc: doctest

    • Doc: formatting and parsing directives table.

    • Doc: adding examples of new formatting directives in introduction: %D, %J, %R, %N, %n, %F, %h, %i, %r, %s, %o.

    • local date & time formats are changed: digits -> persian

    • Formatting and parsing test cases has been separated

  • 2.4.0-beta (2015-07-22)
    • Persian Numbers

    • %D, %J, %R, %N, %n, %F, %h, %i, %r, %s, %o directives has been added.

  • 2.3.0-alpha (2015-07-22)
    • Constants are moved to formatting packages except MINYEAR, MAXYEAR ans weekdays.

    • Doc: Introduction -> Formatting & parsing

    • Doc: Introduction -> Converting

    • New methods jalaliDate.todate, jalaliDate.fromdate, jalaliDatetime.todatetime and jalaliDatetime.fromdatetime

    • Removed methods jalaliDate.to_date, jalaliDate.from_date, jalaliDatetime.to_datetime and jalaliDatetime.fromdate_time

  • 2.2.1-alpha (2015-07-21)
    • Doc: Reading package’s version automatically from khayyam/__init__.py in sphinx/conf.py

    • Doc: Installation: (PYPI, Development version)

    • Doc: Testing

    • Doc: Contribution

  • 2.2.0-alpha (2015-07-21)
    • Generating API Documentation

  • 2.1.0-alpha (2015-07-20)
    • Adding ascii weekdayname in JalaliDatetime and JalaliDate representation(__repr__).

  • 2.0.0-alpha (2015-07-19) Incompatible with < 2.0.0
    • JalaliDate: method localformat renamed to localdateformat.

    • JalaliDatetime: method localformat renamed to localdatetimeformat.

    • JalaliDatetime: method localshortformat_ascii renamed to localshortformatascii.

    • JalaliDatetime: method localdatetimeformat_ascii renamed to localdatetimeformatascii.

    • JalaliDatetime: method ampm_ascii renamed to ampmascii.

    • JalaliDatetime: Migrating to New Formatter/Parser Engine

    • TehTz: renamed to TehranTimezone

    • Comparison and Timezones

    • Comparison with datetime.date & datetime.datetime

    • Fixing timezone bug

  • 1.1.0 (2015-07-17)
    • JalaliDate: New Formatter/Parser & full unittests.

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

Khayyam-2.9.4.tar.gz (63.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

Khayyam-2.9.4.win32-py2.7.exe (253.2 kB view details)

Uploaded Source

Khayyam-2.9.4-py3.4-win32.egg (103.1 kB view details)

Uploaded Egg

Khayyam-2.9.4-py2.7-win32.egg (99.1 kB view details)

Uploaded Egg

Khayyam-2.9.4-cp34-none-win32.whl (54.1 kB view details)

Uploaded CPython 3.4Windows x86

Khayyam-2.9.4-cp27-none-win32.whl (53.2 kB view details)

Uploaded CPython 2.7Windows x86

File details

Details for the file Khayyam-2.9.4.tar.gz.

File metadata

  • Download URL: Khayyam-2.9.4.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Khayyam-2.9.4.tar.gz
Algorithm Hash digest
SHA256 56128ca05e5aaa45f7202c3860f7a72737353a361bf7918b185095002fa89e46
MD5 65a30d24a5b359004aada339d7a05457
BLAKE2b-256 3c40ae9fae9cee557b05f8ad2fe1fb6f7791117d7553cdb97fa160db62eb48be

See more details on using hashes here.

File details

Details for the file Khayyam-2.9.4.win32-py2.7.exe.

File metadata

File hashes

Hashes for Khayyam-2.9.4.win32-py2.7.exe
Algorithm Hash digest
SHA256 03d93ba1b96ea467130f2c998cf04f607098e13ba0852b9fc509d8d0f20b0226
MD5 08c7f28d0e31f9e3a0f23a8f996a6976
BLAKE2b-256 319828a06d04bfb2d0ec1f2beae344336bba1daa09633f62084aaf405be461b5

See more details on using hashes here.

File details

Details for the file Khayyam-2.9.4-py3.4-win32.egg.

File metadata

File hashes

Hashes for Khayyam-2.9.4-py3.4-win32.egg
Algorithm Hash digest
SHA256 6dd1124cd4ec3570d7bb2d63fc88a130ae650557331bdb040b2bc4ec6a591d3d
MD5 ea88221660d58f339d9537a4fd44792c
BLAKE2b-256 c22fc8d1a3ea7c78dac38723717026aa3948354d43b32005b048071f5f0af259

See more details on using hashes here.

File details

Details for the file Khayyam-2.9.4-py2.7-win32.egg.

File metadata

File hashes

Hashes for Khayyam-2.9.4-py2.7-win32.egg
Algorithm Hash digest
SHA256 b8d5d93f3637c4ca73e05246ec1a1ceebe9221ad8e640fe484082ba29d61585c
MD5 50df4a2716e2894c60d3a930d7cd9718
BLAKE2b-256 50a1134ccc4504497b66cf4714b2fa2f9f04ab4c29cf4db61313a2d2e6d03526

See more details on using hashes here.

File details

Details for the file Khayyam-2.9.4-cp34-none-win32.whl.

File metadata

File hashes

Hashes for Khayyam-2.9.4-cp34-none-win32.whl
Algorithm Hash digest
SHA256 47c3b3d3175f82049adddeee4adb0cbb5041c5b396f9fdafb98c31d60f1b0a05
MD5 31df9360f8b4de5446a7c0bff49816d4
BLAKE2b-256 8e7a73bc74ba47114d2c4e0d1f57cd392e9fa62aa817c08b46b81f668a1688e3

See more details on using hashes here.

File details

Details for the file Khayyam-2.9.4-cp27-none-win32.whl.

File metadata

File hashes

Hashes for Khayyam-2.9.4-cp27-none-win32.whl
Algorithm Hash digest
SHA256 bef9f5e76c4d4fbd43dc612f84cac5649c7c313cc6b8728bf751c27043ee6c51
MD5 0b54bb41c5cb88b63b1e7d3c0f388cea
BLAKE2b-256 b4af30fc519945ba84a7d79b09b7b4c1d46bad5b01817ebdd138d2a58944d411

See more details on using hashes here.

Supported by

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