Giter Site home page Giter Site logo

joda-time-android's Introduction

joda-time-android

This library is a version of Joda-Time built with Android in mind.

Why Joda-Time?

Android has built-in date and time handling - why bother with a library? If you've worked with Java's Date and Calendar classes you can probably answer this question yourself, but if not, check out Joda-Time's list of benefits.

For Android developers Joda-Time solves one critical problem: stale timezone data. Built-in timezone data is only updated when the OS is updated, and we all know how often that happens. Countries modify their timezones all the time; being able to update your own tz data keeps your app up-to-date and accurate.

Why This Library?

I know what you are thinking: Joda-Time is a great library and it's just a single JAR, so why make things more complex by wrapping it in an Android library?

There is a particular problem with the JAR setup on Android: due to its usage of ClassLoader.getResourceAsStream(), it greatly inflates its memory footprint on apps. (For more details, see this blog post.) This library avoids the problem for Android by loading from resources instead of a JAR.

This library also has extra utilities designed for Android. For example, see DateUtils, a port of Android's DateUtils.

Usage

You can either import this project as a plain old library project, or you can use it as an AAR from Maven Central.

If you're using maven:

<dependency>
  <groupId>net.danlew</groupId>
  <artifactId>android.joda</artifactId>
  <version>2.3.4</version>
  <type>aar</type>
</dependency>

If you're using gradle:

dependencies {
  compile 'net.danlew:android.joda:2.3.4'
}

Once the project is imported, you must initialize the timezone provider and TIMEZONE_CHANGED broadcast receiver with a Context (via JodaTimeAndroid.init()) before you can start using this library. I suggest putting this code in Application.onCreate():

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
      
        JodaTimeAndroid.init(this);
    }
}

Updating the TimeZone database

  1. Download the latest Time Zone Data package from IANA. You will need only the tzdata package.

  2. Unzip/untar the tzdata package and copy files from the package into the tzdata/ folder in this repository.

  3. Run the following command

     ./gradlew updateTzData
    
  4. Re-compile the library

joda-time-android's People

Contributors

dlew avatar rlac avatar scottdweber avatar josiahneuberger avatar

Watchers

James Cloos avatar Chetan Patil avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.