Skip to content

Commit

Permalink
Timestamp fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Jan 13, 2023
1 parent 5a9dfd1 commit 28c9456
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
4 changes: 2 additions & 2 deletions apps/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.revertron.mimir"
minSdk 21
targetSdk 31
versionCode 13
versionName "1.7.0"
versionCode 14
versionName "1.7.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
15 changes: 2 additions & 13 deletions apps/Android/app/src/main/java/com/revertron/mimir/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,15 @@ fun validPublicKey(text: String): Boolean {
*/
fun getUtcTime(): Long {
val calendar = Calendar.getInstance()
val offset = calendar.timeZone.rawOffset
return (calendar.timeInMillis - offset) / 1000
return calendar.timeInMillis / 1000
}

/**
* Gets current time in milliseconds in UTC timezone
*/
fun getUtcTimeMs(): Long {
val calendar = Calendar.getInstance()
val offset = calendar.timeZone.rawOffset
return calendar.timeInMillis - offset
}

/**
* Converts given time (presumably in UTC) to local timezone
*/
fun convertToTimeZone(time: Long): Long {
val calendar = Calendar.getInstance()
val offset = calendar.timeZone.rawOffset
return time + offset
return calendar.timeInMillis
}

fun isColorDark(color: Int): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class MimirServer(
if (message?.data != null) {
synchronized(connections) {
val connection = connections[publicKey]
Log.i(TAG, "Sending message ${message.guid} with id ${message.id}")
Log.i(TAG, "Sending message ${message.guid} with id ${message.id} and time ${message.time}")
connection?.sendMessage(message.guid, message.replyTo, message.time, message.edit, message.type, message.data)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ContactsAdapter(private var dataSet: List<Contact>, private val onclick: V
holder.lastMessage.text = contact.lastMessage.ifEmpty { "" }
if (contact.lastMessageTime > 0) {
holder.lastMessageTime.visibility = View.VISIBLE
val date = Date(convertToTimeZone(contact.lastMessageTime))
val date = Date(contact.lastMessageTime)
val diff = Date().time - date.time
if (diff > 86400 * 1000) {
holder.lastMessageTime.text = dateFormatter.format(date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.updateMargins
import androidx.recyclerview.widget.RecyclerView
import com.revertron.mimir.R
import com.revertron.mimir.convertToTimeZone
import com.revertron.mimir.storage.SqlStorage
import java.text.DateFormat
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -111,7 +110,7 @@ class MessageAdapter(
}

private fun formatTime(time: Long): String {
val date = Date(convertToTimeZone(time))
val date = Date(time)
val diff = Date().time - date.time
return if (diff > 86400 * 1000) {
"${dateFormatter.format(date)} ${timeFormatter.format(date)}"
Expand Down

0 comments on commit 28c9456

Please sign in to comment.