Skip to content

Instantly share code, notes, and snippets.

@ssouris
Last active June 2, 2017 17:06
Show Gist options
  • Select an option

  • Save ssouris/c708d57ce3589f2b9c5b72ae917f3d75 to your computer and use it in GitHub Desktop.

Select an option

Save ssouris/c708d57ce3589f2b9c5b72ae917f3d75 to your computer and use it in GitHub Desktop.

Revisions

  1. ssouris revised this gist Jun 2, 2017. No changes.
  2. ssouris revised this gist Jun 2, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ExtensionMethods.kt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    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))
    @@ -10,4 +11,4 @@ fun `Test LocalDate#toStr extension method`() {
    @Test
    fun `Test String#toLocalDate extension method`() {
    Assert.assertEquals("01/01/1970".toLocalDate(), LocalDate.of(1970, 1, 1))
    }
    }
  3. ssouris revised this gist Jun 2, 2017. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions ExtensionMethods.kt
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,3 @@
    fun ServerResponse.BodyBuilder.html() = contentType(TEXT_HTML)

    // example usage -> ok().html().render("pets/edit", it)


    // Date Extension methods
    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))
  4. ssouris renamed this gist Jun 2, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. ssouris revised this gist Jun 2, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion ExtensionMethods
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    fun ServerResponse.BodyBuilder.html() = contentType(TEXT_HTML)

    // Date Extension methods
    // example usage -> ok().html().render("pets/edit", it)


    // Date Extension methods
    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))
  6. ssouris created this gist Jun 2, 2017.
    17 changes: 17 additions & 0 deletions ExtensionMethods
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    fun ServerResponse.BodyBuilder.html() = contentType(TEXT_HTML)

    // Date Extension methods

    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))
    }