Closed mahozad closed 3 years ago
Thank you for raising the issue!
The problem is that the library has never intended to format the date into Persian transcriptions. Therefore, neither a specific implementation nor unit test is in place for localized formaters, e.g. fa
locale.
Regarding supporting the fa
locale in the library, I believe it's generally a positive intention. Having that said, the issue (as you pointed out) is that in case the library would support the fa
locale as you proposed, there would be inconsistency between PersianDate#format
and DateTimeFormatter#format
. I would like to refrain from such an inconsistency.
Maybe introducing another class (e.g. PersianDateFormatter
) which specifically addresses the fa
locale would be a better compromise.
Formatting
PersianDate
withjava.time.format.DateTimeFormatter
has two problems:1. When using a
fa
locale, numbers are represented with English digitsThis will be fixed in JDK 15 (using
.localizedBy(myLocale)
will be enough).Until then, format like this:
.localizedBy(myLcoale).withDecimalStyle(DecimalStyle.of(myLocale))
I believe this is a bug in Java. So I filed an issue here and it seems that for some reason (?!) the numbers are formatted in the string without respecting the given locale. To resolve the problem I did this:
So I wanted to know is there any way
PersianDate
formats the numbers as Persian when the locale is set tofa
orfa-IR
?I think this can easily be done with editing the
PersianDate
class to override theformat()
method ofChronoLocalDate
like this:Note that this resolves the problem if user formats the date with the
format()
method ofPersianDate
and notformat()
method ofDateTimeFormatter
.#
2. The month is formatted with Gregorian name and not Persian name
The above code prints فوریه instead of اردیبهشت. The workaround could be again to modify the
format()
method and replace all occurrences of Gregorian month names with the Persian ones.