{"id":13817619,"url":"https://github.com/mhajiloo/persiantools","last_synced_at":"2025-05-15T20:32:33.342Z","repository":{"id":69596509,"uuid":"59749251","full_name":"mhajiloo/persiantools","owner":"mhajiloo","description":"Jalali date and datetime with other tools","archived":true,"fork":false,"pushed_at":"2020-02-13T10:16:28.000Z","size":170,"stargazers_count":69,"open_issues_count":9,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-19T15:45:22.791Z","etag":null,"topics":["datetime","gregorian","jalali","jalali-datetime","jdate","jdatetime","persian","persiantools","python","shamsi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mhajiloo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-05-26T12:41:07.000Z","updated_at":"2024-09-06T16:16:41.000Z","dependencies_parsed_at":"2024-01-13T15:37:44.181Z","dependency_job_id":"56972ddc-8b94-4b37-b381-85f9f40f0a5d","html_url":"https://github.com/mhajiloo/persiantools","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhajiloo%2Fpersiantools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhajiloo%2Fpersiantools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhajiloo%2Fpersiantools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhajiloo%2Fpersiantools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhajiloo","download_url":"https://codeload.github.com/mhajiloo/persiantools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254418667,"owners_count":22068126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datetime","gregorian","jalali","jalali-datetime","jdate","jdatetime","persian","persiantools","python","shamsi"],"created_at":"2024-08-04T06:00:52.176Z","updated_at":"2025-05-15T20:32:33.017Z","avatar_url":"https://github.com/mhajiloo.png","language":"Python","funding_links":[],"categories":["پایتون Python"],"sub_categories":[],"readme":"# PersianTools\n\n[![PyPI](https://img.shields.io/pypi/v/persiantools.svg)](https://pypi.org/project/persiantools/)\n[![Travis (.org)](https://img.shields.io/travis/mhajiloo/persiantools/master.svg)](https://travis-ci.org/mhajiloo/persiantools)\n[![AppVeyor](https://ci.appveyor.com/api/projects/status/8v49tpadjb3d68pe/branch/master?svg=true)](https://ci.appveyor.com/project/mhajiloo/persiantools/branch/master)\n[![Coveralls](https://coveralls.io/repos/github/mhajiloo/persiantools/badge.svg?branch=master)](https://coveralls.io/github/mhajiloo/persiantools?branch=master)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/persiantools.svg)](https://pypi.org/project/persiantools/)\n[![PyPI - License](https://img.shields.io/pypi/l/persiantools.svg)](https://pypi.org/project/persiantools/)\n\n- Jalali (Shamsi) date and datetime (based on python datetime's module)\n\n  - Convert Jalali to Gregorian date/datetime and vice versa\n  - Support comparison and arithmetic operators such as `+`, `-`, `==`, `\u003e=`\n  - Support timezone\n\n- Convert Arabic and Persian characters/digits to each other\n\n## Install Package\n\n```{.sourceCode .bash}\npip install persiantools\n```\n\n## How to use\n\n### Date\n\n```{.sourceCode .python}\n\u003e\u003e\u003e from persiantools.jdatetime import JalaliDate\n\u003e\u003e\u003e import datetime\n\n\u003e\u003e\u003e JalaliDate.today()\nJalaliDate(1395, 4, 18, Jomeh)\n\n\u003e\u003e\u003e JalaliDate(1369, 7, 1)\nJalaliDate(1369, 7, 1, Yekshanbeh)\n\n\u003e\u003e\u003e JalaliDate(datetime.date(1990, 9, 23))      # Gregorian to Jalali\nJalaliDate(1369, 7, 1, Yekshanbeh)\n\n\u003e\u003e\u003e JalaliDate.to_jalali(2013, 9, 16)           # Gregorian to Jalali\nJalaliDate(1392, 6, 25, Doshanbeh)\n\n\u003e\u003e\u003e JalaliDate(1392, 6, 25).to_gregorian()      # Jalali to Gregorian\ndatetime.date(2013, 9, 16)\n\n\u003e\u003e\u003e JalaliDate.fromtimestamp(578707200)         # Timestamp to Jalali\nJalaliDate(1367, 2, 14, Chaharshanbeh)\n```\n\n### Datetime\n\n```{.sourceCode .python}\n\u003e\u003e\u003e from persiantools.jdatetime import JalaliDateTime\n\u003e\u003e\u003e import datetime, pytz\n\n\u003e\u003e\u003e JalaliDateTime.now()\nJalaliDateTime(1395, 4, 18, 1, 43, 24, 720505)\n\n\u003e\u003e\u003e JalaliDateTime.now().to_gregorian()                                     # Jalali to Gregorian\ndatetime.datetime(2016, 7, 8, 1, 43, 24, 720505)\n\n\u003e\u003e\u003e JalaliDateTime.to_jalali(datetime.datetime(1988, 5, 4, 14, 0, 0, 0))    # Gregorian to Jalali\nJalaliDateTime(1367, 2, 14, 14, 0)\n\n\u003e\u003e\u003e JalaliDateTime.fromtimestamp(578723400, pytz.timezone(\"Asia/Tehran\"))   # Timestamp to Jalali\nJalaliDateTime(1367, 2, 14, 8, 0, tzinfo=\u003cDstTzInfo 'Asia/Tehran' +0330+3:30:00 STD\u003e)\n\n\u003e\u003e\u003e JalaliDateTime.now(pytz.utc)\nJalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=\u003cUTC\u003e)\n```\n\n### Format\n\nBased on python `strftime()` behavior\n\n```{.sourceCode .python}\n\u003e\u003e\u003e from persiantools.jdatetime import JalaliDate, JalaliDateTime\n\u003e\u003e\u003e import pytz\n\n\u003e\u003e\u003e JalaliDate(1367, 2, 14).isoformat()\n'1367-02-14'\n\n\u003e\u003e\u003e JalaliDate(1395, 3, 1).strftime(\"%Y/%m/%d\")\n'1395/03/01'\n\n\u003e\u003e\u003e JalaliDateTime(1369, 7, 1, 14, 0, 10, 0, pytz.utc).strftime(\"%c\")\n'Yekshanbeh 01 Mehr 1369 14:00:10'\n\n\u003e\u003e\u003e JalaliDateTime.now(pytz.utc).strftime(\"%I:%M:%S.%f %p %z %Z\")\n'01:49:22.518523 PM +0000 UTC'\n```\n\n### Digit/Character converter\n\n```{.sourceCode .python}\n\u003e\u003e\u003e from persiantools import characters, digits\n\n\u003e\u003e\u003e digits.en_to_fa(\"0987654321\")\n'۰۹۸۷۶۵۴۳۲۱'\n\n\u003e\u003e\u003e digits.ar_to_fa(\"٠٩٨٧٦٥٤٣٢١\")   # or digits.ar_to_fa(u\"٠٩٨٧٦٥٤٣٢١\")\n'۰۹۸۷۶۵۴۳۲۱'\n\n\u003e\u003e\u003e digits.fa_to_en(\"۰۹۸۷۶۵۴۳۲۱\")\n'0987654321'\n\n\u003e\u003e\u003e digits.fa_to_ar(\"۰۹۸۷۶۵۴۳۲۱\")\n'٠٩٨٧٦٥٤٣٢١'\n\n\u003e\u003e\u003e characters.ar_to_fa(\"كيك\")\n'کیک'\n```\n\n### Operators\n\n```{.sourceCode .python}\n\u003e\u003e\u003e from persiantools.jdatetime import JalaliDate, JalaliDateTime\n\u003e\u003e\u003e import datetime\n\n\u003e\u003e\u003e JalaliDate(1367, 2, 14) == JalaliDate(datetime.date(1988, 5, 4))\nTrue\n\n\u003e\u003e\u003e JalaliDateTime(1367, 2, 14, 4, 30) \u003e= JalaliDateTime(1369, 7, 1, 1, 0)\nFalse\n\n\u003e\u003e\u003e JalaliDate(1367, 2, 14) == datetime.date(1988, 5, 4)\nTrue\n\n\u003e\u003e\u003e JalaliDate(1395, 2, 14) + datetime.timedelta(days=38)\nJalaliDate(1395, 3, 21, Jomeh)\n\n\u003e\u003e\u003e JalaliDateTime(1395, 12, 30) - JalaliDateTime(1395, 1, 1)\ndatetime.timedelta(365)\n```\n\n### Serializing and de-serializing\n\n```{.sourceCode .python}\n\u003e\u003e\u003e from persiantools.jdatetime import JalaliDate\n\u003e\u003e\u003e import pickle\n\n\u003e\u003e\u003e # Serializing\n\u003e\u003e\u003e file = open(\"save.p\", \"wb\")\n\u003e\u003e\u003e pickle.dump(JalaliDate(1367, 2, 14), file)\n\u003e\u003e\u003e file.close()\n\n\u003e\u003e\u003e # de-serializing\n\u003e\u003e\u003e file = open(\"save.p\", \"rb\")\n\u003e\u003e\u003e jalali = pickle.load(file)\n\u003e\u003e\u003e file.close()\n\u003e\u003e\u003e jalali\nJalaliDate(1367, 2, 14, Chaharshanbeh)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhajiloo%2Fpersiantools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhajiloo%2Fpersiantools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhajiloo%2Fpersiantools/lists"}