RxTime

A very simple reactive Android library to obtain the current UTC time from the internet.

License

License

GroupId

GroupId

com.github.simonpercic
ArtifactId

ArtifactId

rxtime
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

aar
Description

Description

RxTime
A very simple reactive Android library to obtain the current UTC time from the internet.
Project URL

Project URL

https://github.com/simonpercic/RxTime
Source Code Management

Source Code Management

https://github.com/simonpercic/RxTime

Download rxtime

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.simonpercic/rxtime/ -->
<dependency>
    <groupId>com.github.simonpercic</groupId>
    <artifactId>rxtime</artifactId>
    <version>1.0.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.simonpercic/rxtime/
implementation 'com.github.simonpercic:rxtime:1.0.0'
// https://jarcasting.com/artifacts/com.github.simonpercic/rxtime/
implementation ("com.github.simonpercic:rxtime:1.0.0")
'com.github.simonpercic:rxtime:aar:1.0.0'
<dependency org="com.github.simonpercic" name="rxtime" rev="1.0.0">
  <artifact name="rxtime" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.simonpercic', module='rxtime', version='1.0.0')
)
libraryDependencies += "com.github.simonpercic" % "rxtime" % "1.0.0"
[com.github.simonpercic/rxtime "1.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
io.reactivex : rxjava jar 1.0.13
com.google.dagger : dagger jar 2.0.1
com.squareup.retrofit : retrofit jar 1.9.0

Project Modules

There are no modules declared in this project.

RxTime

A very simple reactive Android library to obtain the current UTC time from the internet.

Build Status Download

What does it do?

It fetches the current UTC time from www.timeapi.org using Retrofit.

Why is it useful?

Useful for getting current UTC time independently of device timezone and the set time.

How does it work?

On first use, UTC time is fetched from the API at www.timeapi.org/utc/now and stored as a base value.

On further requests, UTC time is calculated from the base value and device uptime, to save on network calls.

As a result, the UTC time is always correct, independently of the timezone set on device, even if the timezone (or time) is changed on the device after (or before) RxTime is used.

Usage

Add using Gradle:

compile 'com.github.simonpercic:rxtime:1.0.0'

Create a singleton instance of RxTime and use it:

// a singleton somewhere
RxTime rxTime = new RxTime();

...

rxTime.currentTime()
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Action1<Long>() {
        @Override public void call(Long time) {
            // use time
        }
    });

Use the awesome Gradle Retrolambda Plugin with Java 8 to use lambdas:

rxTime.currentTime()
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(time -> { // use time });

Singleton Pro-tip

Use Dagger to hold a single instance of RxTime.

Scheduler

The Observable returned by RxTime runs on a background thread by default (using .subscribeOn(Schedulers.io())).

Sample application

See the included sample application to see a practical example of usage.

License

Open source, distributed under the MIT License. See LICENSE for details.

Versions

Version
1.0.0