|
|
|
|
@ -1,12 +1,12 @@ |
|
|
|
|
package net.pokeranalytics.android.util |
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.res.Resources |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
|
import java.text.DateFormat |
|
|
|
|
import java.text.DecimalFormat |
|
|
|
|
import java.text.NumberFormat |
|
|
|
|
import java.text.SimpleDateFormat |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
@ -31,8 +31,10 @@ fun Double.round(): String { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun Double.toCurrency(): String { |
|
|
|
|
val formatter = DecimalFormat("##.##") |
|
|
|
|
return "$ ${formatter.format(this)}" |
|
|
|
|
val format = NumberFormat.getCurrencyInstance() |
|
|
|
|
format.maximumFractionDigits = 2 |
|
|
|
|
format.minimumFractionDigits = 0 |
|
|
|
|
return format.format(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Calendar |
|
|
|
|
@ -99,7 +101,7 @@ fun Date.getMonthAndYear(): String { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Return the duration between two dates |
|
|
|
|
fun Date.getDuration(context: Context, toDate: Date) : String { |
|
|
|
|
fun Date.getDuration(toDate: Date) : String { |
|
|
|
|
val difference = (toDate.time - this.time).toInt() |
|
|
|
|
val numOfDays = (difference / (1000 * 60 * 60 * 24)) |
|
|
|
|
val hours = (difference / (1000 * 60 * 60)) |
|
|
|
|
@ -111,7 +113,6 @@ fun Date.getDuration(context: Context, toDate: Date) : String { |
|
|
|
|
return "$hoursStr:$minutesStr" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Toast |
|
|
|
|
|
|
|
|
|
fun PokerAnalyticsActivity.toast(message: String) { |
|
|
|
|
|