Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TryDateLibraryofAndroid

futabooo
January 23, 2016

 TryDateLibraryofAndroid

futabooo

January 23, 2016
Tweet

More Decks by futabooo

Other Decks in Programming

Transcript

  1. Try Date Library
    of Android
    @futabooo

    View Slide

  2. futabooo(Takahiro futagawa)
    - Engineer at eureka, Inc.
    - Android Developer
    futabooo
    futabooo

    View Slide

  3. Topics
    ‣ java.util.Date and java.util.Calendar
    ‣ Android Date Library
    ‣ Joda-Time-Android
    ‣ Date4j
    ‣ ThreeTenABP

    View Slide

  4. java.util.Date
    java.util.Calendar

    View Slide

  5. java.util.Date and java.util.Calendar
    ‣ The Java classes for handling dates
    ‣ Have been mostly unchanged since JDK1.0
    ‣ And suffer from well-known issues
    ‣ for example January starts from 0 leading to many off-by-one
    bugs

    View Slide

  6. Joda-Time-Android
    ‣ Date calculation

    View Slide

  7. ‣ Date period
    Joda-Time-Android

    View Slide

  8. Joda-Time-Android

    View Slide

  9. Joda-Time-Android
    ‣ Joda-Time for Android
    ‣ Joda-Time eases the pain and tedium of manipulating
    dates and time
    ‣ Joda-Time greatly inflates its memory footprint on apps.
    ‣ Avoids the problem for Android by loading from resources instead
    of a JAR
    ‣ Has extra utilities designed for Android

    View Slide

  10. Joda-Time-Android
    ‣ Add the following dependency to build.gradle
    ‣ Initialize the library before using

    View Slide

  11. ‣ Date calculation
    Joda-Time-Android

    View Slide

  12. ‣ Date period
    Joda-Time-Android

    View Slide

  13. Date4j

    View Slide

  14. Date4j
    ‣ Eases the pain and tedium of manipulating dates and time
    ‣ Different scope from Joda-Time
    ‣ Number of classes < 10
    ‣ Works in tandem with some JDK Date classes
    ‣ Supports nanosecond resolutions
    ‣ And more

    View Slide

  15. Date4j
    ‣ Add the following dependency to build.gradle

    View Slide

  16. Date4j
    ‣ Date calculation

    View Slide

  17. Date4j
    ‣ Date period
    • Ignore hour,minitue,secounds

    View Slide

  18. ThreeTenABP

    View Slide

  19. ThreeTenABP
    ‣ An adaptation of the JSR-310 backport for Android
    ‣ JSR-310 was included in Java 8 as the java.time.* package
    ‣ Full replacement for the ailing Date and Calendar

    View Slide

  20. ThreeTenABP
    ‣ Add the following dependency to build.gradle
    ‣ Initialize the library before using

    View Slide

  21. ThreeTenABP
    ‣ Date calculation

    View Slide

  22. ThreeTenABP
    ‣ Date period

    View Slide

  23. ·ͱΊ
    ‣ java.util.Date and java.util.Calendar died
    ‣ Joda-Time-Android fat
    ‣ Date4j old
    ‣ ThreeTenABP cool
    Let’s use ThreeTenABP

    View Slide

  24. ࢀߟจݙ
    ‣ https://dzone.com/articles/game-over-jdks-date-and-time-c
    ‣ http://www.joda.org/joda-time/
    ‣ https://github.com/dlew/joda-time-android
    ‣ http://blog.danlew.net/2013/08/20/joda_time_s_memory_issue_in_android/
    ‣ http://www.date4j.net/
    ‣ https://github.com/JakeWharton/ThreeTenABP
    ‣ https://twitter.com/jakewharton/status/606158843249364993

    View Slide

  25. Thank you
    Credit: NASA Earth Observatory/NOAA NGDC

    View Slide