Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/raheemadamboev/server-time-android

🕜 Light library to get real UNIX time from the server in android
https://github.com/raheemadamboev/server-time-android

android android-library get-time internet-time server-time

Last synced: about 2 months ago
JSON representation

🕜 Light library to get real UNIX time from the server in android

Lists

README

        

Server Time


Android
Version
License
API


🕜 Light library to get real UNIX time from the server in android. Sometimes phone's local date can be wrong so for best accuracy it is better get time from the server. It gets time from the server and always gets correct date.

# Setup

Add it in your root **build.gradle** at the end of repositories:
```groovy
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

Include below dependency in build.gradle of application and sync it:
```groovy
implementation 'com.github.raheemadamboev:server-time-android:1.1'
```

# Implementation

**Get server time (callback API):**
```kotlin
ServerTime().execute { time ->

when (time) {

ServerTime.UNKNOWN_HOST -> {
// handle internet not working or error in host
}

ServerTime.IO_EXCEPTION -> {
// handle io exception
}

ServerTime.TIMEOUT_EXCEPTION -> {
// handle timeout
}

else -> {
// time (milli seconds) was retreived successfully
// println(Date(time).toString())
}
}
}
```

**Get server time (suspend API):**
```kotlin
viewModelScope.launch {
val time = ServerTime().execute()

when (time) {

ServerTime.UNKNOWN_HOST -> {
// handle internet not working or error in host
}

ServerTime.IO_EXCEPTION -> {
// handle io exception
}

ServerTime.TIMEOUT_EXCEPTION -> {
// handle timeout
}

else -> {
// time (milli seconds) was retreived successfully
// println(Date(time).toString())
}
}
}
```

# Demo

Download demo

Italian Trulli

# Projects using this library

**GoTest** 150 000+ downloads in Google Play Store

**Buxgalteriya schyotlar rejasi** 20 000+ downloads in Google Play Store

**Irregular Verbs** 20 000+ downloads in Google Play Store

# License

```xml
Designed and developed by raheemadamboev (Raheem) 2022.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```