Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0b1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajiloo committed Jul 7, 2016
2 parents 7e659f3 + 7608419 commit 0187381
Show file tree
Hide file tree
Showing 11 changed files with 1,450 additions and 39 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
@@ -1,13 +1,10 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.5-dev"
- "nightly"
- "pypy"
- "pypy3"

install:
- pip install coveralls
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1 +1 @@
include README.md
include README.rst
28 changes: 0 additions & 28 deletions README.md

This file was deleted.

141 changes: 141 additions & 0 deletions README.rst
@@ -0,0 +1,141 @@
PersianTools
============

| |pypi-ver| |PyPI-license| |travic-build| |Coverage Status| |python-ver|

- Jalali (Shamsi) date and datetime (based on python datetime's module)
- Convert Jalali to Gregorian date/datetime and vice versa
- Support comparition and arithmetic operators such as +, -, ==, >=
- Support timezone
- Convert Arabic and Persian characters/digits to each other

Install Package
---------------

.. code:: bash
$ pip install persiantools
How to use
----------

Date:
^^^^^

.. code:: python
>>> from persiantools.jdatetime import JalaliDate
>>> import datetime
>>> JalaliDate.today()
JalaliDate(1395, 04, 18, Jomeh)
>>> JalaliDate.today().to_gregorian()
datetime.date(2016, 7, 8)
>>> JalaliDate(1369, 7, 1)
JalaliDate(1369, 07, 01, Yekshanbeh)
>>> JalaliDate(datetime.date(1990, 9, 23))
JalaliDate(1369, 07, 01, Yekshanbeh)
>>> JalaliDate.to_jalali(2013, 9, 16)
JalaliDate(1392, 06, 25, Doshanbeh)
Datetime:
^^^^^^^^^

.. code:: python
>>> from persiantools.jdatetime import JalaliDateTime
>>> import datetime, pytz
>>> JalaliDateTime.now()
JalaliDateTime(1395, 4, 18, 1, 43, 24, 720505)
>>> JalaliDateTime.now().to_gregorian()
datetime.datetime(2016, 7, 8, 1, 43, 24, 720505)
>>> JalaliDateTime.now(pytz.timezone("Asia/Tehran"))
JalaliDateTime(1395, 4, 18, 1, 53, 30, 407770, tzinfo=<DstTzInfo 'Asia/Tehran' IRDT+4:30:00 DST>)
>>> JalaliDateTime.now(pytz.utc)
JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=<UTC>)
Digit/Character converter:
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
>>> from persiantools import characters
>>> from persiantools import digits
>>> digits.en_to_fa("0987654321")
'۰۹۸۷۶۵۴۳۲۱'
>>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")
'۰۹۸۷۶۵۴۳۲۱'
>>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
'0987654321'
>>> digits.fa_to_ar("۰۹۸۷۶۵۴۳۲۱")
'٠٩٨٧٦٥٤٣٢١'
>>> characters.ar_to_fa("راك")
'راک'
>>> characters.fa_to_ar("ای چرخ فلک خرابی از کینه تست")
'اي چرخ فلك خرابي از كينه تست'
Operators
^^^^^^^^^

.. code:: python
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
>>> import datetime
>>> JalaliDate(1367, 2, 14) == JalaliDate(datetime.date(1988, 5, 4))
True
>>> JalaliDateTime(1367, 2, 14, 4, 30) >= JalaliDateTime(1369, 7, 1, 1, 0)
False
>>> JalaliDate(1395, 2, 14) + datetime.timedelta(days=38)
JalaliDate(1395, 03, 21, Jomeh)
>>> JalaliDateTime(1395, 12, 30) - JalaliDateTime(1395, 1, 1)
datetime.timedelta(365)
Serializing and de-serializing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
>>> from persiantools.jdatetime import JalaliDate
>>> import pickle
>>> # Serializing
>>> file = open("save.p", "wb")
>>> pickle.dump(JalaliDate(1369, 7, 1), file)
>>> file.close()
>>> # de-serializing
>>> file = open("save.p", "rb")
>>> jalali = pickle.load(file)
>>> file.close()
>>> jalali
JalaliDate(1369, 07, 01, Yekshanbeh)
.. |pypi-ver| image:: https://img.shields.io/pypi/v/persiantools.svg
:target: https://pypi.python.org/pypi/persiantools
.. |PyPI-license| image:: https://img.shields.io/pypi/l/persiantools.svg
:target: https://pypi.python.org/pypi/persiantools
.. |travic-build| image:: https://travis-ci.org/mhajiloo/persiantools.png?branch=master
:target: https://travis-ci.org/mhajiloo/persiantools
.. |Coverage Status| image:: https://coveralls.io/repos/github/mhajiloo/persiantools/badge.svg?branch=master
:target: https://coveralls.io/github/mhajiloo/persiantools?branch=master
.. |python-ver| image:: https://img.shields.io/pypi/pyversions/persiantools.svg
:target: https://pypi.python.org/pypi/persiantools

0 comments on commit 0187381

Please sign in to comment.