-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update weekly report chart properties
- Loading branch information
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: Android Lint | |
on: push | ||
|
||
jobs: | ||
build: | ||
lint_checks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
|
32 changes: 29 additions & 3 deletions
32
core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
package com.jacob.wakatimeapp.core.models | ||
|
||
data class Time(val hours: Int, val minutes: Int, val decimal: Float) { | ||
@Suppress("MagicNumber") | ||
fun toMinutes(): Int = (hours * 60) + minutes | ||
data class Time( | ||
val hours: Int, | ||
val minutes: Int, | ||
val decimal: Float, | ||
val totalSeconds: Int = calculateTotalSeconds(hours, minutes), | ||
) { | ||
fun toMinutes(): Int = (hours * MINUTES_IN_HOURS) + minutes | ||
|
||
fun formattedPrint() = "${hours}H, ${minutes}M" | ||
|
||
fun longFormattedPrint() = "$hours Hours, $minutes Minutes" | ||
|
||
companion object { | ||
private fun calculateTotalSeconds(hours: Int, minutes: Int) = | ||
(hours * MINUTES_IN_HOURS * MINUTES_IN_HOURS) + (minutes * MINUTES_IN_HOURS) | ||
|
||
fun fromDecimal(decimal: Float): Time { | ||
val hours = decimal.toInt() | ||
val minutesDecimal = (decimal - hours) * MINUTES_IN_HOURS | ||
val minutes = minutesDecimal.toInt() | ||
val totalSeconds = calculateTotalSeconds(hours, minutes) | ||
return Time( | ||
decimal = decimal, | ||
hours = hours, | ||
minutes = minutes, | ||
totalSeconds = totalSeconds | ||
) | ||
} | ||
|
||
fun createFrom(timeString: String, decimal: String): Time { | ||
val (hours, minutes) = timeString.split(":") | ||
.map(String::toInt) | ||
return Time(hours, minutes, decimal.toFloat()) | ||
} | ||
|
||
private const val MINUTES_IN_HOURS = 60 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters