-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 Remove some util enums and replaced with default DateTimeFormatter
Signed-off-by: Leonardo Colman Lopes <[email protected]>
- Loading branch information
Showing
8 changed files
with
111 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package br.com.colman.petals.utils | ||
|
||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.temporal.ChronoUnit | ||
import java.time.temporal.ChronoUnit.MINUTES | ||
|
||
fun LocalTime.truncatedToMinute(): LocalTime = truncatedTo(ChronoUnit.MINUTES) | ||
fun LocalDateTime.truncatedToMinute(): LocalDateTime = truncatedTo(MINUTES) | ||
fun LocalTime.truncatedToMinute(): LocalTime = truncatedTo(MINUTES) |
10 changes: 0 additions & 10 deletions
10
app/src/main/kotlin/br/com/colman/petals/utils/datetime/DateTimeFormatEnum.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
app/src/main/kotlin/br/com/colman/petals/utils/datetime/TimeFormatEnum.kt
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
app/src/test/kotlin/br/com/colman/petals/utils/DateTimeExtensionsTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package br.com.colman.petals.utils | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.temporal.ChronoUnit | ||
|
||
class DateTimeExtensionsTest : FunSpec({ | ||
|
||
context("LocalDateTime truncation") { | ||
|
||
test("should truncate to minute for current time") { | ||
val dateTime = LocalDateTime.now() | ||
val expectedDateTime = dateTime.truncatedTo(ChronoUnit.MINUTES) | ||
|
||
dateTime.truncatedToMinute() shouldBe expectedDateTime | ||
} | ||
|
||
test("should truncate to minute for a specific time") { | ||
val dateTime = LocalDateTime.of(1998, 2, 9, 20, 0, 45) | ||
val expectedDateTime = LocalDateTime.of(1998, 2, 9, 20, 0) | ||
|
||
dateTime.truncatedToMinute() shouldBe expectedDateTime | ||
} | ||
|
||
test("should handle truncation of an already truncated time") { | ||
val dateTime = LocalDateTime.of(1998, 2, 9, 20, 0) | ||
val expectedDateTime = LocalDateTime.of(1998, 2, 9, 20, 0) | ||
|
||
dateTime.truncatedToMinute() shouldBe expectedDateTime | ||
} | ||
} | ||
|
||
context("LocalTime truncation") { | ||
|
||
test("should truncate to minute for current time") { | ||
val time = LocalTime.now() | ||
val expectedTime = time.truncatedTo(ChronoUnit.MINUTES) | ||
|
||
time.truncatedToMinute() shouldBe expectedTime | ||
} | ||
|
||
test("should truncate to minute for a specific time") { | ||
val time = LocalTime.of(20, 0, 45) | ||
val expectedTime = LocalTime.of(20, 0) | ||
|
||
time.truncatedToMinute() shouldBe expectedTime | ||
} | ||
|
||
test("should handle truncation of an already truncated time") { | ||
val time = LocalTime.of(20, 30) | ||
val expectedTime = LocalTime.of(20, 30) | ||
|
||
time.truncatedToMinute() shouldBe expectedTime | ||
} | ||
|
||
test("should handle midnight correctly") { | ||
val time = LocalTime.MIDNIGHT | ||
val expectedTime = LocalTime.MIDNIGHT | ||
|
||
time.truncatedToMinute() shouldBe expectedTime | ||
} | ||
} | ||
}) |