Closed shojaei-mohammad closed 1 year ago
You are trying to parse a Gregorian date using jdatetime.strptime
. That method is only supposed to handle Solar Hijri dates, not Gregorian dates. To convert the Gregorian date to Jalali try this:
>>> import datetime
>>> import jdatetime
>>> jdatetime.datetime.fromgregorian(date=datetime.datetime.fromisoformat("2023-08-31 23:59:59"))
jdatetime.datetime(1402, 6, 9, 23, 59, 59)
BTW, to convert the jdatetime back into a string, you might want to use strftime
instead of implementing your own method:
>>> jdatetime.datetime(1402, 6, 9, 23, 59, 59).strftime('%Y/%-m/%-d %H:%M')
'1402/6/9 23:59'
Thank you for your answer, It solved my issue.
Description: When attempting to convert the timestamp "2023-08-31 23:59:59" from Gregorian to Jalali using the jdatetime library, a ValueError is raised indicating "day is out of range for month". This issue persists even when the time is reduced by an hour to "2023-08-31 22:59:59".
Steps to reproduce: Below is the Python code which reproduces the issue:
python
Expected behavior: The script should successfully convert the Gregorian date "2023-08-31 23:59:59" to the corresponding Jalali date without raising a ValueError.
Actual behavior: The script raises a ValueError with the message "day is out of range for month".