Is it possible to strip the Timezone files from Joda-Time out of my build? I'm only using 1 in release builds and 2 in debug builds to use in a test.
My app is only available in one country and a 2MB reduction seems like a good idea getting me around the 20MB Mark.
You can get Joda-Time's source code and then you have some alternatives.
Don't use any timezone
When you build the project (
mvn clean package
), it generates ajoda-time-2.9.9-no-tzdb.jar
file, which is a jar file without any timezone data. Using this will require some adaptations:DateTimeZone.getAvailableIDs()
andDateTimeZone.getDefault()
returns just UTC. You won't be able to convert between another timezones, as UTC is the only one available.When calling some methods, I'm getting some exceptions (
Resource not found: "org/joda/time/tz/data/ZoneInfoMap"
). To get rid of it, I had to set the default timezone provider to UTC:This way, the exceptions are gone.
Choose which timezones you want
If you want to use another timezone instead of just UTC, there's an alternative.
In the
pom.xml
file, look for thecompile-tzdb
execution and comment the files that you don't want to include in the jar. In this example, I'm keeping just thesouthamerica
file:Then build it with:
I'm skipping the tests because some of them uses timezones that aren't in South America files (such as
Europe/London
). Of course you can also change the tests if you want, but I've just chosen the fastest way (I usually don't skip tests in production builds, don't judge me).Then, the
joda-time-2.9.9.jar
file will contain only South America timezones files. You can optionally include thebackward
file in your build if you want to include synonyms (some zones had their names changed, but the old names are kept and became synonyms in thebackward
file).With this, the resulting jar will contain only South America zones and UTC. If the JVM default timezone is not one of the South America ones,
DateTimeZone.getDefault()
will return UTC.If you want to reduce even more the zone files, you can edit them manually. But you must be careful to not remove important data from the timezones you want to keep. Here's a tutorial about the format of IANA tz files.
Just keep in mind that removing timezone data is not something I would recommend. All the historical data are important and there's (almost) always some timezone acting behind the scenes. You'll have to do lots of tests to make sure it doesn't affect any aspect of your application (some date-related errors, specially involving timezones, can be tricky and hard to debug). Good luck!