-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Tp11Test" type="GradleRunConfiguration" factoryName="Gradle"> | ||
<ExternalSystemSettings> | ||
<option name="executionName" /> | ||
<option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||
<option name="externalSystemIdString" value="GRADLE" /> | ||
<option name="scriptParameters" value="" /> | ||
<option name="taskDescriptions"> | ||
<list /> | ||
</option> | ||
<option name="taskNames"> | ||
<list> | ||
<option value=":tp11:test" /> | ||
<option value="--tests" /> | ||
<option value=""fmt.kotlin.fundamentals.Tp11Test"" /> | ||
</list> | ||
</option> | ||
<option name="vmOptions" /> | ||
</ExternalSystemSettings> | ||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess> | ||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> | ||
<DebugAllEnabled>false</DebugAllEnabled> | ||
<RunAsTest>true</RunAsTest> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,8 +1,10 @@ | ||
[versions] | ||
junit = "5.10.1" | ||
strikt = "0.34.0" | ||
datetime = "0.6.2" | ||
|
||
[libraries] | ||
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit"} | ||
junit-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit"} | ||
strikt = { group = "io.strikt", name = "strikt-core", version.ref = "strikt" } | ||
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "datetime" } |
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,7 @@ | ||
plugins { | ||
id("fmt.kotlin.fundamentals.gradle.component.tp") | ||
} | ||
|
||
dependencies { | ||
implementation(libs.kotlinx.datetime) | ||
} |
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,35 @@ | ||
package fmt.kotlin.fundamentals | ||
|
||
import kotlinx.datetime.* | ||
import kotlinx.datetime.format.MonthNames | ||
import kotlinx.datetime.format.alternativeParsing | ||
import kotlinx.datetime.format.char | ||
import kotlin.time.Duration.Companion.days | ||
|
||
class Tp11 { | ||
|
||
fun whichDayIsInTwoDays(clock: Clock): DayOfWeek = TODO() | ||
|
||
fun parseInstant(s: String): LocalDateTime = TODO() | ||
|
||
fun daysBetween(instant1: Instant, instant2: Instant): Long = TODO() | ||
|
||
companion object { | ||
private val frenchMonthNames = MonthNames( | ||
listOf( | ||
"janvier", | ||
"février", | ||
"mars", | ||
"avril", | ||
"mai", | ||
"juin", | ||
"juillet", | ||
"août", | ||
"septembre", | ||
"octobre", | ||
"novembre", | ||
"décembre" | ||
) | ||
) | ||
} | ||
} |
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,42 @@ | ||
package fmt.kotlin.fundamentals | ||
|
||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.Instant | ||
import kotlinx.datetime.LocalDateTime | ||
import strikt.api.expectThat | ||
import strikt.assertions.isEqualTo | ||
import java.time.DayOfWeek.MONDAY | ||
import kotlin.test.Test | ||
|
||
class Tp11Test { | ||
|
||
private val tp11 = Tp11() | ||
private val now = Instant.parse("1985-11-16T10:00:00Z") | ||
private val clock = object : Clock { | ||
override fun now() = now | ||
} | ||
|
||
@Test | ||
fun `should find what day it is in 2 days`() { | ||
val day = tp11.whichDayIsInTwoDays(clock) | ||
|
||
expectThat(day).isEqualTo(MONDAY) | ||
} | ||
|
||
@Test | ||
fun `should parse instant`() { | ||
val instant1 = tp11.parseInstant("16 novembre 85 à 11h00") | ||
val instant2 = tp11.parseInstant("16/11/85 à 11h00") | ||
|
||
val expected = LocalDateTime.parse("1985-11-16T11:00:00") | ||
expectThat(instant1).isEqualTo(expected) | ||
expectThat(instant2).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `should give days between`() { | ||
val days = tp11.daysBetween(now, Instant.parse("1986-02-21T11:00:00Z")) | ||
|
||
expectThat(days).isEqualTo(97) | ||
} | ||
} |