-
-
Save mochadwi/ba5ea0dae2ea8b2688cab5e91e1a8f6d 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
sealed class ParsedDate { | |
data class Success(val date: Date) : ParsedDate() | |
data class Failure(val errorOffset: Int) : ParsedDate() | |
} | |
fun DateFormat.tryParse(text: String): ParsedDate = | |
try { | |
ParsedDate.Success(parse(text)) | |
} catch (e: ParseException) { | |
ParsedDate.Failure(e.errorOffset) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment