Created
September 21, 2021 21:38
-
-
Save mattmook/147ce7609c6697d0f3a333b9d1c01469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val ddMMMMyyyyRegex = "([0-9]{1,2})\\s+([A-Za-z]{3,4})\\s+([0-9]{4})".toRegex() | |
private val monthMapping = mapOf( | |
"Jan" to Month.JANUARY, | |
... | |
"Sep" to Month.SEPTEMBER, | |
"Sept" to Month.SEPTEMBER, | |
... | |
"Dec" to Month.DECEMBER | |
) | |
fun String.toLocalDate(): LocalDate? { | |
return ddMMMMyyyyRegex.matchEntire(this)?.groupValues?.let { | |
val (_, day, month, year) = it | |
LocalDate.of(year.toInt(), monthMapping[month], day.toInt()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment