Skip to content

Instantly share code, notes, and snippets.

@ssouris
Last active June 2, 2017 17:06
Show Gist options
  • Save ssouris/c708d57ce3589f2b9c5b72ae917f3d75 to your computer and use it in GitHub Desktop.
Save ssouris/c708d57ce3589f2b9c5b72ae917f3d75 to your computer and use it in GitHub Desktop.
fun LocalDate.toStr(format:String = "dd/MM/yyyy") = DateTimeFormatter.ofPattern(format).format(this)
fun String.toDate(format:String = "dd/MM/yyyy") = LocalDate.parse(this, DateTimeFormatter.ofPattern(format))
@Test
fun `Test LocalDate#toStr extension method`() {
Assert.assertEquals(LocalDate.of(1970, 1, 1).toStr(), "01/01/1970")
}
@Test
fun `Test String#toLocalDate extension method`() {
Assert.assertEquals("01/01/1970".toLocalDate(), LocalDate.of(1970, 1, 1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment