Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while parsing cyrillic month names on Linux and OS X #273

Open
crashkin opened this issue May 6, 2015 · 5 comments
Open

Error while parsing cyrillic month names on Linux and OS X #273

crashkin opened this issue May 6, 2015 · 5 comments

Comments

@crashkin
Copy link

crashkin commented May 6, 2015

Works fine on all systems

DateTimeFormat.forPattern("MMMM").withLocale(Locale.US).parseDateTime("January");

Throw exception on OS X

Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "Январь"

DateTimeFormat.forPattern("MMMM").withLocale(new Locale.Builder().setLanguage("ru").setScript("Cyrl").build()).parseDateTime("Январь");

Using OS X 10.10 and Linux Ubuntu 14.04, Oracle JDK/JRE 1.8, joda-time 2.7

@Vest
Copy link

Vest commented May 17, 2015

I was able to reproduce the issue in Windows as well. What I found out is when you convert January to Russian, you get the word "января" instead of "Январь". In other words, if you change your code to the line below, it will work:

DateTimeFormat.forPattern("MMMM").withLocale(new Locale.Builder().setLanguage("ru").setScript("Cyrl").build()).parseDateTime("января");

These words, as you know better than me, have different cases. The library returns you the genitive case, but you are expecting the nominative case.
To be honest, I do not know how the library builds names, let me debug a little. I will write a comment if I find something.

Update:
Well, I have found a class (a standard Java class) that is responsible for month names: sun.text.resources.ru.FormatData_ru. I am afraid that Joda is not guilty. Maybe if you create a custom locale or a formatter, this will give you the ability to use the nominative case.

@crashkin
Copy link
Author

In russian language if date has a day using genitive case (2 января 2015) if only month using nominative case (январь 2015)

update:
Ty. I try create locale formatter ^__^
java.text.SimpleDateFormat support both types

@Vest
Copy link

Vest commented May 17, 2015

Oops, yes, you are right - the genitive case.
Regarding SimpleDateFormat, this part returns me two different words for cases, when I provide with a day, or not:

Date january = new Date(2015, 0, 1);
Locale dLocale = new Locale.Builder().setLanguage("ru").setScript("Cyrl").build();
SimpleDateFormat formatWithDay = new SimpleDateFormat("dd MMMM", dLocale);
SimpleDateFormat formatWithoutDay = new SimpleDateFormat("MMMM", dLocale);

System.out.println("With day: " + formatWithDay.format(january));
System.out.println("Without day: " + formatWithoutDay.format(january));

It gives me two different names:

With day: 01 января
Without day: Январь

Hm... somehow Java decides a correct word. Let me check how.
Update: there is a similar article in StackOverflow - Proper Russian month string translation Java.

@Vest
Copy link

Vest commented Sep 6, 2015

@jodastephen, do you know if this issue can be a bug, or afterwards this is just how Java 8 behaves and we have to live with it?

@jodastephen
Copy link
Member

If JDK 8 has the data, then Joda-Time could be adapted to use it. But it would have to be by reflection, and it would be a fair bit of work. In general, I don't add new features to Joda-Time now that java.time is in JDK 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants