Changed to half down rounding.
This commit is contained in:
parent
0058fa0094
commit
67665ca859
2 changed files with 3 additions and 3 deletions
|
@ -121,7 +121,7 @@ class ReadingTime @JvmOverloads constructor(
|
||||||
* Calculates and returns the reading time. (eg. 1 min read)
|
* Calculates and returns the reading time. (eg. 1 min read)
|
||||||
*/
|
*/
|
||||||
fun calcReadingTime(): String {
|
fun calcReadingTime(): String {
|
||||||
val time = BigDecimal((calcReadingTimeInSec() / 60.0)).setScale(0, RoundingMode.CEILING)
|
val time = BigDecimal((calcReadingTimeInSec() / 60.0)).setScale(0, RoundingMode.HALF_DOWN)
|
||||||
return if (time.compareTo(BigDecimal.ONE) == 1) {
|
return if (time.compareTo(BigDecimal.ONE) == 1) {
|
||||||
"$time $plural".trim()
|
"$time $plural".trim()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -149,10 +149,10 @@ class ReadingTimeTest {
|
||||||
@Test
|
@Test
|
||||||
fun testReadingTime() {
|
fun testReadingTime() {
|
||||||
rt.text = blogPost
|
rt.text = blogPost
|
||||||
assertEquals("3 min read", rt.calcReadingTime())
|
assertEquals("2 min read", rt.calcReadingTime())
|
||||||
|
|
||||||
rt.plural = "mins read"
|
rt.plural = "mins read"
|
||||||
assertEquals("3 mins read", rt.calcReadingTime())
|
assertEquals("2 mins read", rt.calcReadingTime())
|
||||||
|
|
||||||
rt.text = mediumPost
|
rt.text = mediumPost
|
||||||
rt.plural = ""
|
rt.plural = ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue