All Projects → mhajiloo → Persiantools

mhajiloo / Persiantools

Licence: mit
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

persiantools
Jalali date and datetime with other tools
Stars: ✭ 101 (+77.19%)
Mutual labels:  datetime, persian
Md.persiandatetime
A C# library to use PersianCalendar as easy as DateTime
Stars: ✭ 68 (+19.3%)
Mutual labels:  persian, datetime
PersianDateRangePicker
Select range of date and time in the Persian
Stars: ✭ 41 (-28.07%)
Mutual labels:  datetime, persian
react-calendar-datetime-picker
A simple and fast date and time picker component for React
Stars: ✭ 58 (+1.75%)
Mutual labels:  datetime, persian
mds-angular-datetime-picker-package
Angular 2+ And Bootstrap 4+ DateTimePicker
Stars: ✭ 18 (-68.42%)
Mutual labels:  datetime, persian
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 (+3.51%)
Mutual labels:  datetime, persian
PersianTools.Core
Persian Tools for .Net and .Net Core
Stars: ✭ 25 (-56.14%)
Mutual labels:  datetime, persian
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+65466.67%)
Mutual labels:  datetime
Date Time Sketchplugin
Sketch data plugin generating random dates and times
Stars: ✭ 45 (-21.05%)
Mutual labels:  datetime
Tempus Dominus
A powerful Date/time picker widget.
Stars: ✭ 6,900 (+12005.26%)
Mutual labels:  datetime
Khayyam
106 Omar Khayyam quatrains in YAML format.
Stars: ✭ 8 (-85.96%)
Mutual labels:  persian
Angular Datetime Range
📅 Angular directive for datetime range input
Stars: ✭ 27 (-52.63%)
Mutual labels:  datetime
Phobos
The standard library of the D programming language
Stars: ✭ 1,038 (+1721.05%)
Mutual labels:  datetime
Recognizers Text
Microsoft.Recognizers.Text provides recognition and resolution of numbers, units, and date/time expressed in multiple languages (ZH, EN, FR, ES, PT, DE, IT, TR, HI. Partial support for NL, JA, KO, SV). Contributions are greatly welcome! Packages are available at https://www.nuget.org/profiles/Recognizers.Text and https://www.npmjs.com/~recognizers.text
Stars: ✭ 915 (+1505.26%)
Mutual labels:  datetime
Zulu
A drop-in replacement for native Python datetimes that embraces UTC.
Stars: ✭ 52 (-8.77%)
Mutual labels:  datetime
Telegram Iranbot
🌎 A dead simple Telegram bot for FA to FA, EN to FA translation
Stars: ✭ 9 (-84.21%)
Mutual labels:  persian
Flipclock
FlipClock It's a minimalist page-turning clock.
Stars: ✭ 54 (-5.26%)
Mutual labels:  datetime
React Native Jalali Datepicker
📅 React Native Jalali DatePicker component for both Android and iOS ✨
Stars: ✭ 52 (-8.77%)
Mutual labels:  persian
Nanotime
Nanosecond Resolution Time Functionality for R
Stars: ✭ 39 (-31.58%)
Mutual labels:  datetime
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (+1636.84%)
Mutual labels:  datetime

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

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

Digit/Character converter

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

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