summaryrefslogtreecommitdiff
path: root/ebics/src/main/kotlin/iso20022/utils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'ebics/src/main/kotlin/iso20022/utils.kt')
-rw-r--r--ebics/src/main/kotlin/iso20022/utils.kt32
1 files changed, 32 insertions, 0 deletions
diff --git a/ebics/src/main/kotlin/iso20022/utils.kt b/ebics/src/main/kotlin/iso20022/utils.kt
new file mode 100644
index 00000000..9e65be00
--- /dev/null
+++ b/ebics/src/main/kotlin/iso20022/utils.kt
@@ -0,0 +1,32 @@
+/*
+ * This file is part of LibEuFin.
+ * Copyright (C) 2024 Taler Systems S.A.
+ *
+ * LibEuFin is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3, or
+ * (at your option) any later version.
+ *
+ * LibEuFin is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with LibEuFin; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>
+ */
+
+package tech.libeufin.ebics.iso20022
+
+import java.time.format.*
+import java.time.*
+
+/** Handle escaped enum variant due to Java limitation */
+inline fun <reified T : kotlin.Enum<T>> String.xmlCodeSet(): T
+ = java.lang.Enum.valueOf(T::class.java, if (this[0].isDigit()) "_$this" else this)
+
+fun String.toDate(): LocalDate = LocalDate.parse(this, DateTimeFormatter.ISO_DATE)
+fun String.toDateTime(): LocalDateTime = LocalDateTime.parse(this, DateTimeFormatter.ISO_DATE_TIME)
+fun String.toYearMonth(): YearMonth = YearMonth.parse(this, DateTimeFormatter.ISO_DATE)
+fun String.toYear(): Year = Year.parse(this, DateTimeFormatter.ISO_DATE) \ No newline at end of file