Skip to content

Commit 9125e34

Browse files
ctruchiCLOVIS-AI
authored andcommitted
tp11 solution
1 parent 8a24786 commit 9125e34

File tree

1 file changed

+30
-5
lines changed
  • tp11/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+30
-5
lines changed

tp11/src/main/kotlin/fmt/kotlin/fundamentals/Tp11.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
package fmt.kotlin.fundamentals
22

33
import kotlinx.datetime.*
4+
import kotlinx.datetime.DateTimeUnit.Companion.DAY
45
import kotlinx.datetime.format.MonthNames
56
import kotlinx.datetime.format.alternativeParsing
67
import kotlinx.datetime.format.char
7-
import kotlin.time.Duration.Companion.days
8+
import kotlin.time.Duration.Companion.hours
89

910
class Tp11 {
1011

11-
fun whichDayIsIn48h(clock: Clock): DayOfWeek = TODO()
12+
fun whichDayIsIn48h(clock: Clock) = (clock.now() + 48.hours)
13+
.toLocalDateTime(TimeZone.of("Europe/Paris"))
14+
.dayOfWeek
1215

13-
fun whichDayIsInTwoDays(clock: Clock): DayOfWeek = TODO()
16+
fun whichDayIsInTwoDays(clock: Clock) = clock.now()
17+
.toLocalDateTime(TimeZone.of("Europe/Paris"))
18+
.date
19+
.plus(2, DAY)
20+
.dayOfWeek
1421

15-
fun parseInstant(s: String): LocalDateTime = TODO()
22+
fun parseInstant(s: String) =
23+
LocalDateTime.Format {
24+
dayOfMonth()
25+
alternativeParsing({
26+
char('/')
27+
monthNumber()
28+
char('/')
29+
}) {
30+
char(' ')
31+
monthName(frenchMonthNames)
32+
char(' ')
33+
}
34+
yearTwoDigits(1900)
35+
chars(" à ")
36+
hour()
37+
char('h')
38+
minute()
39+
}.parse(s)
1640

17-
fun daysBetween(instant1: Instant, instant2: Instant): Long = TODO()
41+
fun daysBetween(instant1: Instant, instant2: Instant) =
42+
(instant2 - instant1).inWholeDays
1843

1944
companion object {
2045
private val frenchMonthNames = MonthNames(

0 commit comments

Comments
 (0)