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

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

Downloads

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.11.0.tar.gz (45.4 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.11.0.win-amd64-py3.5.exe (680.4 kB view details)

Uploaded Source

Khayyam-2.11.0.win-amd64-py2.7.exe (275.3 kB view details)

Uploaded Source

Khayyam-2.11.0.linux-x86_64.tar.gz (79.9 kB view details)

Uploaded Source

Khayyam-2.11.0-cp35-cp35m-win_amd64.whl (48.8 kB view details)

Uploaded CPython 3.5mWindows x86-64

Khayyam-2.11.0-cp27-cp27m-win_amd64.whl (46.6 kB view details)

Uploaded CPython 2.7mWindows x86-64

Khayyam-2.11.0-cp27-cp27m-macosx_10_11_intel.whl (47.5 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for Khayyam-2.11.0.tar.gz
Algorithm Hash digest
SHA256 91c138508d4df5be4016cb25c79d95c54b6d90bd6795e336cb4db5a3dce87508
MD5 795f772d76f16708f49a78ffb51afce7
BLAKE2b-256 5929c996b9bf31f7cde5f0edd2609f2b042a9b8a57f8a1e56b3ef8d690eba5b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-2.11.0.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 c8298b67c23812770d581a50b94540ee7404cc9a78e42b3c6b3a1bf9f2cfadaf
MD5 317c0164e1f935e42011ce302c130a74
BLAKE2b-256 2195a40c6a723374ace88f30830daaa6f0f6e523f26a862bc7efd21f3bc33709

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-2.11.0.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 cd67464374909df71a92fde7e5e6e237b455ff2aedbcb0dfd09423189f5470da
MD5 7aac65a1d70cfc0199a7eb6606720acc
BLAKE2b-256 b8263eb88e6063cdb98726e632a5136c32511a417d69dccb3422646f0ec29a60

See more details on using hashes here.

File details

Details for the file Khayyam-2.11.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for Khayyam-2.11.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 88425a1046e68491fd30468f31a0ff244b93115f2d0946140c04a4651bd2324e
MD5 0fa2dc14734d443cb79579bf68626621
BLAKE2b-256 38b1cc9deedf1d2c05acbf9af4282285c0ca977e08c366f3e39dd082d5761df2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-2.11.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 6d2c1750f5c7876671546442dd6f1a5cde6209befc394012378d56db0e91daa8
MD5 27fe7ae760fdd3cf5fcdd436f16e1df2
BLAKE2b-256 e52167011c89a8977cb561bc467cfffb3201c7e760a7aa01f59741a359e3555b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-2.11.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 ae0994ea3097fd9de656196ef6c8596eef5f49753f3a94d38369ec64c9982c5e
MD5 f7d1475f7eccc4b0304876d51d817af9
BLAKE2b-256 ecbb03c1fdc3d570ff387b8c7baa2a51a791ac06b1eddd7baaa2c8df6851d41c

See more details on using hashes here.

File details

Details for the file Khayyam-2.11.0-cp27-cp27m-macosx_10_11_intel.whl.

File metadata

File hashes

Hashes for Khayyam-2.11.0-cp27-cp27m-macosx_10_11_intel.whl
Algorithm Hash digest
SHA256 c80ad1f847da137eb5b712948204a707967ca4346c7f20e0bde73d6f213b7c5b
MD5 95d5bd75eae30865d2aa0c02561c58d0
BLAKE2b-256 37a9af361998cb7898d358d2e3aaddbf0100c81fc3d119cb8affbf11f4bc906e

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