slashmili / python-jalali

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

problem with %B in persian locale #32

Closed mostafaasadi closed 6 years ago

mostafaasadi commented 6 years ago

Hi I have this :

locale.setlocale(locale.LC_ALL, 'en_US')
jdt = jdatetime.date.fromgregorian(
    day=int(d[2]),
    month=strptime(d[1], '%b').tm_mon,
    year=int(d[5])
)
print(jdt)
locale.setlocale(locale.LC_ALL, 'fa_IR.UTF-8')
print(jdt)
jdt2 = jdt.strftime('%d %B')
print(jdt2)
print(jdatetime.datetime.now().strftime("%d %B"))

and outout is :

1396-11-29
1396-11-29
29 Bahman
29 بهمن

my problem is about jdt2 that wont change bahman to بهمن is it my fault ? or a problem in lib ? thank you 🌹

slashmili commented 6 years ago

@mostafaasadi it's because the months setting is configured during init

mostafaasadi commented 6 years ago

you mean if I get 11 from 1396-11-29 and int it (int()), I can get name of month as persian ? how ?

slashmili commented 6 years ago

The locale should be set before jdatetime object is created


In [1]: import locale

In [2]: import jdatetime

In [3]: date1 = jdatetime.datetime.now()

In [4]: date1.strftime('%d %B')
Out[4]: u'30 Bahman'

In [5]: locale.setlocale(locale.LC_ALL, 'fa_IR.UTF-8')
Out[5]: 'fa_IR.UTF-8'

In [6]: date1.strftime('%d %B')
Out[6]: u'30 Bahman'

In [7]: date2 = jdatetime.datetime.now()

In [8]: date2.strftime('%d %B')
Out[8]: u'30 \u0628\u0647\u0645\u0646'

`
mostafaasadi commented 6 years ago

thank you, I ll test it.

mostafaasadi commented 6 years ago

thank you brother, it works :rose: