I have to convert this date into normal date string/object.
١٩٩٤-٠٤-١١ to 11-04-1994.
It's definitely a Good Idea to use unicodedata.decimal
. There's probably a nice way to do this using the locale module and time.strptime / time.strftime, but I don't have any Arabic locales on this machine, so I'm not about to experiment. :)
FWIW, here's a fairly direct translation of Amadan's JavaScript code into a Python function.
import re
pat = re.compile(u'[\u0660-\u0669]', re.UNICODE)
def arabic_to_euro_digits(m):
return unichr(ord(m.group(0)) - 0x630)
def arabic_to_euro_date(arabic_date):
s = pat.sub(arabic_to_euro_digits, arabic_date)
return '-'.join(s.split('-')[::-1])
arabic_date = u'١٩٩٤-٠٤-١١'
print arabic_date
euro_date = arabic_to_euro_date(arabic_date)
print euro_date
output
١٩٩٤-٠٤-١١
11-04-1994