Handle potential exception when converting date

This commit is contained in:
EdgarPi 2024-07-23 12:10:19 +02:00
parent 5f1dbd1056
commit 558c37cc94

View file

@ -449,12 +449,12 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
null, null,
null, null,
plot = this.node.synopsis, plot = this.node.synopsis,
releaseDate = if (this.node.start_date == null) null else Date.from( releaseDate = if (this.node.start_date == null) null else try {Date.from(
Instant.from( Instant.from(
DateTimeFormatter.ofPattern(if (this.node.start_date.length == 4) "yyyy" else if (this.node.start_date.length == 7) "yyyy-MM" else "yyyy-MM-dd") DateTimeFormatter.ofPattern(if (this.node.start_date.length == 4) "yyyy" else if (this.node.start_date.length == 7) "yyyy-MM" else "yyyy-MM-dd")
.parse(this.node.start_date) .parse(this.node.start_date)
) )
) )} catch (_: RuntimeException) {null}
) )
} }
} }