DateUtils: move event details formatting to DateUtils
Also display second as 0 since it is easier to read and does not have meaning for the user.
This commit is contained in:
@@ -5,8 +5,13 @@ import android.text.format.DateFormat
|
||||
import it.danieleverducci.lunatracker.R
|
||||
import java.util.Date
|
||||
|
||||
|
||||
class DateUtils {
|
||||
companion object {
|
||||
/**
|
||||
* Format time duration in seconds as e.g. "2 hours, 1 min".
|
||||
* Used for the duration to the next/previous event in the event details dialog.
|
||||
*/
|
||||
fun formatTimeDuration(context: Context, secondsDiff: Long): String {
|
||||
var seconds = secondsDiff
|
||||
|
||||
@@ -65,7 +70,8 @@ class DateUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the provided unix timestamp in a string like "3 hours, 26 minutes ago)
|
||||
* Formats the provided unix timestamp in a string like "3 hours, 26 minutes ago".
|
||||
* Used for the event list.
|
||||
*/
|
||||
fun formatTimeAgo(context: Context, unixTime: Long): String {
|
||||
val secondsDiff = (System.currentTimeMillis() / 1000) - unixTime
|
||||
@@ -100,5 +106,17 @@ class DateUtils {
|
||||
}
|
||||
return formattedTime.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Format time as localized string without seconds. E.g. "28 Sept 03:36:00".
|
||||
* The seconds are set to 0 since they are distracting and not relevant.
|
||||
* Used in the event detail dialog.
|
||||
*/
|
||||
fun formatDateTime(unixTime: Long): String {
|
||||
val roundedUnixTime = unixTime - (unixTime % 60)
|
||||
val date = Date(roundedUnixTime * 1000)
|
||||
val dateFormat = java.text.DateFormat.getDateTimeInstance()
|
||||
return dateFormat.format(date)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user