Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed Jan 27, 2022
2 parents 8d3dfe1 + 129d420 commit 13ff3b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ fun Int.doubleDigits() = if (this <= BIGGEST_DIGIT) "0$this" else "$this"

fun CurrencyResponse.toRates() = rates.copy(base = base, date = nowAsInstant().toDateString())

fun CurrencyResponse.toTodayResponse() = copy(date = nowAsInstant().toDateString())

fun Rates?.calculateResult(name: String, input: String?) = this
?.whetherNot { input.isNullOrEmpty() }
?.getConversionByName(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.github.mustafaozhan.ccc.client.util.launchIgnored
import com.github.mustafaozhan.ccc.client.util.toRates
import com.github.mustafaozhan.ccc.client.util.toStandardDigits
import com.github.mustafaozhan.ccc.client.util.toSupportedCharacters
import com.github.mustafaozhan.ccc.client.util.toTodayResponse
import com.github.mustafaozhan.ccc.client.viewmodel.calculator.CalculatorData.Companion.CHAR_DOT
import com.github.mustafaozhan.ccc.client.viewmodel.calculator.CalculatorData.Companion.KEY_AC
import com.github.mustafaozhan.ccc.client.viewmodel.calculator.CalculatorData.Companion.KEY_DEL
Expand Down Expand Up @@ -105,7 +106,7 @@ class CalculatorViewModel(
calculateConversions(it)
_state.update(rateState = RateState.Online(it.date))
}.also {
offlineRatesRepository.insertOfflineRates(currencyResponse)
offlineRatesRepository.insertOfflineRates(currencyResponse.toTodayResponse())
}

private fun getRatesFailed(t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.github.mustafaozhan.ccc.client.util.toInstant
import com.github.mustafaozhan.ccc.client.util.toRates
import com.github.mustafaozhan.ccc.client.util.toStandardDigits
import com.github.mustafaozhan.ccc.client.util.toSupportedCharacters
import com.github.mustafaozhan.ccc.client.util.toTodayResponse
import com.github.mustafaozhan.ccc.client.util.toValidList
import com.github.mustafaozhan.ccc.common.model.CurrencyResponse
import com.github.mustafaozhan.ccc.common.model.CurrencyType
Expand Down Expand Up @@ -163,6 +164,12 @@ class ExtensionsTest {
assertEquals(rates, currencyResponse.toRates())
}

@Test
fun currencyResponseToTodayResponse() {
val currencyResponse = CurrencyResponse("EUR", null, Rates())
assertEquals(currencyResponse.copy(date = nowAsInstant().toDateString()), currencyResponse.toTodayResponse())
}

@Test
fun isWeekPassed() {
assertEquals(true, (nowAsLong() - 1 - WEEK).isWeekPassed())
Expand Down

0 comments on commit 13ff3b0

Please sign in to comment.