Skip to main content

Persian Date & Time library (aka: Jalali Calendar) with timezone, DST(daylight-saving), full formatting & parsing support for python 2 & 3 including c extention

Project description

http://img.shields.io/pypi/v/khayyam.svg Requirements Status https://travis-ci.org/pylover/khayyam.svg?branch=master https://coveralls.io/repos/github/pylover/khayyam/badge.svg?branch=master https://img.shields.io/badge/license-GPLv3-brightgreen.svg

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())
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.11
    • Allmost the all API’s are documented.

  • 3.0.10
    • Imoprting JalaliDateFormatter & JalaliDatetimeFormatter in __init__.py

    • Accept also callable in JalaliDatetime.__init__(tzinfo=…) for tzinfo argument.

    • JalaliDatetime APIs, well documented.

  • 3.0.9
    • Removing pypy from travis, due the travis bug: buffer overflow !

  • 3.0.0
    • Raising TypeError instead of ValueError on overloaded operators, if the given type is mismatch.

    • Fixing tests to pass on systems that configured as UTC.

    • 100% Code coverage

    • Moving all tests to khayyam/tests

    • Removing some uncovered, obsolete code lines

  • 2.11.0
    • Using pure C instead of cython. Now the C extension is as fast as possible.

    • Including OSX in travis.yaml for python 2 & 3

    • Including pypy 2 & 3 tests in travis.yaml

  • 2.10.0
    • Add english weekday format directive

  • 2.9.8
    • Registering on travis-ci.org

    • Registering on coveralls.io

    • Registering on requires.io

  • 2.9.7
    • Fixing problem in setup.py in python3 #15

  • 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-3.0.14.tar.gz (49.7 kB view details)

Uploaded Source

Built Distributions

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

Khayyam-3.0.14.win-amd64-py3.5.exe (655.6 kB view details)

Uploaded Source

Khayyam-3.0.14.win-amd64-py2.7.exe (287.3 kB view details)

Uploaded Source

Khayyam-3.0.14-py2.7.egg (95.6 kB view details)

Uploaded Egg

Khayyam-3.0.14-cp35-cp35m-win_amd64.whl (60.6 kB view details)

Uploaded CPython 3.5mWindows x86-64

Khayyam-3.0.14-cp35-cp35m-macosx_10_9_x86_64.whl (48.9 kB view details)

Uploaded CPython 3.5mmacOS 10.9+ x86-64

Khayyam-3.0.14-cp27-cp27m-win_amd64.whl (58.4 kB view details)

Uploaded CPython 2.7mWindows x86-64

Khayyam-3.0.14-cp27-cp27m-macosx_10_9_intel.whl (51.5 kB view details)

Uploaded CPython 2.7mmacOS 10.9+ Intel (x86-64, i386)

File details

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

File metadata

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

File hashes

Hashes for Khayyam-3.0.14.tar.gz
Algorithm Hash digest
SHA256 9aaf608ad5b904cf2f485745f031a54f31e3ffbd662b7a8b5bf6243df6e42b4f
MD5 4847c0597c0a722f6b27de78441a47c1
BLAKE2b-256 d9af78209e2037b02271fa6cda893f55e385409d5bca627938e734c0653d1c26

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14.win-amd64-py3.5.exe.

File metadata

File hashes

Hashes for Khayyam-3.0.14.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 f1e6880bed1e915f9115759a40cb49338f4d957aeccfd643c8e51d06e85e1fe1
MD5 d64becf6a900386860ee02565cb095b7
BLAKE2b-256 d2597dd6e5977712c26609094c00883c654fbacd4f16a28d3629f83f1a2190d9

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for Khayyam-3.0.14.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 6b7ae0a9823ad65c13dae793b0b1d13042d8b615bd8951698fd7e698aedcf3ae
MD5 a08f4562f8f121f43848ade0dfdcfceb
BLAKE2b-256 784dc47d7e294e2df0eebb855de4f23255e5f6a90f7da462b10d58b17c1277ef

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-py3.5-freebsd-10.3-RELEASE-amd64.egg.

File metadata

File hashes

Hashes for Khayyam-3.0.14-py3.5-freebsd-10.3-RELEASE-amd64.egg
Algorithm Hash digest
SHA256 ba206f2bd41b891b4e0be54ce158e66bc4cb06a134a0c777db31130d8ce832d4
MD5 d0a48f65eb104392711db42826145a53
BLAKE2b-256 5088bebf73e28d89b0b7bee6267af544503c32dcd67ee8c1e1507ad4a6f9ee56

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-py2.7.egg.

File metadata

  • Download URL: Khayyam-3.0.14-py2.7.egg
  • Upload date:
  • Size: 95.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Khayyam-3.0.14-py2.7.egg
Algorithm Hash digest
SHA256 559446e69b75b641a79bef515d3689b1d0ba9fa3b3c6b02d9ed01d11db838ba3
MD5 01a6f4e05be824654442e29ab5f6023c
BLAKE2b-256 318c4901df14f226a30086fd7f71a61938aa49efa565a0201cb1e4ab23ca3ca8

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-py2.7-freebsd-10.3-RELEASE-amd64.egg.

File metadata

File hashes

Hashes for Khayyam-3.0.14-py2.7-freebsd-10.3-RELEASE-amd64.egg
Algorithm Hash digest
SHA256 ceec77080bd8b98f4d420e48b429930c787b14ed8bb3ed53d73cb6b4ba7e6c83
MD5 8033e801daf532397b571ef3576a9182
BLAKE2b-256 d575dd6657a2204718ff8088bfc2d6aa1f980fa4a1bdf7a87a0c81dddfbf9e39

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for Khayyam-3.0.14-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 5fba12e3109720376d159fb378963363e422e8ce03ed57aa4f430425c41b5c45
MD5 fd1181759f956d614b627b8029242c09
BLAKE2b-256 6e5ea37738ad4e7e8502f8cdfd90ee442d485817e38d12a2b070a35c993e6312

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-cp35-cp35m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for Khayyam-3.0.14-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a172e31ef08bde751f5c68bfdae4dc34b06022aa784b3c91e4965de2a6837e04
MD5 ec6f1c5e87f89293bd9159b6fc40ceb8
BLAKE2b-256 f2c8c4e2aac2aa4c5db183b930af2346285e95b1f8dea3fc6aba8b4241e71f35

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for Khayyam-3.0.14-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 a665c79c856e0aca4df2c4c362b3e9039837a2d78c524fdba0ebb0dd7e7096e9
MD5 f6042399828e8146cb0dc570a45a0f85
BLAKE2b-256 64593a75b55a8b155fce115ac4775631d1cc570014e0f7c9a979ec8ba0d04db4

See more details on using hashes here.

File details

Details for the file Khayyam-3.0.14-cp27-cp27m-macosx_10_9_intel.whl.

File metadata

File hashes

Hashes for Khayyam-3.0.14-cp27-cp27m-macosx_10_9_intel.whl
Algorithm Hash digest
SHA256 9f0c370fd42ca00b858cd50e98e895441c1f3a90867bd91267022f9da7720611
MD5 b7119dc2285cf0fdc5521e66315d08a0
BLAKE2b-256 73f984cb79534c42795c692296428b82b8ee6e630a5e0bf7d72585d959989b91

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