majiidd / persiantools

Jalali date and datetime with other tools
MIT License
166 stars 20 forks source link

JalaliDateTime does not properly parse iso formatted strings: #37

Closed Moeinoddin-Mansourfar closed 3 months ago

Moeinoddin-Mansourfar commented 11 months ago

the method .fromisoformat in JalaliDateTime ignores the time and only parses the date component: image

majiidd commented 3 months ago

Thanks for letting me know about the issue! I’ve added the fromisoformat method to JalaliDateTime, so it now correctly handles both date and time from ISO 8601 strings. Just update to the latest version.

from persiantools.jdatetime import JalaliDateTime

# Convert ISO format string to JalaliDateTime
jdt = JalaliDateTime.fromisoformat('1403-08-09T02:21:45')
print(jdt)  # Outputs: JalaliDateTime(1403, 8, 9, 2, 21, 45)

# Round trip back to ISO format
iso_str = jdt.isoformat()
print(iso_str)  # Outputs: '1403-08-09T02:21:45'