Jalali (Shamsi) date and datetime (based on python datetime's module)

Overview

PersianTools

PyPI Travis (.org) AppVeyor Coveralls PyPI - Python Version PyPI - License

  • 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

pip install persiantools

How to use

Date

>>> from persiantools.jdatetime import JalaliDate
>>> import datetime

>>> JalaliDate.today()
JalaliDate(1395, 4, 18, Jomeh)

>>> JalaliDate(1369, 7, 1)
JalaliDate(1369, 7, 1, Yekshanbeh)

>>> JalaliDate(datetime.date(1990, 9, 23))      # Gregorian to Jalali
JalaliDate(1369, 7, 1, Yekshanbeh)

>>> JalaliDate.to_jalali(2013, 9, 16)           # Gregorian to Jalali
JalaliDate(1392, 6, 25, Doshanbeh)

>>> JalaliDate(1392, 6, 25).to_gregorian()      # Jalali to Gregorian
datetime.date(2013, 9, 16)

>>> JalaliDate.fromtimestamp(578707200)         # Timestamp to Jalali
JalaliDate(1367, 2, 14, Chaharshanbeh)

Datetime

) >>> JalaliDateTime.now(pytz.utc) JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo= )">
>>> from persiantools.jdatetime import JalaliDateTime
>>> import datetime, pytz

>>> JalaliDateTime.now()
JalaliDateTime(1395, 4, 18, 1, 43, 24, 720505)

>>> JalaliDateTime.now().to_gregorian()                                     # Jalali to Gregorian
datetime.datetime(2016, 7, 8, 1, 43, 24, 720505)

>>> JalaliDateTime.to_jalali(datetime.datetime(1988, 5, 4, 14, 0, 0, 0))    # Gregorian to Jalali
JalaliDateTime(1367, 2, 14, 14, 0)

>>> JalaliDateTime.fromtimestamp(578723400, pytz.timezone("Asia/Tehran"))   # Timestamp to Jalali
JalaliDateTime(1367, 2, 14, 8, 0, tzinfo=
    
     )

>>> JalaliDateTime.now(pytz.utc)
JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=
     
      )

     
    

Format

Based on python strftime() behavior

>> 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'">
>>> 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

>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١") # or digits.ar_to_fa(u"٠٩٨٧٦٥٤٣٢١") '۰۹۸۷۶۵۴۳۲۱' >>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱") '0987654321' >>> digits.fa_to_ar("۰۹۸۷۶۵۴۳۲۱") '٠٩٨٧٦٥٤٣٢١' >>> characters.ar_to_fa("كيك") 'کیک'">
>>> from persiantools import characters, digits

>>> digits.en_to_fa("0987654321")
'۰۹۸۷۶۵۴۳۲۱'

>>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")   # or digits.ar_to_fa(u"٠٩٨٧٦٥٤٣٢١")
'۰۹۸۷۶۵۴۳۲۱'

>>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
'0987654321'

>>> digits.fa_to_ar("۰۹۸۷۶۵۴۳۲۱")
'٠٩٨٧٦٥٤٣٢١'

>>> characters.ar_to_fa("كيك")
'کیک'

Operators

>>> 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(1367, 2, 14) == datetime.date(1988, 5, 4)
True

>>> JalaliDate(1395, 2, 14) + datetime.timedelta(days=38)
JalaliDate(1395, 3, 21, Jomeh)

>>> JalaliDateTime(1395, 12, 30) - JalaliDateTime(1395, 1, 1)
datetime.timedelta(365)

Serializing and de-serializing

>> pickle.dump(JalaliDate(1367, 2, 14), file) >>> file.close() >>> # de-serializing >>> file = open("save.p", "rb") >>> jalali = pickle.load(file) >>> file.close() >>> jalali JalaliDate(1367, 2, 14, Chaharshanbeh)">
>>> from persiantools.jdatetime import JalaliDate
>>> import pickle

>>> # Serializing
>>> file = open("save.p", "wb")
>>> pickle.dump(JalaliDate(1367, 2, 14), file)
>>> file.close()

>>> # de-serializing
>>> file = open("save.p", "rb")
>>> jalali = pickle.load(file)
>>> file.close()
>>> jalali
JalaliDate(1367, 2, 14, Chaharshanbeh)
Owner
Majid Hajiloo
Majid Hajiloo
A datetime parser in Python by Ari24-cb24 and NekoFantic

datetimeparser A datetime parser in Python by Ari24-cb24 and NekoFantic V 1.0 Erinnerung für den Parser Auf falsche Eingaben überprüfen Liste an Event

AriDevelopment 13 Dec 30, 2022
E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

2.8k Jan 06, 2023
Generate and work with holidays in Python

python-holidays A fast, efficient Python library for generating country, province and state specific sets of holidays on the fly. It aims to make dete

Maurizio Montel 881 Dec 29, 2022
🏹 Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 09, 2023
ISO 8601 date/time parser

ISO 8601 date/time parser This module implements ISO 8601 date, time and duration parsing. The implementation follows ISO8601:2004 standard, and imple

118 Dec 20, 2022
🕟 Date and time processing language

Date Time Expression dte is a WIP date-time processing language with focus on broad interpretation. If you don't think it's intuitive, it's most likel

Marcelo 303 Dec 19, 2022
Delorean: Time Travel Made Easy

Delorean: Time Travel Made Easy Delorean is a library for clearing up the inconvenient truths that arise dealing with datetimes in Python. Understandi

Mahdi Yusuf 1.8k Dec 20, 2022
python parser for human readable dates

Python parser for human readable dates Key Features • How To Use • Installation • Common use cases • You may also like... • License Key Features Suppo

Scrapinghub 2.2k Jan 08, 2023
⌚️Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with Internet Time 😉

Internet-Ti.me Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with

Jessica Stokes 17 Nov 02, 2022
A simple digital clock made with the help of python

Digital-Clock ⏰ Description 📚 ✔️ A simple digital clock made with the help of python. The code is easy to understand and implement. With this reposit

Mohit 0 Dec 10, 2021
pytz Python historical timezone library and database

pytz Brings the IANA tz database into Python. This library allows accurate and cross platform timezone calculations. pytz contains generated code, and

Stub 236 Jan 03, 2023
darts is a Python library for easy manipulation and forecasting of time series.

A python library for easy manipulation and forecasting of time series.

Unit8 5.2k Jan 01, 2023
Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 05, 2023
A Python library for dealing with dates

moment A Python library for dealing with dates/times. Inspired by Moment.js and Kenneth Reitz's Requests library. Ideas were also taken from the Times

Zach Williams 709 Dec 09, 2022
TimeTagger is a web-based time-tracking solution that can be run locally or on a server

TimeTagger is a web-based time-tracking solution that can be run locally or on a server. In the latter case, you'll want to add authentication, and also be aware of the license restrictions.

Almar Klein 626 Jan 06, 2023
UNIX time from NTP or short UtfN is a simple CLI tool to set the time from an NTP-Server.

UNIX ⌚ from NTP UNIX time from NTP or short UtfN is a simple CLI tool to set the time from an NTP-Server. Sets time and date using the date command pr

Alexander 1 Jan 02, 2022
Parse human-readable date/time strings

parsedatetime Parse human-readable date/time strings. Python 2.6 or greater is required for parsedatetime version 1.0 or greater. While we still test

Mike Taylor 651 Dec 23, 2022
Datetimes for Humans™

Maya: Datetimes for Humans™ Datetimes are very frustrating to work with in Python, especially when dealing with different locales on different systems

Timo Furrer 3.4k Dec 28, 2022
Make Python datetime formatting human readable

Make Python datetime formatting human readable

James Timmins 0 Oct 03, 2021
A simple in-process python scheduler library, designed to be integrated seamlessly with the `datetime` standard library.

scheduler A simple in-process python scheduler library, designed to be integrated seamlessly with the datetime standard library. Due to the support of

30 Dec 30, 2022