slashmili / python-jalali

Jalali calendar binding for Python based on Python's datetime module
http://pypi.python.org/pypi/jdatetime/
Other
335 stars 46 forks source link

py 3.11.x conflictes with jdatetime 4.1.x #144

Closed PalasOnGithub closed 9 months ago

PalasOnGithub commented 10 months ago

Hi there , I want to get the time as Persian Unicode, but when I set locale to 'fa_IR' , I get the same result in English

Here's The code :

jdatetime.set_locale('fa') or jdatetime.set_locale('fa_IR')

date_text = jdatetime.datetime.now() 
date_per_text = date_text.strftime('%a') 
returns "Sun" which is not expected 
PalasOnGithub commented 10 months ago

After 2w I haven't gotten any messages or respond from the developers , I'll close the issue But issues is still out there </3 !

slashmili commented 9 months ago

Hi @PalasOnGithub! Sorry for the late response

It does work for me on Linux

Python 3.11.6 (main, Oct 12 2023, 10:04:56) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jdatetime
>>> jdatetime.set_locale('fa') or jdatetime.set_locale('fa_IR')
'fa'
>>> date_text = jdatetime.datetime.now()
>>> print(date_text.strftime('%a'))
جمعه

I don't have windows to test it, I'm open for a PR to fix the issue on windows!

5j9 commented 9 months ago

On Windows you should use jdatetime.set_locale('Persian_Iran') instead of jdatetime.set_locale('fa_IR').

https://github.com/slashmili/python-jalali/blob/b0a3a089a5e6d4c43f2495b8a40b895ebd1c197d/jdatetime/__init__.py#L61-L64

slashmili commented 9 months ago

Thanks @5j9!

hramezani commented 9 months ago

BTW, @5j9 probably it worth creating a PR and updating the doc about how use it in windows if you have time

PalasOnGithub commented 9 months ago

Thanks to @slashmili and @5j9 my problem got solved! but its better to make a note about it in readme file of proj in github and pypi duc.

5j9 commented 9 months ago

I can make a pull request to improve the docs, but I doubt that 'Persian_Iran' is the best choice here. On my Windows 10 machine the 'fa_IR' locale works just fine if we replace the condition at line 61 with a simple FA_LOCALE = 'fa_IR' for all platforms. One should note that there is a difference between fa_IR and Persian_Iran locales on Windows. The first one uses UTF-8 encoding while the second one uses Windows-1256 and I believe most users would prefer UTF-8. I'm just not sure if all Windows versions support the fa_IR, or why Persian_Iran has been chosen in the first place.