Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[IMPROVEMENT] Convert UTC to time #2077

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.withContext
import timber.log.Timber
import javax.inject.Inject
import java.text.SimpleDateFormat
import java.util.*

class UserDetailsPresenter @Inject constructor(
private val view: UserDetailsView,
Expand All @@ -44,15 +46,15 @@ class UserDetailsPresenter @Inject constructor(
val username = userEntity.username
val name = userEntity.name
val utcOffset =
userEntity.utcOffset // TODO Convert UTC and display like the mockup

if (avatarUrl != null && username != null && name != null && utcOffset != null) {
userEntity.utcOffset
val usertime = utcToTime(utcOffset = utcOffset);// usertime.plus("$utc$utcOffset)")
if (avatarUrl != null && username != null && name != null ) {
view.showUserDetails(
avatarUrl = avatarUrl,
name = name,
username = username,
status = userEntity.status,
utcOffset = utcOffset.toString()
utcOffset = usertime
)
} else {
throw Exception()
Expand Down Expand Up @@ -118,4 +120,28 @@ class UserDetailsPresenter @Inject constructor(
}
}
}

fun utcToTime(utcOffset:Float?): String {
val gmtTime = System.currentTimeMillis() // 2.32pm NZDT
var timezoneAlteredTime: Long
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could Lift out the assignment timeZoneAlteredTime. Directly could
timeZoneAlteredTime = if (condition ) value else other value.
This would be according to Kotlin Coding style :)

if (utcOffset != null) {
val multiplier = utcOffset.times(60 * (60 * 1000))
timezoneAlteredTime = gmtTime.plus(multiplier.toLong())
} else {
timezoneAlteredTime = gmtTime
}
val calendar = GregorianCalendar()
calendar.timeInMillis = timezoneAlteredTime
val formatter = SimpleDateFormat("hh:mm a")
formatter.calendar = calendar
formatter.timeZone = TimeZone.getTimeZone("UTC")
var usertime = formatter.format(calendar.getTime())
val utc = if (utcOffset !=null && utcOffset > 0) {
" (UTC +"
} else {
" (UTC "
}
usertime = usertime.plus("$utc$utcOffset)")
return usertime
}
}