Commit c22a4e22 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Change OffsetDateTime to ZonedDateTime for powerful time calculation.

parent e7250d5e
......@@ -135,7 +135,7 @@ dependencies {
//Lottie
implementation("com.airbnb.android:lottie:2.5.1")
//Date
implementation("com.jakewharton.threetenabp:threetenabp:1.2.0")
implementation("com.jakewharton.threetenabp:threetenabp:1.2.1")
//FlexBox Layout
implementation("com.google.android:flexbox:1.0.0")
//Firebase
......
......@@ -3,13 +3,13 @@ package ru.terrakok.gitlabclient.di.provider
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import org.threeten.bp.LocalDate
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.Color
import ru.terrakok.gitlabclient.entity.todo.Todo
import ru.terrakok.gitlabclient.model.data.server.deserializer.ColorDeserializer
import ru.terrakok.gitlabclient.model.data.server.deserializer.LocalDateDeserializer
import ru.terrakok.gitlabclient.model.data.server.deserializer.OffsetDateTimeDeserializer
import ru.terrakok.gitlabclient.model.data.server.deserializer.TodoDeserializer
import ru.terrakok.gitlabclient.model.data.server.deserializer.ZonedDateTimeDeserializer
import javax.inject.Inject
import javax.inject.Provider
......@@ -23,6 +23,6 @@ class GsonProvider @Inject constructor() : Provider<Gson> {
.registerTypeAdapter(Todo::class.java, TodoDeserializer())
.registerTypeAdapter(Color::class.java, ColorDeserializer())
.registerTypeAdapter(LocalDate::class.java, LocalDateDeserializer())
.registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeDeserializer())
.registerTypeAdapter(ZonedDateTime::class.java, ZonedDateTimeDeserializer())
.create()
}
\ No newline at end of file
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
......@@ -12,11 +12,11 @@ data class Commit(
@SerializedName("title") val title: String,
@SerializedName("author_name") val authorName: String,
@SerializedName("author_email") val authorEmail: String?,
@SerializedName("authored_date") val authoredDate: OffsetDateTime,
@SerializedName("authored_date") val authoredDate: ZonedDateTime,
@SerializedName("commiter_name") val commiterName: String?,
@SerializedName("commiter_email") val commiterEmail: String?,
@SerializedName("commited_date") val commitedDate: OffsetDateTime?,
@SerializedName("created_at") val createdAt: OffsetDateTime,
@SerializedName("commited_date") val commitedDate: ZonedDateTime?,
@SerializedName("created_at") val createdAt: ZonedDateTime,
@SerializedName("message") val message: String,
@SerializedName("parent_ids") val parentIds: List<String>
)
\ No newline at end of file
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.event.EventTargetType
data class Note(
@SerializedName("id") val id: Long,
@SerializedName("body") val body: String,
@SerializedName("author") val author: ShortUser,
@SerializedName("created_at") val createdAt: OffsetDateTime,
@SerializedName("updated_at") val updatedAt: OffsetDateTime?,
@SerializedName("created_at") val createdAt: ZonedDateTime,
@SerializedName("updated_at") val updatedAt: ZonedDateTime?,
@SerializedName("system") val isSystem: Boolean,
@SerializedName("noteable_id") val noteableId: Long,
@SerializedName("noteable_type") val noteableType: EventTargetType?,
......
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
data class Owner(
@SerializedName("id") val id: Long,
@SerializedName("name") val name: String,
@SerializedName("username") val username: String,
@SerializedName("created_at") val createdAt: OffsetDateTime?
@SerializedName("created_at") val createdAt: ZonedDateTime?
)
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
data class Project(
@SerializedName("id") val id: Long,
......@@ -24,8 +24,8 @@ data class Project(
@SerializedName("wiki_enabled") val wikiEnabled: Boolean,
@SerializedName("snippets_enabled") val snippetsEnabled: Boolean,
@SerializedName("container_registry_enabled") val containerRegistryEnabled: Boolean,
@SerializedName("created_at") val createdAt: OffsetDateTime?,
@SerializedName("last_activity_at") val lastActivityAt: OffsetDateTime?,
@SerializedName("created_at") val createdAt: ZonedDateTime?,
@SerializedName("last_activity_at") val lastActivityAt: ZonedDateTime?,
@SerializedName("creator_id") val creatorId: Long,
@SerializedName("namespace") val namespace: Namespace?,
@SerializedName("permissions") val permissions: Permissions?,
......
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
data class User(
@SerializedName("id") val id: Long,
......@@ -11,7 +11,7 @@ data class User(
@SerializedName("state") val state: String?,
@SerializedName("avatar_url") val avatarUrl: String?,
@SerializedName("web_url") val webUrl: String?,
@SerializedName("created_at") val createdAt: OffsetDateTime,
@SerializedName("created_at") val createdAt: ZonedDateTime,
@SerializedName("is_admin") val isAdmin: Boolean,
@SerializedName("bio") val bio: String?,
@SerializedName("location") val location: String?,
......@@ -20,11 +20,11 @@ data class User(
@SerializedName("twitter") val twitter: String?,
@SerializedName("website_url") val websiteUrl: String?,
@SerializedName("organization") val organization: String?,
@SerializedName("last_sign_in_at") val lastSignInAt: OffsetDateTime,
@SerializedName("confirmed_at") val confirmedAt: OffsetDateTime,
@SerializedName("last_sign_in_at") val lastSignInAt: ZonedDateTime,
@SerializedName("confirmed_at") val confirmedAt: ZonedDateTime,
@SerializedName("color_scheme_id") val colorSchemeId: Long,
@SerializedName("projects_limit") val projectsLimit: Long,
@SerializedName("current_sign_in_at") val currentSignInAt: OffsetDateTime,
@SerializedName("current_sign_in_at") val currentSignInAt: ZonedDateTime,
@SerializedName("identities") val identities: List<Identity>?,
@SerializedName("can_create_group") val canCreateGroup: Boolean,
@SerializedName("can_create_project") val canCreateProject: Boolean,
......
package ru.terrakok.gitlabclient.entity.app.target
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.ShortUser
/**
......@@ -12,7 +12,7 @@ sealed class TargetHeader {
val icon: TargetHeaderIcon,
val title: TargetHeaderTitle,
val body: CharSequence,
val date: OffsetDateTime,
val date: ZonedDateTime,
val target: AppTarget,
val targetId: Long,
val internal: TargetInternal?,
......
package ru.terrakok.gitlabclient.entity.event
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.Note
import ru.terrakok.gitlabclient.entity.PushData
import ru.terrakok.gitlabclient.entity.ShortUser
......@@ -17,7 +17,7 @@ data class Event(
@SerializedName("target_type") val targetType: EventTargetType?,
@SerializedName("author_id") val authorId: Long,
@SerializedName("target_title") val targetTitle: String?,
@SerializedName("created_at") val createdAt: OffsetDateTime,
@SerializedName("created_at") val createdAt: ZonedDateTime,
@SerializedName("author") val author: ShortUser,
@SerializedName("author_username") val authorUsername: String,
@SerializedName("push_data") val pushData: PushData?,
......
......@@ -2,7 +2,7 @@ package ru.terrakok.gitlabclient.entity.issue
import com.google.gson.annotations.SerializedName
import org.threeten.bp.LocalDate
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.TimeStats
import ru.terrakok.gitlabclient.entity.milestone.Milestone
......@@ -16,9 +16,9 @@ data class Issue(
@SerializedName("milestone") val milestone: Milestone?,
@SerializedName("project_id") val projectId: Long,
@SerializedName("assignees") val assignees: List<ShortUser>,
@SerializedName("updated_at") val updatedAt: OffsetDateTime?,
@SerializedName("updated_at") val updatedAt: ZonedDateTime?,
@SerializedName("title") val title: String?,
@SerializedName("created_at") val createdAt: OffsetDateTime,
@SerializedName("created_at") val createdAt: ZonedDateTime,
@SerializedName("labels") val labels: List<String>,
@SerializedName("user_notes_count") val userNotesCount: Int,
@SerializedName("due_date") val dueDate: LocalDate?,
......@@ -30,7 +30,7 @@ data class Issue(
// This value will only be present for issues which were closed after GitLab 10.6 and
// when the user account that closed the issue still exists.
@SerializedName("closed_by") val closedBy: ShortUser?,
@SerializedName("closed_at") val closedAt: OffsetDateTime?,
@SerializedName("closed_at") val closedAt: ZonedDateTime?,
// The merge_requests_count attribute was introduced in GitLab 11.9.
@SerializedName("merge_requests_count") val relatedMergeRequestCount: Int,
@SerializedName("time_stats") val timeStats: TimeStats,
......
package ru.terrakok.gitlabclient.entity.mergerequest
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.TimeStats
import ru.terrakok.gitlabclient.entity.milestone.Milestone
......@@ -9,8 +9,8 @@ import ru.terrakok.gitlabclient.entity.milestone.Milestone
data class MergeRequest(
@SerializedName("id") val id: Long,
@SerializedName("iid") val iid: Long,
@SerializedName("created_at") val createdAt: OffsetDateTime,
@SerializedName("updated_at") val updatedAt: OffsetDateTime?,
@SerializedName("created_at") val createdAt: ZonedDateTime,
@SerializedName("updated_at") val updatedAt: ZonedDateTime?,
@SerializedName("target_branch") val targetBranch: String,
@SerializedName("source_branch") val sourceBranch: String,
@SerializedName("project_id") val projectId: Long,
......@@ -38,9 +38,9 @@ data class MergeRequest(
// This value will only be present for merge requests which were closed/merged after GitLab 10.6
// and when the user account that closed/merged the issue still exists.
@SerializedName("closed_by") val closedBy: ShortUser?,
@SerializedName("closed_at") val closedAt: OffsetDateTime?,
@SerializedName("closed_at") val closedAt: ZonedDateTime?,
@SerializedName("merged_by") val mergedBy: ShortUser?,
@SerializedName("merged_at") val mergedAt: OffsetDateTime?,
@SerializedName("merged_at") val mergedAt: ZonedDateTime?,
@SerializedName("changes") val changes: List<MergeRequestChange>?,
@SerializedName("assignees") val assignees: List<ShortUser>,
@SerializedName("time_stats") val timeStats: TimeStats,
......
......@@ -2,7 +2,7 @@ package ru.terrakok.gitlabclient.entity.milestone
import com.google.gson.annotations.SerializedName
import org.threeten.bp.LocalDate
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
data class Milestone(
@SerializedName("id") val id: Long,
......@@ -12,8 +12,8 @@ data class Milestone(
@SerializedName("state") val state: MilestoneState,
@SerializedName("due_date") val dueDate: LocalDate?,
@SerializedName("start_date") val startDate: LocalDate?,
@SerializedName("created_at") val createdAt: OffsetDateTime?,
@SerializedName("created_at") val createdAt: ZonedDateTime?,
@SerializedName("title") val title: String?,
@SerializedName("updated_at") val updatedAt: OffsetDateTime?,
@SerializedName("updated_at") val updatedAt: ZonedDateTime?,
@SerializedName("web_url") val webUrl: String?
)
package ru.terrakok.gitlabclient.entity.target
import com.google.gson.annotations.SerializedName
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.TimeStats
import ru.terrakok.gitlabclient.entity.milestone.Milestone
......@@ -21,9 +21,9 @@ abstract class Target {
@SerializedName("state")
private val _state: TargetState? = null
@SerializedName("updated_at")
val updatedAt: OffsetDateTime? = null
val updatedAt: ZonedDateTime? = null
@SerializedName("created_at")
val createdAt: OffsetDateTime? = null
val createdAt: ZonedDateTime? = null
@SerializedName("labels")
private val _labels: List<String>? = null
@SerializedName("milestone")
......
package ru.terrakok.gitlabclient.entity.todo
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.target.Target
......@@ -19,5 +19,5 @@ data class Todo(
val targetUrl: String,
val body: String,
val state: TodoState,
val createdAt: OffsetDateTime
val createdAt: ZonedDateTime
)
\ No newline at end of file
......@@ -5,7 +5,7 @@ import android.content.res.Resources
import androidx.annotation.DrawableRes
import org.threeten.bp.Duration
import org.threeten.bp.LocalDate
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import org.threeten.bp.format.DateTimeFormatter
import retrofit2.HttpException
import ru.terrakok.gitlabclient.R
......@@ -42,8 +42,8 @@ fun Throwable.userMessage(resourceManager: ResourceManager) = when (this) {
}
private val DATE_FORMAT = DateTimeFormatter.ofPattern("dd MMM yyyy")
fun OffsetDateTime.humanTime(resources: Resources): String {
val delta = Duration.between(this, OffsetDateTime.now())
fun ZonedDateTime.humanTime(resources: Resources): String {
val delta = Duration.between(this, ZonedDateTime.now())
.seconds
.let { maxOf(0, it) }
......
......@@ -3,7 +3,7 @@ package ru.terrakok.gitlabclient.model.data.server
import io.reactivex.Completable
import io.reactivex.Single
import org.threeten.bp.LocalDate
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import retrofit2.adapter.rxjava2.Result
import retrofit2.http.*
import ru.terrakok.gitlabclient.entity.*
......@@ -164,8 +164,8 @@ interface GitlabApi {
@Query("milestone") milestone: String?,
@Query("view") viewType: MergeRequestViewType?,
@Query("labels") labels: String?,
@Query("created_before") createdBefore: OffsetDateTime?,
@Query("created_after") createdAfter: OffsetDateTime?,
@Query("created_before") createdBefore: ZonedDateTime?,
@Query("created_after") createdAfter: ZonedDateTime?,
@Query("scope") scope: MergeRequestScope?,
@Query("author_id") authorId: Int?,
@Query("assignee_id") assigneeId: Int?,
......@@ -183,8 +183,8 @@ interface GitlabApi {
@Query("milestone") milestone: String?,
@Query("view") viewType: MergeRequestViewType?,
@Query("labels") labels: String?,
@Query("created_before") createdBefore: OffsetDateTime?,
@Query("created_after") createdAfter: OffsetDateTime?,
@Query("created_before") createdBefore: ZonedDateTime?,
@Query("created_after") createdAfter: ZonedDateTime?,
@Query("scope") scope: MergeRequestScope?,
@Query("author_id") authorId: Int?,
@Query("assignee_id") assigneeId: Int?,
......
......@@ -4,7 +4,7 @@ import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.target.Target
......@@ -51,7 +51,10 @@ class TodoDeserializer : JsonDeserializer<Todo> {
jsonObject.get("target_url").asString,
jsonObject.get("body").asString,
context.deserialize<TodoState>(jsonObject.get("state"), TodoState::class.java),
context.deserialize<OffsetDateTime>(jsonObject.get("created_at"), OffsetDateTime::class.java)
context.deserialize<ZonedDateTime>(
jsonObject.get("created_at"),
ZonedDateTime::class.java
)
)
} else {
throw JsonParseException("Configure Gson in GsonProvider.")
......
......@@ -3,14 +3,14 @@ package ru.terrakok.gitlabclient.model.data.server.deserializer
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import java.lang.reflect.Type
class OffsetDateTimeDeserializer : JsonDeserializer<OffsetDateTime> {
class ZonedDateTimeDeserializer : JsonDeserializer<ZonedDateTime> {
override fun deserialize(
json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext?
): OffsetDateTime = OffsetDateTime.parse(json.asJsonPrimitive.asString)
): ZonedDateTime = ZonedDateTime.parse(json.asJsonPrimitive.asString)
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ package ru.terrakok.gitlabclient.model.repository.event
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.functions.BiFunction
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.di.DefaultPageSize
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.entity.OrderBy
......@@ -34,8 +34,8 @@ class EventRepository @Inject constructor(
fun getEvents(
action: EventAction? = null,
targetType: EventTarget? = null,
beforeDay: OffsetDateTime? = null,
afterDay: OffsetDateTime? = null,
beforeDay: ZonedDateTime? = null,
afterDay: ZonedDateTime? = null,
sort: Sort? = Sort.DESC,
orderBy: OrderBy = OrderBy.UPDATED_AT,
page: Int,
......@@ -68,8 +68,8 @@ class EventRepository @Inject constructor(
projectId: Long,
action: EventAction? = null,
targetType: EventTarget? = null,
beforeDay: OffsetDateTime? = null,
afterDay: OffsetDateTime? = null,
beforeDay: ZonedDateTime? = null,
afterDay: ZonedDateTime? = null,
sort: Sort? = Sort.DESC,
orderBy: OrderBy = OrderBy.UPDATED_AT,
page: Int,
......
......@@ -3,7 +3,7 @@ package ru.terrakok.gitlabclient.model.repository.mergerequest
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.functions.BiFunction
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.di.DefaultPageSize
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.entity.*
......@@ -36,8 +36,8 @@ class MergeRequestRepository @Inject constructor(
milestone: String? = null,
viewType: MergeRequestViewType? = null,
labels: String? = null,
createdBefore: OffsetDateTime? = null,
createdAfter: OffsetDateTime? = null,
createdBefore: ZonedDateTime? = null,
createdAfter: ZonedDateTime? = null,
scope: MergeRequestScope? = null,
authorId: Int? = null,
assigneeId: Int? = null,
......@@ -69,8 +69,8 @@ class MergeRequestRepository @Inject constructor(
milestone: String? = null,
viewType: MergeRequestViewType? = null,
labels: String? = null,
createdBefore: OffsetDateTime? = null,
createdAfter: OffsetDateTime? = null,
createdBefore: ZonedDateTime? = null,
createdAfter: ZonedDateTime? = null,
scope: MergeRequestScope? = null,
authorId: Int? = null,
assigneeId: Int? = null,
......
......@@ -8,7 +8,7 @@ import org.junit.Test
import org.mockito.Mockito.`when`
import org.mockito.Mockito.verify
import org.threeten.bp.LocalDateTime
import org.threeten.bp.OffsetDateTime
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.TestSchedulers
import ru.terrakok.gitlabclient.entity.User
import ru.terrakok.gitlabclient.model.data.server.GitlabApi
......@@ -24,7 +24,8 @@ class ProfileRepositoryTest {
private val testServer = "Test server"
private val testError = RuntimeException("test error")
private val testDate = OffsetDateTime.of(LocalDateTime.of(2018, 1, 1, 0, 0), OffsetDateTime.now().offset)
private val testDate =
ZonedDateTime.of(LocalDateTime.of(2018, 1, 1, 0, 0), ZonedDateTime.now().offset)
private val testUser = User(
id = 1L,
username = "",
......
......@@ -5,7 +5,7 @@ buildscript {
maven { url = uri("https://maven.fabric.io/public") }
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.0")
classpath("com.android.tools.build:gradle:3.4.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
classpath("com.google.gms:google-services:4.2.0")
classpath("io.fabric.tools:gradle:1.29.0")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment