persiantools 5.5.1__tar.gz → 6.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- persiantools-6.0.0/PKG-INFO +241 -0
- persiantools-6.0.0/README.md +207 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools/__init__.py +1 -1
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools/jdatetime.py +363 -139
- persiantools-6.0.0/persiantools.egg-info/PKG-INFO +241 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/pyproject.toml +11 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/tests/test_jalalidate.py +310 -115
- {persiantools-5.5.1 → persiantools-6.0.0}/tests/test_jalalidatetime.py +238 -6
- persiantools-5.5.1/PKG-INFO +0 -344
- persiantools-5.5.1/README.md +0 -310
- persiantools-5.5.1/persiantools.egg-info/PKG-INFO +0 -344
- {persiantools-5.5.1 → persiantools-6.0.0}/LICENSE +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/MANIFEST.in +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools/characters.py +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools/digits.py +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools/utils.py +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools.egg-info/SOURCES.txt +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools.egg-info/dependency_links.txt +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools.egg-info/requires.txt +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/persiantools.egg-info/top_level.txt +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/setup.cfg +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/tests/test_characters.py +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/tests/test_digits.py +0 -0
- {persiantools-5.5.1 → persiantools-6.0.0}/tests/test_utils.py +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: persiantools
|
|
3
|
+
Version: 6.0.0
|
|
4
|
+
Summary: Jalali date and datetime with other tools
|
|
5
|
+
Author-email: Majid Hajiloo <majid.hajiloo@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/majiidd/persiantools
|
|
8
|
+
Project-URL: Source, https://github.com/majiidd/persiantools
|
|
9
|
+
Project-URL: Issues, https://github.com/majiidd/persiantools/issues
|
|
10
|
+
Keywords: jalali,shamsi,persian,digits,characters,converter,jalalidate,jalalidatetime,date,datetime,jdate,jdatetime,farsi
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: Persian
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
24
|
+
Classifier: Topic :: Software Development
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Topic :: Software Development :: Localization
|
|
28
|
+
Classifier: Topic :: Utilities
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: tzdata; platform_system == "Windows"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# PersianTools
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/persiantools/)
|
|
38
|
+

|
|
39
|
+
[](https://codecov.io/gh/majiidd/persiantools)
|
|
40
|
+
[](https://pypi.org/project/persiantools/)
|
|
41
|
+
[](https://pypi.org/project/persiantools/)
|
|
42
|
+
|
|
43
|
+
`PersianTools` provides Jalali (Shamsi) dates and datetimes that work just like Python's `datetime` — plus handy tools for Persian text: digit conversion between Persian, Arabic, and English, character normalization, and numbers to Persian words.
|
|
44
|
+
|
|
45
|
+
If you know `datetime.date` and `datetime.datetime`, you already know `JalaliDate` and `JalaliDateTime`. They support the same operations: comparison, arithmetic with `timedelta`, timezones, `strftime`/`strptime` and formatting, hashing, and pickling.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install persiantools
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Requires Python 3.9 or newer. No dependencies, except `tzdata` on Windows for timezone data.
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
59
|
+
>>> import datetime
|
|
60
|
+
|
|
61
|
+
>>> JalaliDate.today()
|
|
62
|
+
JalaliDate(1405, 4, 12, Jomeh)
|
|
63
|
+
|
|
64
|
+
>>> JalaliDate(datetime.date(1988, 5, 4)) # Gregorian → Jalali
|
|
65
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
66
|
+
|
|
67
|
+
>>> JalaliDate(1367, 2, 14).to_gregorian() # Jalali → Gregorian
|
|
68
|
+
datetime.date(1988, 5, 4)
|
|
69
|
+
|
|
70
|
+
>>> JalaliDateTime.now().strftime("%A %d %B %Y, %H:%M")
|
|
71
|
+
'Jomeh 12 Tir 1405, 14:30'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Dates
|
|
75
|
+
|
|
76
|
+
Create a `JalaliDate` from Jalali values, a Gregorian date, an ISO string, or a timestamp:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
>>> from persiantools.jdatetime import JalaliDate
|
|
80
|
+
>>> import datetime
|
|
81
|
+
|
|
82
|
+
>>> JalaliDate(1367, 2, 14)
|
|
83
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
84
|
+
|
|
85
|
+
>>> JalaliDate.to_jalali(2013, 9, 16)
|
|
86
|
+
JalaliDate(1392, 6, 25, Doshanbeh)
|
|
87
|
+
|
|
88
|
+
>>> JalaliDate.fromisoformat("1404-01-01")
|
|
89
|
+
JalaliDate(1404, 1, 1, Jomeh)
|
|
90
|
+
|
|
91
|
+
>>> JalaliDate.fromtimestamp(578707200)
|
|
92
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
93
|
+
|
|
94
|
+
>>> JalaliDate(1400, 1, 1).replace(month=2, day=10)
|
|
95
|
+
JalaliDate(1400, 2, 10, Jomeh)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The week starts on Shanbeh (Saturday). `weekday()` counts from 0 (Shanbeh) to 6 (Jomeh), and `isoweekday()` from 1 to 7:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
>>> d = JalaliDate(1367, 2, 14) # a Chaharshanbeh (Wednesday)
|
|
102
|
+
>>> d.weekday()
|
|
103
|
+
4
|
|
104
|
+
>>> d.isoweekday()
|
|
105
|
+
5
|
|
106
|
+
>>> d.isocalendar()
|
|
107
|
+
IsoCalendarDate(year=1367, week=7, weekday=5)
|
|
108
|
+
>>> d.isoformat()
|
|
109
|
+
'1367-02-14'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Datetimes
|
|
113
|
+
|
|
114
|
+
`JalaliDateTime` adds time and timezone support on top of `JalaliDate`:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
>>> from persiantools.jdatetime import JalaliDateTime
|
|
118
|
+
>>> from zoneinfo import ZoneInfo
|
|
119
|
+
>>> import datetime
|
|
120
|
+
|
|
121
|
+
>>> JalaliDateTime.now(ZoneInfo("Asia/Tehran"))
|
|
122
|
+
JalaliDateTime(1405, 4, 12, 14, 30, 7, 907909, tzinfo=zoneinfo.ZoneInfo(key='Asia/Tehran'))
|
|
123
|
+
|
|
124
|
+
>>> JalaliDateTime(datetime.datetime(1988, 5, 4, 14, 30, 15))
|
|
125
|
+
JalaliDateTime(1367, 2, 14, 14, 30, 15)
|
|
126
|
+
|
|
127
|
+
>>> JalaliDateTime(1367, 2, 14, 14, 30, 15).to_gregorian()
|
|
128
|
+
datetime.datetime(1988, 5, 4, 14, 30, 15)
|
|
129
|
+
|
|
130
|
+
>>> JalaliDateTime(1367, 2, 14, 14, 30, tzinfo=datetime.timezone.utc).isoformat(timespec="minutes")
|
|
131
|
+
'1367-02-14T14:30+00:00'
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Formatting and parsing
|
|
135
|
+
|
|
136
|
+
Both classes support `strftime` and `strptime` with the familiar directives, in English or Persian:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
140
|
+
|
|
141
|
+
>>> JalaliDate(1367, 2, 14).strftime("%A %d %B %Y")
|
|
142
|
+
'Chaharshanbeh 14 Ordibehesht 1367'
|
|
143
|
+
|
|
144
|
+
>>> JalaliDateTime(1367, 2, 14, 14, 30).strftime("%c", locale="fa")
|
|
145
|
+
'چهارشنبه ۱۴ اردیبهشت ۱۳۶۷ ۱۴:۳۰:۰۰'
|
|
146
|
+
|
|
147
|
+
>>> JalaliDate.strptime("1367-02-14", "%Y-%m-%d")
|
|
148
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
149
|
+
|
|
150
|
+
>>> JalaliDateTime.strptime("1367/02/14 14:30", "%Y/%m/%d %H:%M")
|
|
151
|
+
JalaliDateTime(1367, 2, 14, 14, 30)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
A date created with `locale="fa"` renders itself with Persian digits and names everywhere:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
>>> JalaliDate(1367, 2, 14, locale="fa").isoformat()
|
|
158
|
+
'۱۳۶۷-۰۲-۱۴'
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Comparison and arithmetic
|
|
162
|
+
|
|
163
|
+
Jalali objects compare and do arithmetic with each other, with `timedelta`, and directly with their Gregorian counterparts:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
167
|
+
>>> import datetime
|
|
168
|
+
|
|
169
|
+
>>> JalaliDate(1367, 2, 14) == datetime.date(1988, 5, 4)
|
|
170
|
+
True
|
|
171
|
+
|
|
172
|
+
>>> JalaliDate(1395, 2, 14) + datetime.timedelta(days=38)
|
|
173
|
+
JalaliDate(1395, 3, 21, Jomeh)
|
|
174
|
+
|
|
175
|
+
>>> JalaliDateTime(1395, 12, 30) - JalaliDateTime(1395, 1, 1)
|
|
176
|
+
datetime.timedelta(days=365)
|
|
177
|
+
|
|
178
|
+
>>> JalaliDate(1399, 12, 30) > JalaliDate(1399, 12, 29) # leap-year Esfand 30
|
|
179
|
+
True
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
They are also hashable (usable as dict keys) and picklable, like the standard library types.
|
|
183
|
+
|
|
184
|
+
## Digits
|
|
185
|
+
|
|
186
|
+
Convert digits between English, Persian, and Arabic:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
>>> from persiantools import digits
|
|
190
|
+
|
|
191
|
+
>>> digits.en_to_fa("0987654321")
|
|
192
|
+
'۰۹۸۷۶۵۴۳۲۱'
|
|
193
|
+
|
|
194
|
+
>>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")
|
|
195
|
+
'۰۹۸۷۶۵۴۳۲۱'
|
|
196
|
+
|
|
197
|
+
>>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
|
|
198
|
+
'0987654321'
|
|
199
|
+
|
|
200
|
+
>>> digits.fa_to_ar("۰۹۸۷۶۵۴۳۲۱")
|
|
201
|
+
'٠٩٨٧٦٥٤٣٢١'
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
And spell numbers out in Persian — integers, floats, and negatives:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
>>> digits.to_word(9512026)
|
|
208
|
+
'نه میلیون و پانصد و دوازده هزار و بیست و شش'
|
|
209
|
+
|
|
210
|
+
>>> digits.to_word(15.007)
|
|
211
|
+
'پانزده و هفت هزارم'
|
|
212
|
+
|
|
213
|
+
>>> digits.to_word(-123.45)
|
|
214
|
+
'منفی یکصد و بیست و سه و چهل و پنج صدم'
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Characters
|
|
218
|
+
|
|
219
|
+
Arabic and Persian share letters that look alike but have different Unicode code points (`ك` vs `ک`, `ي` vs `ی`) — a common source of failed string matching and broken search. Normalize them in either direction:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
>>> from persiantools import characters
|
|
223
|
+
|
|
224
|
+
>>> characters.ar_to_fa("كيك")
|
|
225
|
+
'کیک'
|
|
226
|
+
|
|
227
|
+
>>> characters.fa_to_ar("کیک")
|
|
228
|
+
'كيك'
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Support this project
|
|
232
|
+
|
|
233
|
+
If persiantools saves you time, you can support its development with a donation:
|
|
234
|
+
|
|
235
|
+
| Coin | Address |
|
|
236
|
+
| --- | --- |
|
|
237
|
+
| Bitcoin (BTC) | `bc1qg5rp7ymznc98wmhltzvpwl2dvfuvjr33m4hy77` |
|
|
238
|
+
| Ethereum (ETH) | `0xC7D6bf306E456632764D0aD111C8dBBb43a3B9ad` |
|
|
239
|
+
| Tron (TRX) | `TDd63bVWZDBHmwVNFgJ6T2WdWmk9z7PBLg` |
|
|
240
|
+
| Stellar (XLM) | `GDSFPPLY34QSAOTOP4DQDXAI2YDRNRIADZHTN3HCGMQXRLIGPYOEH7L5` |
|
|
241
|
+
| USDT (BSC) | `0xC7D6bf306E456632764D0aD111C8dBBb43a3B9ad` |
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# PersianTools
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/persiantools/)
|
|
4
|
+

|
|
5
|
+
[](https://codecov.io/gh/majiidd/persiantools)
|
|
6
|
+
[](https://pypi.org/project/persiantools/)
|
|
7
|
+
[](https://pypi.org/project/persiantools/)
|
|
8
|
+
|
|
9
|
+
`PersianTools` provides Jalali (Shamsi) dates and datetimes that work just like Python's `datetime` — plus handy tools for Persian text: digit conversion between Persian, Arabic, and English, character normalization, and numbers to Persian words.
|
|
10
|
+
|
|
11
|
+
If you know `datetime.date` and `datetime.datetime`, you already know `JalaliDate` and `JalaliDateTime`. They support the same operations: comparison, arithmetic with `timedelta`, timezones, `strftime`/`strptime` and formatting, hashing, and pickling.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install persiantools
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Python 3.9 or newer. No dependencies, except `tzdata` on Windows for timezone data.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
25
|
+
>>> import datetime
|
|
26
|
+
|
|
27
|
+
>>> JalaliDate.today()
|
|
28
|
+
JalaliDate(1405, 4, 12, Jomeh)
|
|
29
|
+
|
|
30
|
+
>>> JalaliDate(datetime.date(1988, 5, 4)) # Gregorian → Jalali
|
|
31
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
32
|
+
|
|
33
|
+
>>> JalaliDate(1367, 2, 14).to_gregorian() # Jalali → Gregorian
|
|
34
|
+
datetime.date(1988, 5, 4)
|
|
35
|
+
|
|
36
|
+
>>> JalaliDateTime.now().strftime("%A %d %B %Y, %H:%M")
|
|
37
|
+
'Jomeh 12 Tir 1405, 14:30'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Dates
|
|
41
|
+
|
|
42
|
+
Create a `JalaliDate` from Jalali values, a Gregorian date, an ISO string, or a timestamp:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
>>> from persiantools.jdatetime import JalaliDate
|
|
46
|
+
>>> import datetime
|
|
47
|
+
|
|
48
|
+
>>> JalaliDate(1367, 2, 14)
|
|
49
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
50
|
+
|
|
51
|
+
>>> JalaliDate.to_jalali(2013, 9, 16)
|
|
52
|
+
JalaliDate(1392, 6, 25, Doshanbeh)
|
|
53
|
+
|
|
54
|
+
>>> JalaliDate.fromisoformat("1404-01-01")
|
|
55
|
+
JalaliDate(1404, 1, 1, Jomeh)
|
|
56
|
+
|
|
57
|
+
>>> JalaliDate.fromtimestamp(578707200)
|
|
58
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
59
|
+
|
|
60
|
+
>>> JalaliDate(1400, 1, 1).replace(month=2, day=10)
|
|
61
|
+
JalaliDate(1400, 2, 10, Jomeh)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The week starts on Shanbeh (Saturday). `weekday()` counts from 0 (Shanbeh) to 6 (Jomeh), and `isoweekday()` from 1 to 7:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
>>> d = JalaliDate(1367, 2, 14) # a Chaharshanbeh (Wednesday)
|
|
68
|
+
>>> d.weekday()
|
|
69
|
+
4
|
|
70
|
+
>>> d.isoweekday()
|
|
71
|
+
5
|
|
72
|
+
>>> d.isocalendar()
|
|
73
|
+
IsoCalendarDate(year=1367, week=7, weekday=5)
|
|
74
|
+
>>> d.isoformat()
|
|
75
|
+
'1367-02-14'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Datetimes
|
|
79
|
+
|
|
80
|
+
`JalaliDateTime` adds time and timezone support on top of `JalaliDate`:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
>>> from persiantools.jdatetime import JalaliDateTime
|
|
84
|
+
>>> from zoneinfo import ZoneInfo
|
|
85
|
+
>>> import datetime
|
|
86
|
+
|
|
87
|
+
>>> JalaliDateTime.now(ZoneInfo("Asia/Tehran"))
|
|
88
|
+
JalaliDateTime(1405, 4, 12, 14, 30, 7, 907909, tzinfo=zoneinfo.ZoneInfo(key='Asia/Tehran'))
|
|
89
|
+
|
|
90
|
+
>>> JalaliDateTime(datetime.datetime(1988, 5, 4, 14, 30, 15))
|
|
91
|
+
JalaliDateTime(1367, 2, 14, 14, 30, 15)
|
|
92
|
+
|
|
93
|
+
>>> JalaliDateTime(1367, 2, 14, 14, 30, 15).to_gregorian()
|
|
94
|
+
datetime.datetime(1988, 5, 4, 14, 30, 15)
|
|
95
|
+
|
|
96
|
+
>>> JalaliDateTime(1367, 2, 14, 14, 30, tzinfo=datetime.timezone.utc).isoformat(timespec="minutes")
|
|
97
|
+
'1367-02-14T14:30+00:00'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Formatting and parsing
|
|
101
|
+
|
|
102
|
+
Both classes support `strftime` and `strptime` with the familiar directives, in English or Persian:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
106
|
+
|
|
107
|
+
>>> JalaliDate(1367, 2, 14).strftime("%A %d %B %Y")
|
|
108
|
+
'Chaharshanbeh 14 Ordibehesht 1367'
|
|
109
|
+
|
|
110
|
+
>>> JalaliDateTime(1367, 2, 14, 14, 30).strftime("%c", locale="fa")
|
|
111
|
+
'چهارشنبه ۱۴ اردیبهشت ۱۳۶۷ ۱۴:۳۰:۰۰'
|
|
112
|
+
|
|
113
|
+
>>> JalaliDate.strptime("1367-02-14", "%Y-%m-%d")
|
|
114
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
115
|
+
|
|
116
|
+
>>> JalaliDateTime.strptime("1367/02/14 14:30", "%Y/%m/%d %H:%M")
|
|
117
|
+
JalaliDateTime(1367, 2, 14, 14, 30)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
A date created with `locale="fa"` renders itself with Persian digits and names everywhere:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
>>> JalaliDate(1367, 2, 14, locale="fa").isoformat()
|
|
124
|
+
'۱۳۶۷-۰۲-۱۴'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Comparison and arithmetic
|
|
128
|
+
|
|
129
|
+
Jalali objects compare and do arithmetic with each other, with `timedelta`, and directly with their Gregorian counterparts:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
133
|
+
>>> import datetime
|
|
134
|
+
|
|
135
|
+
>>> JalaliDate(1367, 2, 14) == datetime.date(1988, 5, 4)
|
|
136
|
+
True
|
|
137
|
+
|
|
138
|
+
>>> JalaliDate(1395, 2, 14) + datetime.timedelta(days=38)
|
|
139
|
+
JalaliDate(1395, 3, 21, Jomeh)
|
|
140
|
+
|
|
141
|
+
>>> JalaliDateTime(1395, 12, 30) - JalaliDateTime(1395, 1, 1)
|
|
142
|
+
datetime.timedelta(days=365)
|
|
143
|
+
|
|
144
|
+
>>> JalaliDate(1399, 12, 30) > JalaliDate(1399, 12, 29) # leap-year Esfand 30
|
|
145
|
+
True
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
They are also hashable (usable as dict keys) and picklable, like the standard library types.
|
|
149
|
+
|
|
150
|
+
## Digits
|
|
151
|
+
|
|
152
|
+
Convert digits between English, Persian, and Arabic:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
>>> from persiantools import digits
|
|
156
|
+
|
|
157
|
+
>>> digits.en_to_fa("0987654321")
|
|
158
|
+
'۰۹۸۷۶۵۴۳۲۱'
|
|
159
|
+
|
|
160
|
+
>>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")
|
|
161
|
+
'۰۹۸۷۶۵۴۳۲۱'
|
|
162
|
+
|
|
163
|
+
>>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
|
|
164
|
+
'0987654321'
|
|
165
|
+
|
|
166
|
+
>>> digits.fa_to_ar("۰۹۸۷۶۵۴۳۲۱")
|
|
167
|
+
'٠٩٨٧٦٥٤٣٢١'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
And spell numbers out in Persian — integers, floats, and negatives:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
>>> digits.to_word(9512026)
|
|
174
|
+
'نه میلیون و پانصد و دوازده هزار و بیست و شش'
|
|
175
|
+
|
|
176
|
+
>>> digits.to_word(15.007)
|
|
177
|
+
'پانزده و هفت هزارم'
|
|
178
|
+
|
|
179
|
+
>>> digits.to_word(-123.45)
|
|
180
|
+
'منفی یکصد و بیست و سه و چهل و پنج صدم'
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Characters
|
|
184
|
+
|
|
185
|
+
Arabic and Persian share letters that look alike but have different Unicode code points (`ك` vs `ک`, `ي` vs `ی`) — a common source of failed string matching and broken search. Normalize them in either direction:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
>>> from persiantools import characters
|
|
189
|
+
|
|
190
|
+
>>> characters.ar_to_fa("كيك")
|
|
191
|
+
'کیک'
|
|
192
|
+
|
|
193
|
+
>>> characters.fa_to_ar("کیک")
|
|
194
|
+
'كيك'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Support this project
|
|
198
|
+
|
|
199
|
+
If persiantools saves you time, you can support its development with a donation:
|
|
200
|
+
|
|
201
|
+
| Coin | Address |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| Bitcoin (BTC) | `bc1qg5rp7ymznc98wmhltzvpwl2dvfuvjr33m4hy77` |
|
|
204
|
+
| Ethereum (ETH) | `0xC7D6bf306E456632764D0aD111C8dBBb43a3B9ad` |
|
|
205
|
+
| Tron (TRX) | `TDd63bVWZDBHmwVNFgJ6T2WdWmk9z7PBLg` |
|
|
206
|
+
| Stellar (XLM) | `GDSFPPLY34QSAOTOP4DQDXAI2YDRNRIADZHTN3HCGMQXRLIGPYOEH7L5` |
|
|
207
|
+
| USDT (BSC) | `0xC7D6bf306E456632764D0aD111C8dBBb43a3B9ad` |
|