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.15:
    • BUGFIX: Removing from sphinx.util import inspect from jalali_datetime.py.

  • 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.15.tar.gz (49.8 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.15.win-amd64-py3.5.exe (655.7 kB view details)

Uploaded Source

Khayyam-3.0.15.win-amd64-py2.7.exe (287.4 kB view details)

Uploaded Source

Khayyam-3.0.15-cp35-cp35m-win_amd64.whl (60.7 kB view details)

Uploaded CPython 3.5mWindows x86-64

Khayyam-3.0.15-cp35-cp35m-macosx_10_9_x86_64.whl (49.0 kB view details)

Uploaded CPython 3.5mmacOS 10.9+ x86-64

Khayyam-3.0.15-cp27-cp27m-win_amd64.whl (58.5 kB view details)

Uploaded CPython 2.7mWindows x86-64

Khayyam-3.0.15-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.15.tar.gz.

File metadata

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

File hashes

Hashes for Khayyam-3.0.15.tar.gz
Algorithm Hash digest
SHA256 053289108590dd356dbbfb0148f7a424f4d0824cfe2671a7cc5ef2c53f75a8d1
MD5 8b89b0466fdf5dc329a6480aee22a7aa
BLAKE2b-256 5d65810acff104e04bae517b3e2846d82ca0e0b4420ffec4b2126259b0a509af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-3.0.15.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 0d9c06e2c73a077554232930ac8843ba316f184327e408831d48d26ee440ba4f
MD5 cf0aa9d50caf14dc8762dd367529b9be
BLAKE2b-256 4feedcf7f9f7d8fbd2fc586ac32e583874a2b21db8b8ea1399adb3f4f6cb07f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-3.0.15.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 293b99d8fa9b0857b79e3d72f58732b7343b31c497d622fbae3705c30e1b3102
MD5 cd71e87ad6e491f36a0d417ca61a3b07
BLAKE2b-256 4d3c9650fe620fc9e5a4bf162ab3b9a68bf3747594a4b6e1b7b118dd408df10a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-3.0.15-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 e0b6e5fb2e9f7f6b6b08d55bf39c714396a1a1b5313699746239f2c341860e72
MD5 981fd97d6f21673bf464790644901dbd
BLAKE2b-256 426256bc8ab83a5ce3bfcfebf8fa50569430bb50346053e554531ded683832dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-3.0.15-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8cefc3b6575d2f4df829d2659fc5244b7100c524c763b8754a2ec7bd582b8f16
MD5 b011996bc7a126c4dfc0afe557868b7e
BLAKE2b-256 8eabd13dd0fe8bda8b4f7aaf1eaec3587af037b106955dc8ca3e421cbfbde969

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-3.0.15-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 263d99882bd87c03695e4f81c9ad90bec116b2c6ff7fb78560645c21ea96d645
MD5 074b8daf01e9fca44f531308ec050562
BLAKE2b-256 54a6e3a9a3c5f8a0eb04a76b72749105355636dac73d8e6c6b5f181adea3a38a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Khayyam-3.0.15-cp27-cp27m-macosx_10_9_intel.whl
Algorithm Hash digest
SHA256 60c798f76b8d8dc8e79f5a019084a7ae32be6f8fa2dc54a44ac5cf16378e2b52
MD5 81b099468075cfc22bd8c27968e785bf
BLAKE2b-256 6f140ad76913a9e5cc23bca6bdd7641043684bb16745a1757e6e07444c638248

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