Fixes issue with duration

feature/top10
Laurent 7 years ago
parent f9a2f3ca9d
commit c7fa7b32c1
  1. 143
      app/src/androidTest/java/net/pokeranalytics/android/ExampleInstrumentedUnitTest.kt
  2. 30
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  3. 4
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  4. 17
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  5. 27
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  6. 119
      app/src/main/java/net/pokeranalytics/android/model/realm/TimeFrame.kt
  7. 2
      app/src/main/java/net/pokeranalytics/android/util/DateExtension.kt
  8. 4
      app/src/main/java/net/pokeranalytics/android/util/NumbersExtension.kt

@ -7,6 +7,7 @@ import net.pokeranalytics.android.calculus.ComputedResults
import net.pokeranalytics.android.calculus.SessionGroup
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.SessionSet
import net.pokeranalytics.android.model.realm.TimeFrame
import org.junit.Assert
import org.junit.Assert.assertEquals
@ -26,7 +27,7 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
// convenience extension
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session {
val session: Session = Session.newInstance()
val session: Session = Session.newInstance(super.mockRealm, false)
session.result?.netResult = netResult
session.timeFrame?.setDate(startDate, endDate)
return session
@ -67,8 +68,8 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
realm.beginTransaction()
s1.timeFrame?.setDate(sd1, ed1) // duration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
s2.timeFrame?.setDate(sd2, ed2) // duration = 3h, hourly = 100, bb100 = 150 / 75 * 100 = +200
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 3h, hourly = 100, bb100 = 150 / 75 * 100 = +200
realm.copyToRealmOrUpdate(s1)
realm.copyToRealmOrUpdate(s2)
@ -102,7 +103,7 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
if (duration != null) {
assertEquals(4.0, duration.value, delta)
} else {
Assert.fail("No duration stat")
Assert.fail("No netDuration stat")
}
val hourlyRate = results.computedStat(Stat.HOURLY_RATE)
@ -207,7 +208,6 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
realm.insert(s1)
realm.insert(s2)
realm.commitTransaction()
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm")
@ -216,10 +216,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
val sd2 = sdf.parse("01/1/2019 08:00")
val ed2 = sdf.parse("01/1/2019 11:00")
realm.beginTransaction()
s1.timeFrame?.setDate(sd1, ed1) // duration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
s2.timeFrame?.setDate(sd2, ed2) // duration = 4h, hourly = 100, bb100 = 150 / 75 * 100 = +200
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 4h, hourly = 100, bb100 = 150 / 75 * 100 = +200
realm.copyToRealmOrUpdate(s1)
realm.copyToRealmOrUpdate(s2)
@ -274,7 +273,6 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
realm.insert(s1)
realm.insert(s2)
realm.insert(s3)
realm.commitTransaction()
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm")
@ -285,11 +283,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
val sd3 = sdf.parse("01/1/2019 03:00")
val ed3 = sdf.parse("01/1/2019 06:00")
realm.beginTransaction()
s1.timeFrame?.setDate(sd1, ed1) // duration = 4h
s2.timeFrame?.setDate(sd2, ed2) // duration = 4h
s3.timeFrame?.setDate(sd3, ed3) // duration = 3h
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 4h
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 4h
s3.timeFrame?.setDate(sd3, ed3) // netDuration = 3h
realm.copyToRealmOrUpdate(s1)
realm.copyToRealmOrUpdate(s2)
@ -370,9 +366,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
realm.beginTransaction()
s1.timeFrame?.setDate(sd1, ed1) // duration = 4h
s2.timeFrame?.setDate(sd2, ed2) // duration = 4h
s3.timeFrame?.setDate(sd3, ed3) // duration = 3h
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 4h
s2.timeFrame?.setDate(sd2, ed2) // netDuration = 4h
s3.timeFrame?.setDate(sd3, ed3) // netDuration = 3h
realm.copyToRealmOrUpdate(s1)
realm.copyToRealmOrUpdate(s2)
@ -393,12 +389,9 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
if (duration != null) {
assertEquals(8.0, duration.value, delta)
} else {
Assert.fail("No duration stat")
Assert.fail("No netDuration stat")
}
// realm.beginTransaction()
// s1.deleteFromRealm()
// realm.commitTransaction()
realm.executeTransaction {
s1.deleteFromRealm()
}
@ -414,4 +407,112 @@ class ExampleInstrumentedUnitTest : RealmInstrumentedUnitTest() {
}
}
@Test
fun testSessionSetCount() {
val realm = this.mockRealm
realm.beginTransaction()
val s1 = realm.createObject(Session::class.java, "1")
s1.timeFrame = realm.createObject(TimeFrame::class.java)
s1.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java)
realm.insert(s1)
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm")
val sd1 = sdf.parse("01/1/2019 09:00")
val ed1 = sdf.parse("01/1/2019 10:00")
s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
realm.copyToRealmOrUpdate(s1)
realm.commitTransaction()
val sets = realm.where(SessionSet::class.java).findAll()
Assert.assertEquals(1, sets.size)
val set = sets.first()
if (set != null) {
Assert.assertEquals(sd1.time, set.timeFrame?.startDate?.time)
Assert.assertEquals(ed1.time, set.timeFrame?.endDate?.time)
} else {
Assert.fail("No set")
}
}
@Test
fun testSessionSetCount2() {
val realm = this.mockRealm
realm.beginTransaction()
val s1 = realm.createObject(Session::class.java, "1")
val s2 = realm.createObject(Session::class.java, "2")
s1.timeFrame = realm.createObject(TimeFrame::class.java)
s2.timeFrame = realm.createObject(TimeFrame::class.java)
s1.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java)
s2.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java)
realm.insert(s1)
realm.insert(s2)
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm")
val sd1 = sdf.parse("01/1/2019 09:00")
val ed1 = sdf.parse("01/1/2019 10:00")
val sd2 = sdf.parse("01/2/2018 09:00")
val ed2 = sdf.parse("01/2/2018 10:00")
s1.timeFrame?.let {
it.setStart(sd1)
it.setEnd(ed1)
}
s2.timeFrame?.let {
it.setStart(sd2)
it.setEnd(ed2)
}
// s1.timeFrame?.setDate(sd1, ed1) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
// s2.timeFrame?.setDate(sd2, ed2) // netDuration = 1h, hourly = -100, bb100 = -200bb / 25hands * 100 = -800
realm.copyToRealmOrUpdate(s1)
realm.copyToRealmOrUpdate(s2)
realm.commitTransaction()
val sets = realm.where(SessionSet::class.java).findAll()
Assert.assertEquals(2, sets.size)
// val set = sets.first()
// if (set != null) {
// Assert.assertEquals(sd1.time, set.timeFrame?.startDate?.time)
// Assert.assertEquals(ed1.time, set.timeFrame?.endDate?.time)
// } else {
// Assert.fail("No set")
// }
}
// @Test
// fun testDurationConversion() {
//
// val duration = 6.7555561274509826
// val longDuration = duration.toLong()
// val formatted = longDuration.toMinutes()
//
// assert(formatted == "11:00")
// }
}

@ -131,8 +131,8 @@ class PokerAnalyticsApplication : Application() {
for (index in 0..50) {
realm.executeTransaction {
val session = Session()
session.id = UUID.randomUUID().toString()
val session = Session.newInstance(realm, false)
// session.id = UUID.randomUUID().toString()
val calendar = Calendar.getInstance()
calendar.set(
@ -148,21 +148,27 @@ class PokerAnalyticsApplication : Application() {
calendar.add(Calendar.MINUTE, (0..59).random())
val endDate = calendar.time
val timeFrame = TimeFrame()
timeFrame.setDate(startDate, endDate)
session.timeFrame = timeFrame
// val timeFrame = TimeFrame()
session.timeFrame?.let {
// it.startDate = startDate
// it.endDate = endDate
it.setDate(startDate, endDate)
}
// session.timeFrame = timeFrame
session.creationDate = startDate
session.limit = Limit.values().random().ordinal
session.game = realm.where<Game>().findAll().random()
val result = Result()
session.result?.let { result ->
result.buyin = arrayListOf(100, 200, 300, 500, 1000, 2000).random().toDouble()
result.netResult = arrayListOf(
-2500.0, -2000.0, -1500.0, -1000.0, -500.0, 200.0, 1000.0, 1500.0,
2500.0
).random()
session.result = result
}
realm.copyToRealmOrUpdate(session)
}
@ -172,6 +178,16 @@ class PokerAnalyticsApplication : Application() {
realm.close()
val sets = realm.where(SessionSet::class.java).findAll()
// Timber.d("sets = ${sets.size}")
//
// sets.forEach { set ->
// Timber.d("set sd = : ${set.timeFrame?.startDate}, ed = ${set.timeFrame?.endDate}")
// }
}
}

@ -7,7 +7,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.FormatUtils
import net.pokeranalytics.android.util.formatted
import net.pokeranalytics.android.util.toMinutes
import net.pokeranalytics.android.util.formattedHourlyDuration
/**
* An enum representing all the types of Session statistics
@ -138,7 +138,7 @@ class ComputedStat(stat: Stat, value: Double) {
return TextFormat("${value.toInt()}")
} // white durations
Stat.DURATION, Stat.AVERAGE_DURATION -> {
return TextFormat("${value.toLong().toMinutes()}")
return TextFormat(value.formattedHourlyDuration())
} // red/green percentages
Stat.WIN_RATIO, Stat.ROI -> {
val color = if (value >= this.stat.threshold) R.color.green else R.color.red

@ -37,6 +37,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
companion object {
fun newInstance(realm: Realm, isTournament: Boolean): Session {
val session = Session()
session.timeFrame = TimeFrame()
session.result = Result()
session.bankroll = realm.where<Bankroll>().findFirst()
session.type = if (isTournament) Session.Type.TOURNAMENT.ordinal else Session.Type.CASH_GAME.ordinal
@ -59,7 +60,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
var timeFrame: TimeFrame? = null
set(value) {
field = value
value?.let { it.notifySessionDateChange(this) }
// value?.let { it.notifySessionDateChange(this) }
}
// The time frame sessionGroup, which can contain multiple sessions
@ -142,7 +143,8 @@ open class Session : RealmObject(), SessionInterface, Savable,
when (getState()) {
SessionState.PENDING, SessionState.PLANNED -> {
val sessionTimeFrame = this.timeFrame ?: realm.createObject(TimeFrame::class.java)
sessionTimeFrame.setDate(Date(), null)
sessionTimeFrame.setStart(Date())
// sessionTimeFrame.setDate(Date(), null)
this.timeFrame = sessionTimeFrame
}
SessionState.PAUSED -> {
@ -178,7 +180,8 @@ open class Session : RealmObject(), SessionInterface, Savable,
SessionState.STARTED, SessionState.PAUSED -> {
this.timeFrame?.paused = false
this.timeFrame?.pauseDate = null
this.timeFrame?.setDate(null, Date())
this.timeFrame?.setEnd(Date())
// this.timeFrame?.setDate(null, Date())
}
else -> throw Exception("Stopping session in unmanaged state")
}
@ -198,7 +201,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
}
/**
* Return the duration of the current session
* Return the netDuration of the current session
*/
fun getDuration(): String {
val startDate = timeFrame?.startDate ?: Date()
@ -570,7 +573,8 @@ open class Session : RealmObject(), SessionInterface, Savable,
SessionRow.END_DATE -> if (value is Date?) {
val timeFrameToUpdate =
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
timeFrameToUpdate.setDate(null, value)
// timeFrameToUpdate.setDate(null, value)
timeFrameToUpdate.setEnd(value)
timeFrame = timeFrameToUpdate
}
SessionRow.GAME -> {
@ -604,7 +608,8 @@ open class Session : RealmObject(), SessionInterface, Savable,
} else {
val timeFrameToUpdate =
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
timeFrameToUpdate.setDate(value, null)
timeFrameToUpdate.setStart(value)
// timeFrameToUpdate.setDate(value, null)
timeFrame = timeFrameToUpdate
}
}

@ -9,6 +9,16 @@ import io.realm.annotations.LinkingObjects
open class SessionSet() : RealmObject() {
companion object {
fun newInstance(realm: Realm) : SessionSet {
val sessionSet: SessionSet = realm.createObject(SessionSet::class.java)
sessionSet.timeFrame = realm.createObject(TimeFrame::class.java)
return realm.copyToRealm(sessionSet)
}
}
/**
* The timeframe of the set, i.e. its start & end date
*/
@ -21,13 +31,13 @@ open class SessionSet() : RealmObject() {
@LinkingObjects("sessionSet")
val sessions: RealmResults<Session>? = null
@Ignore // a duration shortcut
@Ignore // a netDuration shortcut
var duration: Long = 0L
get() {
return this.timeFrame?.duration ?: 0L
return this.timeFrame?.netDuration ?: 0L
}
@Ignore // a duration in hour
@Ignore // a netDuration in hour
var hourlyDuration: Double = 0.0
get() {
return this.timeFrame?.hourlyDuration ?: 0.0
@ -39,7 +49,7 @@ open class SessionSet() : RealmObject() {
return this.sessions?.sumByDouble { it.value } ?: 0.0
}
@Ignore // a duration shortcut
@Ignore // a netDuration shortcut
var hourlyRate: Double = 0.0
get () {
return this.netResult / this.hourlyDuration
@ -51,15 +61,6 @@ open class SessionSet() : RealmObject() {
@Ignore
var bbNetResult: Double = 0.0
companion object {
fun newInstance(realm: Realm) : SessionSet {
val sessionSet: SessionSet = realm.createObject(SessionSet::class.java)
sessionSet.timeFrame = realm.createObject(TimeFrame::class.java)
return sessionSet
}
}
}

@ -1,6 +1,5 @@
package net.pokeranalytics.android.model.realm
import io.realm.Realm
import io.realm.RealmObject
import io.realm.RealmQuery
import io.realm.RealmResults
@ -38,20 +37,20 @@ open class TimeFrame : RealmObject() {
this.computeDuration()
}
// The break duration
// The break netDuration
var breakDuration: Long = 0L
set(value) {
field = value
this.computeDuration()
}
// the total duration
var duration: Long = 0L
// the total netDuration
var netDuration: Long = 0L
private set
var hourlyDuration: Double = 0.0
get() {
return this.duration / 3600000.0 // 3.6 millions of milliseconds
return this.netDuration / 3600000.0 // 3.6 millions of milliseconds
}
// indicates a state of pause
@ -73,29 +72,35 @@ open class TimeFrame : RealmObject() {
var set: SessionSet? = null
get() = this.sets?.first()
fun setDate(startDate: Date?, endDate: Date?) {
startDate?.let {
fun setStart(startDate: Date) {
this.startDate = startDate
this.session?.let {
this.notifySessionDateChange(it)
}
}
fun setEnd(endDate: Date?) {
this.endDate = endDate
this.session?.let {
this.notifySessionDateChange(it)
}
}
this.computeDuration()
fun setDate(startDate: Date, endDate: Date?) {
this.startDate = startDate
this.endDate = endDate
this.session?.let {
this.notifySessionDateChange(it)
}
}
/**
* Computes the net duration of the session
* Computes the net netDuration of the session
*/
private fun computeDuration() {
var endDate: Date = this.endDate ?: Date()
val netDuration = endDate.time - this.startDate.time - this.breakDuration
this.duration = netDuration
this.netDuration = endDate.time - this.startDate.time - this.breakDuration
}
/**
@ -103,25 +108,35 @@ open class TimeFrame : RealmObject() {
* Makes all necessary changes to keep sequential time frames
*/
fun notifySessionDateChange(owner: Session) {
val realm = Realm.getDefaultInstance()
var query: RealmQuery<SessionSet> = realm.where(SessionSet::class.java)
var query: RealmQuery<SessionSet> = this.realm.where(SessionSet::class.java)
query.isNotNull("timeFrame")
// Timber.d("this> sd = : ${this.startDate}, ed = ${this.endDate}")
val sets = realm.where(SessionSet::class.java).findAll()
// Timber.d("set count = ${sets.size}")
if (this.endDate == null) {
query.greaterThan("timeFrame.startDate", this.startDate).or().greaterThan("timeFrame.endDate", this.startDate)
query.greaterThanOrEqualTo("timeFrame.startDate", this.startDate)
.or()
.greaterThanOrEqualTo("timeFrame.endDate", this.startDate)
.or()
.isNull("timeFrame.endDate")
} else {
val endDate = this.endDate!!
query
.lessThan("timeFrame.startDate", this.startDate)
.greaterThan("timeFrame.endDate", this.startDate)
.lessThanOrEqualTo("timeFrame.startDate", this.startDate)
.greaterThanOrEqualTo("timeFrame.endDate", this.startDate)
.or()
.lessThanOrEqualTo("timeFrame.startDate", endDate)
.greaterThanOrEqualTo("timeFrame.endDate", endDate)
.or()
.lessThan("timeFrame.startDate", endDate)
.greaterThan("timeFrame.endDate", endDate)
.greaterThanOrEqualTo("timeFrame.startDate", this.startDate)
.lessThanOrEqualTo("timeFrame.endDate", endDate)
.or()
.greaterThan("timeFrame.startDate", this.startDate)
.lessThan("timeFrame.endDate", endDate)
.isNull("timeFrame.endDate")
.lessThanOrEqualTo("timeFrame.startDate", endDate)
}
val sessionGroups = query.findAll()
@ -137,7 +152,7 @@ open class TimeFrame : RealmObject() {
when (sessionSets.size) {
0 -> this.createSessionGroup(owner)
1 -> this.updateSingleSessionGroup(owner, sessionSets.first()!!)
1 -> this.updateSessionGroup(owner, sessionSets.first()!!)
else -> this.mergeSessionGroups(owner, sessionSets)
}
@ -148,9 +163,7 @@ open class TimeFrame : RealmObject() {
*/
private fun createSessionGroup(owner: Session) {
val realm = Realm.getDefaultInstance()
val set: SessionSet = SessionSet.newInstance(realm)
val set: SessionSet = SessionSet.newInstance(this.realm)
set.timeFrame?.let {
it.startDate = this.startDate
it.endDate = this.endDate
@ -160,30 +173,54 @@ open class TimeFrame : RealmObject() {
owner.sessionSet = set
Timber.d("sd = : ${set.timeFrame?.startDate}, ed = ${set.timeFrame?.endDate}")
// Timber.d("sd = : ${set.timeFrame?.startDate}, ed = ${set.timeFrame?.endDate}")
Timber.d("netDuration 1 = : ${set.timeFrame?.netDuration}")
}
/**
* Single session sessionGroup update
* Single SessionSet update, the session might be the owner
* Changes the sessionGroup timeframe using the current timeframe dates
*/
private fun updateSingleSessionGroup(owner: Session, sessionSet: SessionSet) {
private fun updateSessionGroup(owner: Session, sessionSet: SessionSet) {
var groupTimeFrame: TimeFrame = sessionSet.timeFrame!! // tested in the query
var timeFrame: TimeFrame = sessionSet.timeFrame!! // tested in the query
// timeFrame.setDate(this.startDate, this.endDate)
val sisterSessions = sessionSet.sessions!! // shouldn't crash ever
// if we have only one session in the set and that it corresponds to the set
if (sessionSet.sessions?.size == 1 && sessionSet.sessions?.first() == owner) {
timeFrame.setDate(this.startDate, this.endDate)
} else { // there are 2+ sessions to manage and possible splits
if (this.startDate.before(groupTimeFrame.startDate)) {
groupTimeFrame.startDate = this.startDate
}
val endDate = this.endDate
if (endDate != null && groupTimeFrame.endDate != null && endDate.after(groupTimeFrame.endDate)) {
groupTimeFrame.endDate = endDate
// case where all sessions are over but the set is not, we might have a split, so we delete the set and save everything again
if (endDate != null && sisterSessions.all { it.timeFrame?.endDate != null } && timeFrame.endDate == null) {
var sessions = mutableListOf<Session>(owner)
sessionSet.sessions?.forEach { sessions.add(it) }
sessionSet.deleteFromRealm()
sessions.forEach { it.timeFrame?.notifySessionDateChange(it) }
} else {
if (this.startDate.before(timeFrame.startDate)) {
timeFrame.startDate = this.startDate
}
if (endDate != null && timeFrame.endDate != null && endDate.after(timeFrame.endDate)) {
timeFrame.endDate = endDate
} else if (endDate == null) {
groupTimeFrame.endDate = null
timeFrame.endDate = null
}
owner.sessionSet = sessionSet
// Timber.d("sd = : ${sessionSet.timeFrame?.startDate}, ed = ${sessionSet.timeFrame?.endDate}")
Timber.d("netDuration 2 = : ${sessionSet.timeFrame?.netDuration}")
}
}
}
/**
@ -216,16 +253,17 @@ open class TimeFrame : RealmObject() {
// get all sessions from sets
var sessions = mutableSetOf<Session>()
sessionSets.forEach { it.sessions?.asIterable()?.let { it1 -> sessions.addAll(it1) } }
sessionSets.forEach { set ->
set.sessions?.asIterable()?.let { sessions.addAll(it) }
}
// delete all sets
sessionSets.deleteAllFromRealm()
// Create a new sets
val set: SessionSet = SessionSet.newInstance(realm)
val set: SessionSet = SessionSet.newInstance(this.realm)
set.timeFrame?.let {
it.startDate = startDate
it.endDate = endDate
it.setDate(startDate, endDate)
} ?: run {
throw ModelException("TimeFrame should never be null here")
}
@ -235,6 +273,7 @@ open class TimeFrame : RealmObject() {
// Add all orphan sessions
sessions.forEach { it.sessionSet = set }
Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}")
}

@ -84,7 +84,7 @@ fun Date.getMonthAndYear(): String {
return SimpleDateFormat("MMMM YYYY", Locale.getDefault()).format(this).capitalize()
}
// Return the duration between two dates
// Return the netDuration between two dates
fun Date.getDuration(toDate: Date) : String {
val difference = (toDate.time - this.time).toInt()
val numOfDays = (difference / (1000 * 60 * 60 * 24))

@ -25,6 +25,10 @@ fun Double.toCurrency(): String {
return format.format(this)
}
fun Double.formattedHourlyDuration() : String {
return (this * 1000 * 3600).toLong().toMinutes()
}
// Return the time from milliseconds to hours:minutes
fun Long.toMinutes() : String {
val totalMinutes = this / (1000 * 60)

Loading…
Cancel
Save