persiantools 3.0.0__tar.gz → 5.1.1__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-3.0.0 → persiantools-5.1.1}/LICENSE +2 -2
- persiantools-5.1.1/MANIFEST.in +1 -0
- {persiantools-3.0.0/persiantools.egg-info → persiantools-5.1.1}/PKG-INFO +76 -58
- {persiantools-3.0.0 → persiantools-5.1.1}/README.md +58 -49
- {persiantools-3.0.0 → persiantools-5.1.1}/persiantools/__init__.py +2 -2
- persiantools-5.1.1/persiantools/characters.py +61 -0
- persiantools-5.1.1/persiantools/digits.py +264 -0
- {persiantools-3.0.0 → persiantools-5.1.1}/persiantools/jdatetime.py +785 -130
- persiantools-5.1.1/persiantools/utils.py +25 -0
- {persiantools-3.0.0 → persiantools-5.1.1/persiantools.egg-info}/PKG-INFO +76 -58
- {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/SOURCES.txt +7 -1
- persiantools-5.1.1/persiantools.egg-info/requires.txt +1 -0
- {persiantools-3.0.0 → persiantools-5.1.1}/setup.py +6 -5
- persiantools-5.1.1/tests/test_characters.py +50 -0
- persiantools-5.1.1/tests/test_digits.py +89 -0
- persiantools-5.1.1/tests/test_jalalidate.py +548 -0
- persiantools-5.1.1/tests/test_jalalidatetime.py +639 -0
- persiantools-5.1.1/tests/test_utils.py +62 -0
- persiantools-3.0.0/MANIFEST.in +0 -1
- persiantools-3.0.0/persiantools/characters.py +0 -41
- persiantools-3.0.0/persiantools/digits.py +0 -191
- persiantools-3.0.0/persiantools/utils.py +0 -10
- {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/dependency_links.txt +0 -0
- {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/not-zip-safe +0 -0
- {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/top_level.txt +0 -0
- {persiantools-3.0.0 → persiantools-5.1.1}/pyproject.toml +0 -0
- {persiantools-3.0.0 → persiantools-5.1.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2016-
|
|
3
|
+
Copyright (c) 2016-2024 Majid Hajiloo
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include LICENSE README.md
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: persiantools
|
|
3
|
-
Version:
|
|
3
|
+
Version: 5.1.1
|
|
4
4
|
Summary: Jalali date and datetime with other tools
|
|
5
5
|
Home-page: https://github.com/majiidd/persiantools
|
|
6
6
|
Author: Majid Hajiloo
|
|
7
7
|
Author-email: majid.hajiloo@gmail.com
|
|
8
8
|
License: MIT
|
|
9
9
|
Keywords: jalali shamsi persian digits characters converter jalalidate jalalidatetime date datetime jdate jdatetime farsi
|
|
10
|
-
Platform: UNKNOWN
|
|
11
10
|
Classifier: Intended Audience :: Developers
|
|
12
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
12
|
Classifier: Natural Language :: Persian
|
|
14
13
|
Classifier: Operating System :: OS Independent
|
|
15
14
|
Classifier: Programming Language :: Python
|
|
16
15
|
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
20
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
21
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
|
|
22
21
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
22
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
24
23
|
Classifier: Topic :: Software Development
|
|
@@ -26,9 +25,21 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
26
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
26
|
Classifier: Topic :: Software Development :: Localization
|
|
28
27
|
Classifier: Topic :: Utilities
|
|
29
|
-
Requires-Python: >=3.
|
|
28
|
+
Requires-Python: >=3.9
|
|
30
29
|
Description-Content-Type: text/markdown
|
|
31
30
|
License-File: LICENSE
|
|
31
|
+
Requires-Dist: pytz
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: description
|
|
36
|
+
Dynamic: description-content-type
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: keywords
|
|
39
|
+
Dynamic: license
|
|
40
|
+
Dynamic: requires-dist
|
|
41
|
+
Dynamic: requires-python
|
|
42
|
+
Dynamic: summary
|
|
32
43
|
|
|
33
44
|
# PersianTools
|
|
34
45
|
|
|
@@ -39,126 +50,137 @@ License-File: LICENSE
|
|
|
39
50
|
[](https://pypi.org/project/persiantools/)
|
|
40
51
|
[](https://pypi.org/project/persiantools/)
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Convert Arabic and Persian characters/digits to each other
|
|
49
|
-
- Convert numbers to words
|
|
53
|
+
PersianTools provides comprehensive tools for handling Jalali (Shamsi or Persian) dates, date-time functionalities, and more.
|
|
54
|
+
- Conversion between Jalali and Gregorian dates/datetimes using Python's native datetime module.
|
|
55
|
+
- Full support for operations like `+`, `-`, `==`, and `>=`.
|
|
56
|
+
- Timezone-aware date and datetime handling.
|
|
57
|
+
- Conversion between Persian and Arabic characters and digits.
|
|
58
|
+
- Conversion of numbers to their Persian word representation.
|
|
50
59
|
|
|
51
60
|
## Install Package
|
|
52
|
-
|
|
53
|
-
```
|
|
61
|
+
You can install the package using pip with the following command:
|
|
62
|
+
```bash
|
|
54
63
|
python -m pip install persiantools
|
|
55
64
|
```
|
|
56
|
-
Persiantools supports Python 3.6+. (_for python 2.7 and 3.5 use [1.5.x](https://github.com/majiidd/persiantools/tree/1.5.x) version_)
|
|
57
65
|
|
|
58
|
-
##
|
|
66
|
+
## Usage Guide
|
|
59
67
|
|
|
60
|
-
### Date
|
|
68
|
+
### Date Operations
|
|
61
69
|
|
|
62
|
-
```
|
|
70
|
+
```python
|
|
63
71
|
>>> from persiantools.jdatetime import JalaliDate
|
|
64
72
|
>>> import datetime
|
|
65
73
|
|
|
74
|
+
# Get today's date in Jalali
|
|
66
75
|
>>> JalaliDate.today()
|
|
67
|
-
JalaliDate(
|
|
76
|
+
JalaliDate(1403, 8, 18, Jomeh)
|
|
68
77
|
|
|
69
|
-
>>> JalaliDate(
|
|
70
|
-
JalaliDate(
|
|
78
|
+
>>> JalaliDate(1367, 2, 14)
|
|
79
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
71
80
|
|
|
72
|
-
|
|
73
|
-
JalaliDate(
|
|
81
|
+
# Convert Gregorian to Jalali
|
|
82
|
+
>>> JalaliDate(datetime.date(1988, 5, 4))
|
|
83
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
74
84
|
|
|
75
|
-
|
|
85
|
+
# Convert from Gregorian to Jalali using method
|
|
86
|
+
>>> JalaliDate.to_jalali(2013, 9, 16)
|
|
76
87
|
JalaliDate(1392, 6, 25, Doshanbeh)
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
# Convert from Jalali to Gregorian
|
|
90
|
+
>>> JalaliDate(1392, 6, 25).to_gregorian()
|
|
79
91
|
datetime.date(2013, 9, 16)
|
|
80
92
|
|
|
81
|
-
|
|
93
|
+
# Create a Jalali date from a Unix timestamp
|
|
94
|
+
>>> JalaliDate.fromtimestamp(578707200)
|
|
82
95
|
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
83
96
|
```
|
|
84
97
|
|
|
85
|
-
### Datetime
|
|
98
|
+
### Datetime Operations
|
|
86
99
|
|
|
87
|
-
```
|
|
100
|
+
```python
|
|
88
101
|
>>> from persiantools.jdatetime import JalaliDateTime
|
|
89
102
|
>>> import datetime, pytz
|
|
90
103
|
|
|
104
|
+
# Get the current Jalali datetime
|
|
91
105
|
>>> JalaliDateTime.now()
|
|
92
|
-
JalaliDateTime(
|
|
106
|
+
JalaliDateTime(1403, 8, 18, 12, 48, 54, 569082)
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
# Convert Jalali datetime to Gregorian
|
|
109
|
+
>>> JalaliDateTime.now().to_gregorian()
|
|
110
|
+
datetime.datetime(2024, 11, 8, 12, 48, 54, 569082)
|
|
96
111
|
|
|
97
|
-
|
|
112
|
+
# Convert Gregorian datetime to Jalali
|
|
113
|
+
>>> JalaliDateTime.to_jalali(datetime.datetime(1988, 5, 4, 14, 0, 0, 0))
|
|
98
114
|
JalaliDateTime(1367, 2, 14, 14, 0)
|
|
99
115
|
|
|
100
|
-
|
|
116
|
+
# Create a timezone-aware Jalali datetime from a timestamp
|
|
117
|
+
>>> JalaliDateTime.fromtimestamp(578723400, pytz.timezone("Asia/Tehran"))
|
|
101
118
|
JalaliDateTime(1367, 2, 14, 8, 0, tzinfo=<DstTzInfo 'Asia/Tehran' +0330+3:30:00 STD>)
|
|
102
119
|
|
|
103
120
|
>>> JalaliDateTime.now(pytz.utc)
|
|
104
121
|
JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=<UTC>)
|
|
105
122
|
```
|
|
106
123
|
|
|
107
|
-
###
|
|
124
|
+
### Formatting
|
|
108
125
|
|
|
109
126
|
Based on python `strftime()` behavior
|
|
110
127
|
|
|
111
|
-
```
|
|
128
|
+
```python
|
|
112
129
|
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
113
130
|
>>> import pytz
|
|
114
131
|
|
|
132
|
+
# ISO formatting
|
|
115
133
|
>>> JalaliDate(1367, 2, 14).isoformat()
|
|
116
134
|
'1367-02-14'
|
|
117
135
|
|
|
136
|
+
# Custom date formatting
|
|
118
137
|
>>> JalaliDate(1395, 3, 1).strftime("%Y/%m/%d")
|
|
119
138
|
'1395/03/01'
|
|
120
139
|
|
|
140
|
+
# Custom datetime formatting
|
|
121
141
|
>>> JalaliDateTime(1369, 7, 1, 14, 0, 10, 0, pytz.utc).strftime("%c")
|
|
122
142
|
'Yekshanbeh 01 Mehr 1369 14:00:10'
|
|
123
|
-
|
|
124
|
-
>>> JalaliDateTime.now(pytz.utc).strftime("%I:%M:%S.%f %p %z %Z")
|
|
125
|
-
'01:49:22.518523 PM +0000 UTC'
|
|
126
143
|
```
|
|
127
144
|
|
|
128
|
-
### Digits
|
|
145
|
+
### Digits and Character Conversion
|
|
129
146
|
|
|
130
|
-
```
|
|
147
|
+
```python
|
|
131
148
|
>>> from persiantools import characters, digits
|
|
132
149
|
|
|
150
|
+
# Convert English digits to Persian
|
|
133
151
|
>>> digits.en_to_fa("0987654321")
|
|
134
152
|
'۰۹۸۷۶۵۴۳۲۱'
|
|
135
153
|
|
|
154
|
+
# Convert Arabic digits to Persian
|
|
136
155
|
>>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")
|
|
137
156
|
'۰۹۸۷۶۵۴۳۲۱'
|
|
138
157
|
|
|
158
|
+
# Convert Persian digits to English
|
|
139
159
|
>>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
|
|
140
160
|
'0987654321'
|
|
141
161
|
|
|
162
|
+
# Convert numbers to Persian words
|
|
142
163
|
>>> digits.to_word(9512026)
|
|
143
164
|
'نه میلیون و پانصد و دوازده هزار و بیست و شش'
|
|
144
165
|
|
|
145
166
|
>>> digits.to_word(15.007)
|
|
146
167
|
'پانزده و هفت هزارم'
|
|
147
168
|
|
|
169
|
+
# Convert Arabic to Persian characters
|
|
148
170
|
>>> characters.ar_to_fa("كيك")
|
|
149
171
|
'کیک'
|
|
150
172
|
```
|
|
151
173
|
|
|
152
174
|
### Operators
|
|
153
|
-
|
|
154
|
-
```
|
|
175
|
+
The package supports various operators for date and time manipulations. Here are some examples:
|
|
176
|
+
```python
|
|
155
177
|
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
156
178
|
>>> import datetime
|
|
157
179
|
|
|
158
180
|
>>> JalaliDate(1367, 2, 14) == JalaliDate(datetime.date(1988, 5, 4))
|
|
159
181
|
True
|
|
160
182
|
|
|
161
|
-
>>> JalaliDateTime(1367, 2, 14, 4, 30) >= JalaliDateTime(
|
|
183
|
+
>>> JalaliDateTime(1367, 2, 14, 4, 30) >= JalaliDateTime(1368, 2, 14, 1, 0)
|
|
162
184
|
False
|
|
163
185
|
|
|
164
186
|
>>> JalaliDate(1367, 2, 14) == datetime.date(1988, 5, 4)
|
|
@@ -171,23 +193,19 @@ JalaliDate(1395, 3, 21, Jomeh)
|
|
|
171
193
|
datetime.timedelta(365)
|
|
172
194
|
```
|
|
173
195
|
|
|
174
|
-
### Serializing and
|
|
196
|
+
### Serializing and Deserializing
|
|
175
197
|
|
|
176
|
-
```
|
|
198
|
+
```python
|
|
177
199
|
>>> from persiantools.jdatetime import JalaliDate
|
|
178
200
|
>>> import pickle
|
|
179
201
|
|
|
180
|
-
|
|
181
|
-
>>>
|
|
182
|
-
>>>
|
|
183
|
-
>>> file.close()
|
|
202
|
+
# Serialize a Jalali date to a file
|
|
203
|
+
>>> with open("save.p", "wb") as file:
|
|
204
|
+
>>> pickle.dump(JalaliDate(1367, 2, 14), file)
|
|
184
205
|
|
|
185
|
-
|
|
186
|
-
>>>
|
|
187
|
-
>>>
|
|
188
|
-
>>> file.close()
|
|
206
|
+
# Deserialize from a file
|
|
207
|
+
>>> with open("save.p", "rb") as file:
|
|
208
|
+
>>> jalali = pickle.load(file)
|
|
189
209
|
>>> jalali
|
|
190
210
|
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
191
211
|
```
|
|
192
|
-
|
|
193
|
-
|
|
@@ -7,126 +7,137 @@
|
|
|
7
7
|
[](https://pypi.org/project/persiantools/)
|
|
8
8
|
[](https://pypi.org/project/persiantools/)
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- Convert Arabic and Persian characters/digits to each other
|
|
17
|
-
- Convert numbers to words
|
|
10
|
+
PersianTools provides comprehensive tools for handling Jalali (Shamsi or Persian) dates, date-time functionalities, and more.
|
|
11
|
+
- Conversion between Jalali and Gregorian dates/datetimes using Python's native datetime module.
|
|
12
|
+
- Full support for operations like `+`, `-`, `==`, and `>=`.
|
|
13
|
+
- Timezone-aware date and datetime handling.
|
|
14
|
+
- Conversion between Persian and Arabic characters and digits.
|
|
15
|
+
- Conversion of numbers to their Persian word representation.
|
|
18
16
|
|
|
19
17
|
## Install Package
|
|
20
|
-
|
|
21
|
-
```
|
|
18
|
+
You can install the package using pip with the following command:
|
|
19
|
+
```bash
|
|
22
20
|
python -m pip install persiantools
|
|
23
21
|
```
|
|
24
|
-
Persiantools supports Python 3.6+. (_for python 2.7 and 3.5 use [1.5.x](https://github.com/majiidd/persiantools/tree/1.5.x) version_)
|
|
25
22
|
|
|
26
|
-
##
|
|
23
|
+
## Usage Guide
|
|
27
24
|
|
|
28
|
-
### Date
|
|
25
|
+
### Date Operations
|
|
29
26
|
|
|
30
|
-
```
|
|
27
|
+
```python
|
|
31
28
|
>>> from persiantools.jdatetime import JalaliDate
|
|
32
29
|
>>> import datetime
|
|
33
30
|
|
|
31
|
+
# Get today's date in Jalali
|
|
34
32
|
>>> JalaliDate.today()
|
|
35
|
-
JalaliDate(
|
|
33
|
+
JalaliDate(1403, 8, 18, Jomeh)
|
|
36
34
|
|
|
37
|
-
>>> JalaliDate(
|
|
38
|
-
JalaliDate(
|
|
35
|
+
>>> JalaliDate(1367, 2, 14)
|
|
36
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
JalaliDate(
|
|
38
|
+
# Convert Gregorian to Jalali
|
|
39
|
+
>>> JalaliDate(datetime.date(1988, 5, 4))
|
|
40
|
+
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
# Convert from Gregorian to Jalali using method
|
|
43
|
+
>>> JalaliDate.to_jalali(2013, 9, 16)
|
|
44
44
|
JalaliDate(1392, 6, 25, Doshanbeh)
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
# Convert from Jalali to Gregorian
|
|
47
|
+
>>> JalaliDate(1392, 6, 25).to_gregorian()
|
|
47
48
|
datetime.date(2013, 9, 16)
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
# Create a Jalali date from a Unix timestamp
|
|
51
|
+
>>> JalaliDate.fromtimestamp(578707200)
|
|
50
52
|
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
### Datetime
|
|
55
|
+
### Datetime Operations
|
|
54
56
|
|
|
55
|
-
```
|
|
57
|
+
```python
|
|
56
58
|
>>> from persiantools.jdatetime import JalaliDateTime
|
|
57
59
|
>>> import datetime, pytz
|
|
58
60
|
|
|
61
|
+
# Get the current Jalali datetime
|
|
59
62
|
>>> JalaliDateTime.now()
|
|
60
|
-
JalaliDateTime(
|
|
63
|
+
JalaliDateTime(1403, 8, 18, 12, 48, 54, 569082)
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
# Convert Jalali datetime to Gregorian
|
|
66
|
+
>>> JalaliDateTime.now().to_gregorian()
|
|
67
|
+
datetime.datetime(2024, 11, 8, 12, 48, 54, 569082)
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
# Convert Gregorian datetime to Jalali
|
|
70
|
+
>>> JalaliDateTime.to_jalali(datetime.datetime(1988, 5, 4, 14, 0, 0, 0))
|
|
66
71
|
JalaliDateTime(1367, 2, 14, 14, 0)
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
# Create a timezone-aware Jalali datetime from a timestamp
|
|
74
|
+
>>> JalaliDateTime.fromtimestamp(578723400, pytz.timezone("Asia/Tehran"))
|
|
69
75
|
JalaliDateTime(1367, 2, 14, 8, 0, tzinfo=<DstTzInfo 'Asia/Tehran' +0330+3:30:00 STD>)
|
|
70
76
|
|
|
71
77
|
>>> JalaliDateTime.now(pytz.utc)
|
|
72
78
|
JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=<UTC>)
|
|
73
79
|
```
|
|
74
80
|
|
|
75
|
-
###
|
|
81
|
+
### Formatting
|
|
76
82
|
|
|
77
83
|
Based on python `strftime()` behavior
|
|
78
84
|
|
|
79
|
-
```
|
|
85
|
+
```python
|
|
80
86
|
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
81
87
|
>>> import pytz
|
|
82
88
|
|
|
89
|
+
# ISO formatting
|
|
83
90
|
>>> JalaliDate(1367, 2, 14).isoformat()
|
|
84
91
|
'1367-02-14'
|
|
85
92
|
|
|
93
|
+
# Custom date formatting
|
|
86
94
|
>>> JalaliDate(1395, 3, 1).strftime("%Y/%m/%d")
|
|
87
95
|
'1395/03/01'
|
|
88
96
|
|
|
97
|
+
# Custom datetime formatting
|
|
89
98
|
>>> JalaliDateTime(1369, 7, 1, 14, 0, 10, 0, pytz.utc).strftime("%c")
|
|
90
99
|
'Yekshanbeh 01 Mehr 1369 14:00:10'
|
|
91
|
-
|
|
92
|
-
>>> JalaliDateTime.now(pytz.utc).strftime("%I:%M:%S.%f %p %z %Z")
|
|
93
|
-
'01:49:22.518523 PM +0000 UTC'
|
|
94
100
|
```
|
|
95
101
|
|
|
96
|
-
### Digits
|
|
102
|
+
### Digits and Character Conversion
|
|
97
103
|
|
|
98
|
-
```
|
|
104
|
+
```python
|
|
99
105
|
>>> from persiantools import characters, digits
|
|
100
106
|
|
|
107
|
+
# Convert English digits to Persian
|
|
101
108
|
>>> digits.en_to_fa("0987654321")
|
|
102
109
|
'۰۹۸۷۶۵۴۳۲۱'
|
|
103
110
|
|
|
111
|
+
# Convert Arabic digits to Persian
|
|
104
112
|
>>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")
|
|
105
113
|
'۰۹۸۷۶۵۴۳۲۱'
|
|
106
114
|
|
|
115
|
+
# Convert Persian digits to English
|
|
107
116
|
>>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
|
|
108
117
|
'0987654321'
|
|
109
118
|
|
|
119
|
+
# Convert numbers to Persian words
|
|
110
120
|
>>> digits.to_word(9512026)
|
|
111
121
|
'نه میلیون و پانصد و دوازده هزار و بیست و شش'
|
|
112
122
|
|
|
113
123
|
>>> digits.to_word(15.007)
|
|
114
124
|
'پانزده و هفت هزارم'
|
|
115
125
|
|
|
126
|
+
# Convert Arabic to Persian characters
|
|
116
127
|
>>> characters.ar_to_fa("كيك")
|
|
117
128
|
'کیک'
|
|
118
129
|
```
|
|
119
130
|
|
|
120
131
|
### Operators
|
|
121
|
-
|
|
122
|
-
```
|
|
132
|
+
The package supports various operators for date and time manipulations. Here are some examples:
|
|
133
|
+
```python
|
|
123
134
|
>>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
|
|
124
135
|
>>> import datetime
|
|
125
136
|
|
|
126
137
|
>>> JalaliDate(1367, 2, 14) == JalaliDate(datetime.date(1988, 5, 4))
|
|
127
138
|
True
|
|
128
139
|
|
|
129
|
-
>>> JalaliDateTime(1367, 2, 14, 4, 30) >= JalaliDateTime(
|
|
140
|
+
>>> JalaliDateTime(1367, 2, 14, 4, 30) >= JalaliDateTime(1368, 2, 14, 1, 0)
|
|
130
141
|
False
|
|
131
142
|
|
|
132
143
|
>>> JalaliDate(1367, 2, 14) == datetime.date(1988, 5, 4)
|
|
@@ -139,21 +150,19 @@ JalaliDate(1395, 3, 21, Jomeh)
|
|
|
139
150
|
datetime.timedelta(365)
|
|
140
151
|
```
|
|
141
152
|
|
|
142
|
-
### Serializing and
|
|
153
|
+
### Serializing and Deserializing
|
|
143
154
|
|
|
144
|
-
```
|
|
155
|
+
```python
|
|
145
156
|
>>> from persiantools.jdatetime import JalaliDate
|
|
146
157
|
>>> import pickle
|
|
147
158
|
|
|
148
|
-
|
|
149
|
-
>>>
|
|
150
|
-
>>>
|
|
151
|
-
>>> file.close()
|
|
159
|
+
# Serialize a Jalali date to a file
|
|
160
|
+
>>> with open("save.p", "wb") as file:
|
|
161
|
+
>>> pickle.dump(JalaliDate(1367, 2, 14), file)
|
|
152
162
|
|
|
153
|
-
|
|
154
|
-
>>>
|
|
155
|
-
>>>
|
|
156
|
-
>>> file.close()
|
|
163
|
+
# Deserialize from a file
|
|
164
|
+
>>> with open("save.p", "rb") as file:
|
|
165
|
+
>>> jalali = pickle.load(file)
|
|
157
166
|
>>> jalali
|
|
158
167
|
JalaliDate(1367, 2, 14, Chaharshanbeh)
|
|
159
168
|
```
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
__title__ = "persiantools"
|
|
9
9
|
__url__ = "https://github.com/majiidd/persiantools"
|
|
10
|
-
__version__ = "
|
|
10
|
+
__version__ = "5.1.1"
|
|
11
11
|
__build__ = __version__
|
|
12
12
|
__author__ = "Majid Hajiloo"
|
|
13
13
|
__author_email__ = "majid.hajiloo@gmail.com"
|
|
14
14
|
__license__ = "MIT"
|
|
15
|
-
__copyright__ = "Copyright (c) 2016-
|
|
15
|
+
__copyright__ = "Copyright (c) 2016-2025 Majid Hajiloo"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from persiantools.utils import replace
|
|
2
|
+
|
|
3
|
+
CHARACTER_MAP_AR_TO_FA = {
|
|
4
|
+
"دِ": "د",
|
|
5
|
+
"بِ": "ب",
|
|
6
|
+
"زِ": "ز",
|
|
7
|
+
"ذِ": "ذ",
|
|
8
|
+
"شِ": "ش",
|
|
9
|
+
"سِ": "س",
|
|
10
|
+
"ى": "ی",
|
|
11
|
+
"ي": "ی",
|
|
12
|
+
"ك": "ک",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
CHARACTER_MAP_FA_TO_AR = {"ی": "ي", "ک": "ك"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def ar_to_fa(string: str) -> str:
|
|
19
|
+
"""
|
|
20
|
+
Convert Arabic characters to Persian.
|
|
21
|
+
|
|
22
|
+
Usage::
|
|
23
|
+
from persiantools import characters
|
|
24
|
+
converted = characters.ar_to_fa("السلام عليكم")
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
string (str): The string to convert.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
str: The converted string with Arabic characters replaced by Persian characters.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
TypeError: If the input string is not of type str.
|
|
34
|
+
"""
|
|
35
|
+
if not isinstance(string, str):
|
|
36
|
+
raise TypeError("Input must be of type str")
|
|
37
|
+
|
|
38
|
+
return replace(string, CHARACTER_MAP_AR_TO_FA)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def fa_to_ar(string: str) -> str:
|
|
42
|
+
"""
|
|
43
|
+
Convert Persian characters to Arabic.
|
|
44
|
+
|
|
45
|
+
Usage::
|
|
46
|
+
from persiantools import characters
|
|
47
|
+
converted = characters.fa_to_ar("ای چرخ فلک خرابی از کینه تست")
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
string (str): The string to convert.
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
str: The converted string with Persian characters replaced by Arabic characters.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
TypeError: If the input string is not of type str.
|
|
57
|
+
"""
|
|
58
|
+
if not isinstance(string, str):
|
|
59
|
+
raise TypeError("Input must be of type str")
|
|
60
|
+
|
|
61
|
+
return replace(string, CHARACTER_MAP_FA_TO_AR)
|