java.util.Date val date = Date(2020, 0, 35) print(date.toString()) Expected - Exception. What is even January 35? Actual - Wed Feb 04 00:00:00 IST 3920
Joda-Time Separate classes for each concept • LocalTime - Time without date • LocalDate - Date without time • Instant - Instance in time • Interval - Interval between two Instants • Duration - Time between Instants in milliseconds
Joda-Time Arithmetic operations and immutability val today = DateTime() val aMonthLayer = today.plusMonths(1) val daysBetween = Days.daysBetween(today, aMonthLayer).days val dayOfWeek = today.dayOfWeek val dayOfMonth = today.dayOfMonth
Joda-Time Android • Joda-Time JAR ships with the TimeZone database • ClassLoader.getResourceAsStream() is used to load the TZ data and is not memory efficient https://github.com/dlew/joda-time-android
Joda-Time Android • Joda-Time JAR ships with the TimeZone database • ClassLoader.getResourceAsStream() is used to load the TZ data and is not memory efficient • Joda-Time Android loads the TZ data from resources using AssetManager https://github.com/dlew/joda-time-android
https://github.com/dlew/joda-time-android • Loading the TZ data at app startup can be time consuming • This can add 50-200ms to cold boot time for app Joda-Time Android - a caution
https://github.com/dlew/joda-time-android • Loading the TZ data at app startup can be time consuming • This can add 50-200ms to cold boot time for apps • If possible, defer initialization till you need it Joda-Time Android - a caution
https://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html • Joda-Time has some design flaws • Pluggable Chronology • Complex internals • Nullability • Difference between Human and Machine times Why anything more?
ThreeTenBP • Backport of java.time library to be used on Java 6 and 7 • Ships TZ data along with the JAR • JakeWharton created ThreeTenABP • Can be used back to API Level 15
Core Library Desugaring • Android Gradle Plugin 3.0.0+ added support for some Java 8 language features • AGP 4.0.0+ added support for desugaring Java 8 language API
Core Library Desugaring • Android Gradle Plugin 3.0.0+ added support for some Java 8 language features • AGP 4.0.0+ added support for desugaring Java 8 language API • AGP 4.0.0+ supports a subset of java.time