persiantools 3.0.1__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.1 → persiantools-5.1.1}/LICENSE +2 -2
  2. persiantools-5.1.1/MANIFEST.in +1 -0
  3. {persiantools-3.0.1/persiantools.egg-info → persiantools-5.1.1}/PKG-INFO +69 -48
  4. {persiantools-3.0.1 → persiantools-5.1.1}/README.md +51 -42
  5. {persiantools-3.0.1 → 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.1 → persiantools-5.1.1}/persiantools/jdatetime.py +785 -130
  9. persiantools-5.1.1/persiantools/utils.py +25 -0
  10. {persiantools-3.0.1 → persiantools-5.1.1/persiantools.egg-info}/PKG-INFO +69 -48
  11. {persiantools-3.0.1 → 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.1 → 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.1/MANIFEST.in +0 -1
  20. persiantools-3.0.1/persiantools/characters.py +0 -41
  21. persiantools-3.0.1/persiantools/digits.py +0 -191
  22. persiantools-3.0.1/persiantools/utils.py +0 -10
  23. {persiantools-3.0.1 → persiantools-5.1.1}/persiantools.egg-info/dependency_links.txt +0 -0
  24. {persiantools-3.0.1 → persiantools-5.1.1}/persiantools.egg-info/not-zip-safe +0 -0
  25. {persiantools-3.0.1 → persiantools-5.1.1}/persiantools.egg-info/top_level.txt +0 -0
  26. {persiantools-3.0.1 → persiantools-5.1.1}/pyproject.toml +0 -0
  27. {persiantools-3.0.1 → 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-2022 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,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: persiantools
3
- Version: 3.0.1
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
@@ -13,11 +13,11 @@ Classifier: Natural Language :: Persian
13
13
  Classifier: Operating System :: OS Independent
14
14
  Classifier: Programming Language :: Python
15
15
  Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.6
17
- Classifier: Programming Language :: Python :: 3.7
18
- Classifier: Programming Language :: Python :: 3.8
19
16
  Classifier: Programming Language :: Python :: 3.9
20
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
21
  Classifier: Programming Language :: Python :: Implementation :: CPython
22
22
  Classifier: Programming Language :: Python :: Implementation :: PyPy
23
23
  Classifier: Topic :: Software Development
@@ -25,9 +25,21 @@ Classifier: Topic :: Software Development :: Libraries
25
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
26
  Classifier: Topic :: Software Development :: Localization
27
27
  Classifier: Topic :: Utilities
28
- Requires-Python: >=3.6
28
+ Requires-Python: >=3.9
29
29
  Description-Content-Type: text/markdown
30
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
31
43
 
32
44
  # PersianTools
33
45
 
@@ -38,72 +50,78 @@ License-File: LICENSE
38
50
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/persiantools.svg)](https://pypi.org/project/persiantools/)
39
51
  [![PyPI - License](https://img.shields.io/pypi/l/persiantools.svg)](https://pypi.org/project/persiantools/)
40
52
 
41
- - Jalali (Shamsi) date and datetime (based on python datetime's module)
42
-
43
- - Convert Jalali to Gregorian date/datetime and vice versa
44
- - Support comparison and arithmetic operators such as `+`, `-`, `==`, `>=`
45
- - Support timezone
46
-
47
- - Convert Arabic and Persian characters/digits to each other
48
- - 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.
49
59
 
50
60
  ## Install Package
51
-
61
+ You can install the package using pip with the following command:
52
62
  ```bash
53
63
  python -m pip install persiantools
54
64
  ```
55
- 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_)
56
65
 
57
- ## How to use
66
+ ## Usage Guide
58
67
 
59
- ### Date
68
+ ### Date Operations
60
69
 
61
70
  ```python
62
71
  >>> from persiantools.jdatetime import JalaliDate
63
72
  >>> import datetime
64
73
 
74
+ # Get today's date in Jalali
65
75
  >>> JalaliDate.today()
66
- JalaliDate(1395, 4, 18, Jomeh)
76
+ JalaliDate(1403, 8, 18, Jomeh)
67
77
 
68
- >>> JalaliDate(1369, 7, 1)
69
- JalaliDate(1369, 7, 1, Yekshanbeh)
78
+ >>> JalaliDate(1367, 2, 14)
79
+ JalaliDate(1367, 2, 14, Chaharshanbeh)
70
80
 
71
- >>> JalaliDate(datetime.date(1990, 9, 23)) # Gregorian to Jalali
72
- JalaliDate(1369, 7, 1, Yekshanbeh)
81
+ # Convert Gregorian to Jalali
82
+ >>> JalaliDate(datetime.date(1988, 5, 4))
83
+ JalaliDate(1367, 2, 14, Chaharshanbeh)
73
84
 
74
- >>> JalaliDate.to_jalali(2013, 9, 16) # Gregorian to Jalali
85
+ # Convert from Gregorian to Jalali using method
86
+ >>> JalaliDate.to_jalali(2013, 9, 16)
75
87
  JalaliDate(1392, 6, 25, Doshanbeh)
76
88
 
77
- >>> JalaliDate(1392, 6, 25).to_gregorian() # Jalali to Gregorian
89
+ # Convert from Jalali to Gregorian
90
+ >>> JalaliDate(1392, 6, 25).to_gregorian()
78
91
  datetime.date(2013, 9, 16)
79
92
 
80
- >>> JalaliDate.fromtimestamp(578707200) # Timestamp to Jalali
93
+ # Create a Jalali date from a Unix timestamp
94
+ >>> JalaliDate.fromtimestamp(578707200)
81
95
  JalaliDate(1367, 2, 14, Chaharshanbeh)
82
96
  ```
83
97
 
84
- ### Datetime
98
+ ### Datetime Operations
85
99
 
86
100
  ```python
87
101
  >>> from persiantools.jdatetime import JalaliDateTime
88
102
  >>> import datetime, pytz
89
103
 
104
+ # Get the current Jalali datetime
90
105
  >>> JalaliDateTime.now()
91
- JalaliDateTime(1395, 4, 18, 1, 43, 24, 720505)
106
+ JalaliDateTime(1403, 8, 18, 12, 48, 54, 569082)
92
107
 
93
- >>> JalaliDateTime.now().to_gregorian() # Jalali to Gregorian
94
- 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)
95
111
 
96
- >>> 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))
97
114
  JalaliDateTime(1367, 2, 14, 14, 0)
98
115
 
99
- >>> 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"))
100
118
  JalaliDateTime(1367, 2, 14, 8, 0, tzinfo=<DstTzInfo 'Asia/Tehran' +0330+3:30:00 STD>)
101
119
 
102
120
  >>> JalaliDateTime.now(pytz.utc)
103
121
  JalaliDateTime(1395, 4, 17, 21, 23, 53, 474618, tzinfo=<UTC>)
104
122
  ```
105
123
 
106
- ### Format
124
+ ### Formatting
107
125
 
108
126
  Based on python `strftime()` behavior
109
127
 
@@ -111,45 +129,50 @@ Based on python `strftime()` behavior
111
129
  >>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
112
130
  >>> import pytz
113
131
 
132
+ # ISO formatting
114
133
  >>> JalaliDate(1367, 2, 14).isoformat()
115
134
  '1367-02-14'
116
135
 
136
+ # Custom date formatting
117
137
  >>> JalaliDate(1395, 3, 1).strftime("%Y/%m/%d")
118
138
  '1395/03/01'
119
139
 
140
+ # Custom datetime formatting
120
141
  >>> JalaliDateTime(1369, 7, 1, 14, 0, 10, 0, pytz.utc).strftime("%c")
121
142
  'Yekshanbeh 01 Mehr 1369 14:00:10'
122
-
123
- >>> JalaliDateTime.now(pytz.utc).strftime("%I:%M:%S.%f %p %z %Z")
124
- '01:49:22.518523 PM +0000 UTC'
125
143
  ```
126
144
 
127
- ### Digits/Characters Tools
145
+ ### Digits and Character Conversion
128
146
 
129
147
  ```python
130
148
  >>> from persiantools import characters, digits
131
149
 
150
+ # Convert English digits to Persian
132
151
  >>> digits.en_to_fa("0987654321")
133
152
  '۰۹۸۷۶۵۴۳۲۱'
134
153
 
154
+ # Convert Arabic digits to Persian
135
155
  >>> digits.ar_to_fa("٠٩٨٧٦٥٤٣٢١")
136
156
  '۰۹۸۷۶۵۴۳۲۱'
137
157
 
158
+ # Convert Persian digits to English
138
159
  >>> digits.fa_to_en("۰۹۸۷۶۵۴۳۲۱")
139
160
  '0987654321'
140
161
 
162
+ # Convert numbers to Persian words
141
163
  >>> digits.to_word(9512026)
142
164
  'نه میلیون و پانصد و دوازده هزار و بیست و شش'
143
165
 
144
166
  >>> digits.to_word(15.007)
145
167
  'پانزده و هفت هزارم'
146
168
 
169
+ # Convert Arabic to Persian characters
147
170
  >>> characters.ar_to_fa("كيك")
148
171
  'کیک'
149
172
  ```
150
173
 
151
174
  ### Operators
152
-
175
+ The package supports various operators for date and time manipulations. Here are some examples:
153
176
  ```python
154
177
  >>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
155
178
  >>> import datetime
@@ -157,7 +180,7 @@ Based on python `strftime()` behavior
157
180
  >>> JalaliDate(1367, 2, 14) == JalaliDate(datetime.date(1988, 5, 4))
158
181
  True
159
182
 
160
- >>> 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)
161
184
  False
162
185
 
163
186
  >>> JalaliDate(1367, 2, 14) == datetime.date(1988, 5, 4)
@@ -170,21 +193,19 @@ JalaliDate(1395, 3, 21, Jomeh)
170
193
  datetime.timedelta(365)
171
194
  ```
172
195
 
173
- ### Serializing and de-serializing
196
+ ### Serializing and Deserializing
174
197
 
175
198
  ```python
176
199
  >>> from persiantools.jdatetime import JalaliDate
177
200
  >>> import pickle
178
201
 
179
- >>> # Serializing
180
- >>> file = open("save.p", "wb")
181
- >>> pickle.dump(JalaliDate(1367, 2, 14), file)
182
- >>> 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)
183
205
 
184
- >>> # de-serializing
185
- >>> file = open("save.p", "rb")
186
- >>> jalali = pickle.load(file)
187
- >>> file.close()
206
+ # Deserialize from a file
207
+ >>> with open("save.p", "rb") as file:
208
+ >>> jalali = pickle.load(file)
188
209
  >>> jalali
189
210
  JalaliDate(1367, 2, 14, Chaharshanbeh)
190
211
  ```
@@ -7,72 +7,78 @@
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
-
18
+ You can install the package using pip with the following command:
21
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
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
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
 
@@ -80,45 +86,50 @@ Based on python `strftime()` behavior
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
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
-
132
+ The package supports various operators for date and time manipulations. Here are some examples:
122
133
  ```python
123
134
  >>> from persiantools.jdatetime import JalaliDate, JalaliDateTime
124
135
  >>> import datetime
@@ -126,7 +137,7 @@ Based on python `strftime()` behavior
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
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.1"
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)