Iorana! Greetings from Easter Island!
I am using JodaTime 2.10.6 in Android to print the timezone abbreviations for dates such as EAST, PDT, GMT, EEST:
DateTimeZone zoneEasterIsland = DateTimeZone.forID("Pacific/Easter");
DateTime nowEasterIsland = DateTime.now(zoneEasterIsland);
long millis = nowEasterIsland.getMillis();
String key = zoneEasterIsland.getNameKey(millis);
String shortName = zoneEasterIsland.getShortName(millis);
String name = zoneEasterIsland.getName(millis);
String shortNameLocalized = zoneEasterIsland.getShortName(millis, Locale.US);
String nameLocalized = zoneEasterIsland.getName(millis, Locale.US);
System.out.println("JodaTime Key: " + key );
System.out.println("JodaTime Short Name: " + shortName );
System.out.println("JodaTime Name: " + name );
System.out.println("JodaTime Short Name Localized: " + shortNameLocalized );
System.out.println("JodaTime Name Localized: " + nameLocalized );
On any Android device, this prints:
JodaTime Key: -06
JodaTime Short Name: GMT-06:00
JodaTime Name: Easter Island Standard Time
JodaTime Short Name Localized: GMT-06:00
JodaTime Name Localized: Easter Island Standard Time
...but what I wanted to produce was EAST
or EASST
and I can't get any of them!
If I run the same code on a local unit test (executed on computer, not Android), I get the desired results:
JodaTime Key: -06
JodaTime Short Name: EAST
JodaTime Name: Easter Is. Time
JodaTime Short Name Localized: EAST
JodaTime Name Localized: Easter Is. Time
I debug why, and JodaTime is using a DefaultNameProvider
which apparently gets all the timezone name groups from the platform itself: DateFormatSymbols.getZoneStrings()
is implemented differently in the JDK and in Android.
Android seems to be getting into libcore.icu
which are implemented natively, and seems to be missing abbreviations for the majority of the 600 timezones provided. The JDK however has almost all of them! None of the implementations are debuggable.
- Android TZ names (bad):
- JDK TZ names (good):
I always thought that JodaTime has all the timezone info and is platform data independent. I didn't know they rely on the underlying platform to provide these timezone names?
Is there any NameProvider
available, that I can plug into JodaTime, maybe some implementation based exclusively on the bundled TZData?
Or any other way I can make it print correctly these timezone abbreviations on Android?
Mauru-ur!