All Projects → majiidd → persiantools

majiidd / persiantools

Licence: MIT license
Jalali date and datetime with other tools

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to persiantools

shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (-41.58%)
Mutual labels:  datetime, date, persian, jalali, shamsi, gregorian
libcalendars
Collection of calendar arithmetic algorithms
Stars: ✭ 38 (-62.38%)
Mutual labels:  jalali, shamsi, gregorian
wp-parsidate
Integrates the Solar Hijri (Persian) calendar in WordPress
Stars: ✭ 36 (-64.36%)
Mutual labels:  persian, jalali, shamsi
react-calendar-datetime-picker
A simple and fast date and time picker component for React
Stars: ✭ 58 (-42.57%)
Mutual labels:  datetime, date, persian
gahshomar
A Persian (Jalali/Farsi) calendar for Linux
Stars: ✭ 69 (-31.68%)
Mutual labels:  persian, jalali, farsi
PersianTools.Core
Persian Tools for .Net and .Net Core
Stars: ✭ 25 (-75.25%)
Mutual labels:  datetime, persian, persiantools
Date
Fix all needs to date in php
Stars: ✭ 32 (-68.32%)
Mutual labels:  datetime, jalali, gregorian
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+1863.37%)
Mutual labels:  datetime, date
Date
A date and time library based on the C++11/14/17 <chrono> header
Stars: ✭ 2,389 (+2265.35%)
Mutual labels:  datetime, date
fmtdate
MS Excel (TM) syntax for Go time/date
Stars: ✭ 95 (-5.94%)
Mutual labels:  datetime, date
Jest Date Mock
🌗 Mock `Date` when run unit test cases with jest. Make tests of Date easier.
Stars: ✭ 224 (+121.78%)
Mutual labels:  datetime, date
Gostradamus
Gostradamus: Better DateTimes for Go 🕰️
Stars: ✭ 148 (+46.53%)
Mutual labels:  datetime, date
Date Picker
📅 Custom responsive date picker widget for Android, written in Kotlin.
Stars: ✭ 146 (+44.55%)
Mutual labels:  datetime, date
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (+85.15%)
Mutual labels:  datetime, date
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (+1675.25%)
Mutual labels:  datetime, date
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (+37.62%)
Mutual labels:  datetime, date
Go Naturaldate
Natural date/time parsing for Go.
Stars: ✭ 217 (+114.85%)
Mutual labels:  datetime, date
Flatpickr
lightweight, powerful javascript datetimepicker with no dependencies
Stars: ✭ 14,575 (+14330.69%)
Mutual labels:  datetime, date
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+20.79%)
Mutual labels:  datetime, date
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (-38.61%)
Mutual labels:  datetime, date

PersianTools

PyPI test workflow pre-commit.ci status codecov 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

  • Convert numbers to words

Install Package

python -m pip install persiantools

Persiantools supports Python 3.6+. (for python 2.7 and 3.5 use 1.5.x version)

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

>>> 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=<DstTzInfo 'Asia/Tehran' +0330+3:30:00 STD>)

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

Format

Based on python strftime() behavior

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

Digits/Characters Tools

>>> from persiantools import characters, digits

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

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

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

>>> digits.to_word(9512026)
'نه میلیون و پانصد و دوازده هزار و بیست و شش'

>>> digits.to_word(15.007)
'پانزده و هفت هزارم'

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

>>> 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)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].