libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit d1aa17de9a16bd4dbf24ba4e946203e1db5c243f
parent f8ff5c0a81bd74e3ca094f5b02bcd4a26b3a11ea
Author: MS <ms@taler.net>
Date:   Wed, 15 Nov 2023 15:11:52 +0100

nexus fetch: adapt time parser to camt.054

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt | 2+-
Mnexus/src/test/kotlin/Parsing.kt | 9++++++++-
Mutil/src/main/kotlin/time.kt | 11++++++-----
3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt @@ -251,7 +251,7 @@ fun findIncomingTxInNotification( // Obtaining the execution time. val executionTime: Instant = requireUniqueChildNamed("RltdDts") { requireUniqueChildNamed("AccptncDtTm") { - parseGregorianTime(focusElement.textContent) + parseCamtTime(focusElement.textContent) } } // Obtaining the payer's details diff --git a/nexus/src/test/kotlin/Parsing.kt b/nexus/src/test/kotlin/Parsing.kt @@ -1,10 +1,10 @@ -import net.taler.wallet.crypto.Base32Crockford import org.junit.Test import org.junit.jupiter.api.assertThrows import tech.libeufin.nexus.TalerAmount import tech.libeufin.nexus.getAmountNoCurrency import tech.libeufin.nexus.getTalerAmount import tech.libeufin.nexus.isReservePub +import tech.libeufin.util.parseCamtTime import java.lang.StringBuilder import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -12,6 +12,13 @@ import kotlin.test.assertNull import kotlin.test.assertTrue class Parsing { + + @Test + fun gregorianTime() { + parseCamtTime("2023-11-06T20:00:00") + assertThrows<Exception> { parseCamtTime("2023-11-06T20:00:00+01:00") } + assertThrows<Exception> { parseCamtTime("2023-11-06T20:00:00Z") } + } @Test // Could be moved in a dedicated Amounts.kt test module. fun generateCurrencyAgnosticAmount() { assertThrows<Exception> { diff --git a/util/src/main/kotlin/time.kt b/util/src/main/kotlin/time.kt @@ -82,13 +82,14 @@ fun Long.microsToJavaInstant(): Instant? { } /** - * Parses one timestamp from the ISO 8601 format. + * Parses timestamps found in camt.054 documents. They have + * the following format: yyy-MM-ddThh:mm:ss, without any timezone. * * @param timeFromXml input time string from the XML * @return [Instant] in the UTC timezone */ -fun parseGregorianTime(timeFromXml: String): Instant { - val formatter = DateTimeFormatter.ISO_DATE_TIME.parse(timeFromXml) - return Instant.from(formatter) - +fun parseCamtTime(timeFromCamt: String): Instant { + val t = LocalDateTime.parse(timeFromCamt) + val utc = ZoneId.of("UTC") + return t.toInstant(utc.rules.getOffset(t)) } \ No newline at end of file