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.
Files changed (27) hide show
  1. {persiantools-3.0.0 → persiantools-5.1.1}/LICENSE +2 -2
  2. persiantools-5.1.1/MANIFEST.in +1 -0
  3. {persiantools-3.0.0/persiantools.egg-info → persiantools-5.1.1}/PKG-INFO +76 -58
  4. {persiantools-3.0.0 → persiantools-5.1.1}/README.md +58 -49
  5. {persiantools-3.0.0 → persiantools-5.1.1}/persiantools/__init__.py +2 -2
  6. persiantools-5.1.1/persiantools/characters.py +61 -0
  7. persiantools-5.1.1/persiantools/digits.py +264 -0
  8. {persiantools-3.0.0 → persiantools-5.1.1}/persiantools/jdatetime.py +785 -130
  9. persiantools-5.1.1/persiantools/utils.py +25 -0
  10. {persiantools-3.0.0 → persiantools-5.1.1/persiantools.egg-info}/PKG-INFO +76 -58
  11. {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/SOURCES.txt +7 -1
  12. persiantools-5.1.1/persiantools.egg-info/requires.txt +1 -0
  13. {persiantools-3.0.0 → persiantools-5.1.1}/setup.py +6 -5
  14. persiantools-5.1.1/tests/test_characters.py +50 -0
  15. persiantools-5.1.1/tests/test_digits.py +89 -0
  16. persiantools-5.1.1/tests/test_jalalidate.py +548 -0
  17. persiantools-5.1.1/tests/test_jalalidatetime.py +639 -0
  18. persiantools-5.1.1/tests/test_utils.py +62 -0
  19. persiantools-3.0.0/MANIFEST.in +0 -1
  20. persiantools-3.0.0/persiantools/characters.py +0 -41
  21. persiantools-3.0.0/persiantools/digits.py +0 -191
  22. persiantools-3.0.0/persiantools/utils.py +0 -10
  23. {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/dependency_links.txt +0 -0
  24. {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/not-zip-safe +0 -0
  25. {persiantools-3.0.0 → persiantools-5.1.1}/persiantools.egg-info/top_level.txt +0 -0
  26. {persiantools-3.0.0 → persiantools-5.1.1}/pyproject.toml +0 -0
  27. {persiantools-3.0.0 → persiantools-5.1.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2016-2021 Majid Hajiloo
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
1
+ Metadata-Version: 2.2
2
2
  Name: persiantools
3
- Version: 3.0.0
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.6
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
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/persiantools.svg)](https://pypi.org/project/persiantools/)
40
51
  [![PyPI - License](https://img.shields.io/pypi/l/persiantools.svg)](https://pypi.org/project/persiantools/)
41
52
 
42
- - Jalali (Shamsi) date and datetime (based on python datetime's module)
43
-
44
- - Convert Jalali to Gregorian date/datetime and vice versa
45
- - Support comparison and arithmetic operators such as `+`, `-`, `==`, `>=`
46
- - Support timezone
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
- ```{.sourceCode .bash}
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
- ## How to use
66
+ ## Usage Guide
59
67
 
60
- ### Date
68
+ ### Date Operations
61
69
 
62
- ```{.sourceCode .python}
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(1395, 4, 18, Jomeh)
76
+ JalaliDate(1403, 8, 18, Jomeh)
68
77
 
69
- >>> JalaliDate(1369, 7, 1)
70
- JalaliDate(1369, 7, 1, Yekshanbeh)
78
+ >>> JalaliDate(1367, 2, 14)
79
+ JalaliDate(1367, 2, 14, Chaharshanbeh)
71
80
 
72
- >>> JalaliDate(datetime.date(1990, 9, 23)) # Gregorian to Jalali
73
- JalaliDate(1369, 7, 1, Yekshanbeh)
81
+ # Convert Gregorian to Jalali
82
+ >>> JalaliDate(datetime.date(1988, 5, 4))
83
+ JalaliDate(1367, 2, 14, Chaharshanbeh)
74
84
 
75
- >>> JalaliDate.to_jalali(2013, 9, 16) # Gregorian to Jalali
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
- >>> JalaliDate(1392, 6, 25).to_gregorian() # Jalali to Gregorian
89
+ # Convert from Jalali to Gregorian
90
+ >>> JalaliDate(1392, 6, 25).to_gregorian()
79
91
  datetime.date(2013, 9, 16)
80
92
 
81
- >>> JalaliDate.fromtimestamp(578707200) # Timestamp to Jalali
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
- ```{.sourceCode .python}
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(1395, 4, 18, 1, 43, 24, 720505)
106
+ JalaliDateTime(1403, 8, 18, 12, 48, 54, 569082)
93
107
 
94
- >>> JalaliDateTime.now().to_gregorian() # Jalali to Gregorian
95
- datetime.datetime(2016, 7, 8, 1, 43, 24, 720505)
108
+ # Convert Jalali datetime to Gregorian
109
+ >>> JalaliDateTime.now().to_gregorian()
110
+ datetime.datetime(2024, 11, 8, 12, 48, 54, 569082)
96
111
 
97
- >>> JalaliDateTime.to_jalali(datetime.datetime(1988, 5, 4, 14, 0, 0, 0)) # Gregorian to Jalali
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
- >>> JalaliDateTime.fromtimestamp(578723400, pytz.timezone("Asia/Tehran")) # Timestamp to Jalali
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
- ### Format
124
+ ### Formatting
108
125
 
109
126
  Based on python `strftime()` behavior
110
127
 
111
- ```{.sourceCode .python}
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/Characters Tools
145
+ ### Digits and Character Conversion
129
146
 
130
- ```{.sourceCode .python}
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
- ```{.sourceCode .python}
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(1369, 7, 1, 1, 0)
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 de-serializing
196
+ ### Serializing and Deserializing
175
197
 
176
- ```{.sourceCode .python}
198
+ ```python
177
199
  >>> from persiantools.jdatetime import JalaliDate
178
200
  >>> import pickle
179
201
 
180
- >>> # Serializing
181
- >>> file = open("save.p", "wb")
182
- >>> pickle.dump(JalaliDate(1367, 2, 14), file)
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
- >>> # de-serializing
186
- >>> file = open("save.p", "rb")
187
- >>> jalali = pickle.load(file)
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
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/persiantools.svg)](https://pypi.org/project/persiantools/)
8
8
  [![PyPI - License](https://img.shields.io/pypi/l/persiantools.svg)](https://pypi.org/project/persiantools/)
9
9
 
10
- - Jalali (Shamsi) date and datetime (based on python datetime's module)
11
-
12
- - Convert Jalali to Gregorian date/datetime and vice versa
13
- - Support comparison and arithmetic operators such as `+`, `-`, `==`, `>=`
14
- - Support timezone
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
- ```{.sourceCode .bash}
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
- ## How to use
23
+ ## Usage Guide
27
24
 
28
- ### Date
25
+ ### Date Operations
29
26
 
30
- ```{.sourceCode .python}
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(1395, 4, 18, Jomeh)
33
+ JalaliDate(1403, 8, 18, Jomeh)
36
34
 
37
- >>> JalaliDate(1369, 7, 1)
38
- JalaliDate(1369, 7, 1, Yekshanbeh)
35
+ >>> JalaliDate(1367, 2, 14)
36
+ JalaliDate(1367, 2, 14, Chaharshanbeh)
39
37
 
40
- >>> JalaliDate(datetime.date(1990, 9, 23)) # Gregorian to Jalali
41
- JalaliDate(1369, 7, 1, Yekshanbeh)
38
+ # Convert Gregorian to Jalali
39
+ >>> JalaliDate(datetime.date(1988, 5, 4))
40
+ JalaliDate(1367, 2, 14, Chaharshanbeh)
42
41
 
43
- >>> JalaliDate.to_jalali(2013, 9, 16) # Gregorian to Jalali
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
- >>> JalaliDate(1392, 6, 25).to_gregorian() # Jalali to Gregorian
46
+ # Convert from Jalali to Gregorian
47
+ >>> JalaliDate(1392, 6, 25).to_gregorian()
47
48
  datetime.date(2013, 9, 16)
48
49
 
49
- >>> JalaliDate.fromtimestamp(578707200) # Timestamp to Jalali
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
- ```{.sourceCode .python}
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(1395, 4, 18, 1, 43, 24, 720505)
63
+ JalaliDateTime(1403, 8, 18, 12, 48, 54, 569082)
61
64
 
62
- >>> JalaliDateTime.now().to_gregorian() # Jalali to Gregorian
63
- datetime.datetime(2016, 7, 8, 1, 43, 24, 720505)
65
+ # Convert Jalali datetime to Gregorian
66
+ >>> JalaliDateTime.now().to_gregorian()
67
+ datetime.datetime(2024, 11, 8, 12, 48, 54, 569082)
64
68
 
65
- >>> JalaliDateTime.to_jalali(datetime.datetime(1988, 5, 4, 14, 0, 0, 0)) # Gregorian to Jalali
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
- >>> JalaliDateTime.fromtimestamp(578723400, pytz.timezone("Asia/Tehran")) # Timestamp to Jalali
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
- ### Format
81
+ ### Formatting
76
82
 
77
83
  Based on python `strftime()` behavior
78
84
 
79
- ```{.sourceCode .python}
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/Characters Tools
102
+ ### Digits and Character Conversion
97
103
 
98
- ```{.sourceCode .python}
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
- ```{.sourceCode .python}
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(1369, 7, 1, 1, 0)
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 de-serializing
153
+ ### Serializing and Deserializing
143
154
 
144
- ```{.sourceCode .python}
155
+ ```python
145
156
  >>> from persiantools.jdatetime import JalaliDate
146
157
  >>> import pickle
147
158
 
148
- >>> # Serializing
149
- >>> file = open("save.p", "wb")
150
- >>> pickle.dump(JalaliDate(1367, 2, 14), file)
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
- >>> # de-serializing
154
- >>> file = open("save.p", "rb")
155
- >>> jalali = pickle.load(file)
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__ = "3.0.0"
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-2022 Majid Hajiloo"
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)