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.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajiloo committed Jul 21, 2016
2 parents 69334ff + c2bca53 commit a2cbc03
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 91 deletions.
53 changes: 38 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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 comparison and arithmetic operators such as +, -, ==, >=
- Support timezone
- Convert Arabic and Persian characters/digits to each other
------

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

------

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

.. code:: bash
$ pip install persiantools==1.0b2
$ pip install persiantools
How to use
----------
Expand All @@ -28,19 +31,19 @@ Date:
>>> import datetime
>>> JalaliDate.today()
JalaliDate(1395, 04, 18, Jomeh)
JalaliDate(1395, 4, 18, Jomeh)
>>> JalaliDate.today().to_gregorian()
datetime.date(2016, 7, 8)
>>> JalaliDate(1369, 7, 1)
JalaliDate(1369, 07, 01, Yekshanbeh)
JalaliDate(1369, 7, 1, Yekshanbeh)
>>> JalaliDate(datetime.date(1990, 9, 23))
JalaliDate(1369, 07, 01, Yekshanbeh)
JalaliDate(1369, 7, 1, Yekshanbeh)
>>> JalaliDate.to_jalali(2013, 9, 16)
JalaliDate(1392, 06, 25, Doshanbeh)
JalaliDate(1392, 6, 25, Doshanbeh)
Datetime:
^^^^^^^^^
Expand All @@ -62,13 +65,33 @@ Datetime:
>>> JalaliDateTime.now(pytz.utc)
JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=<UTC>)
Format
^^^^^^
Based on python ``strftime()`` behavior

.. code:: python
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
>>> import pytz
>>> JalaliDate(1367, 2, 14).isoformat()
'1367-02-14'
>>> JalaliDate(1395, 3, 1).strftime("%Y/%m/%d")
'1395/03/01'
>>> JalaliDateTime(1369, 7, 1, 14, 0, 10, 0, pytz.utc).strftime("%c")
'Yekshanbeh 01 Mehr 1369 14:00:10'
>>> JalaliDateTime.now(pytz.utc).strftime("%I:%M:%S.%f %p %z %Z")
'01:49:22.518523 PM +0000 UTC'
Digit/Character converter:
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
>>> from persiantools import characters
>>> from persiantools import digits
>>> from persiantools import characters, digits
>>> digits.en_to_fa("0987654321")
'۰۹۸۷۶۵۴۳۲۱'
Expand Down Expand Up @@ -103,7 +126,7 @@ Operators
False
>>> JalaliDate(1395, 2, 14) + datetime.timedelta(days=38)
JalaliDate(1395, 03, 21, Jomeh)
JalaliDate(1395, 3, 21, Jomeh)
>>> JalaliDateTime(1395, 12, 30) - JalaliDateTime(1395, 1, 1)
datetime.timedelta(365)
Expand All @@ -126,7 +149,7 @@ Serializing and de-serializing
>>> jalali = pickle.load(file)
>>> file.close()
>>> jalali
JalaliDate(1369, 07, 01, Yekshanbeh)
JalaliDate(1369, 7, 1, Yekshanbeh)
.. |pypi-ver| image:: https://img.shields.io/pypi/v/persiantools.svg
:target: https://pypi.python.org/pypi/persiantools
Expand Down
2 changes: 1 addition & 1 deletion persiantools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

__title__ = 'persiantools'
__version__ = '1.0b2'
__version__ = '1.1.0'
__build__ = __version__
__author__ = 'Majid Hajiloo'
__license__ = 'MIT'
Expand Down
16 changes: 8 additions & 8 deletions persiantools/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def en_to_fa(string):
"""Convert EN digits to Persian
Usage::
from persiantools import digits
converted = digits.en_to_fa("0123456789")
>>> from persiantools import digits
>>> converted = digits.en_to_fa("0123456789")
:param string: A string, will be converted
:rtype: str
Expand All @@ -32,8 +32,8 @@ def ar_to_fa(string):
"""Convert Arabic digits to Persian
Usage::
from persiantools import digits
converted = digits.ar_to_fa("٠١٢٣٤٥٦٧٨٩")
>>> from persiantools import digits
>>> converted = digits.ar_to_fa("٠١٢٣٤٥٦٧٨٩")
:param string: A string, will be converted
:rtype: str
Expand All @@ -58,8 +58,8 @@ def fa_to_en(string):
"""Convert Persian digits to EN
Usage::
from persiantools import digits
converted = digits.fa_to_en("۰۱۲۳۴۵۶۷۸۹")
>>> from persiantools import digits
>>> converted = digits.fa_to_en("۰۱۲۳۴۵۶۷۸۹")
:param string: A string, will be converted
:rtype: str
Expand All @@ -84,8 +84,8 @@ def fa_to_ar(string):
"""Convert Persian digits to Arabic
Usage::
from persiantools import digits
converted = digits.fa_to_ar("۰۱۲۳۴۵۶۷۸۹")
>>> from persiantools import digits
>>> converted = digits.fa_to_ar("۰۱۲۳۴۵۶۷۸۹")
:param string: A string, will be converted
:rtype: str
Expand Down
Loading

0 comments on commit a2cbc03

Please sign in to comment.