3

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):

Android TZ Names

  • JDK TZ names (good):

Local TZ Names

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!

RumburaK
  • 1,985
  • 1
  • 21
  • 30
  • I all else fails you may migrate to java.time, the modern Java date and time API, in some sense the successor of Joda-Time. If for API level under 26, then through the backport, [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP). – Ole V.V. Jun 22 '20 at 06:02
  • 1
    I have tried both Java 8 and 310ABP. It's the same problem, it doesn't have the abbreviations on Android, but it does on regular JDK. – RumburaK Jun 22 '20 at 13:14

0 Answers0