-
Notifications
You must be signed in to change notification settings - Fork 1
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
6 changed files
with
89 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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Dependencies.kotlincsv | ||
|
||
dependencies { | ||
implementation(kotlincsv) | ||
api(project(":domain")) | ||
} |
26 changes: 26 additions & 0 deletions
26
components/toggl/src/main/kotlin/com/agilogy/timetracking/toggl/TogglImporter.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,26 @@ | ||
package com.agilogy.timetracking.toggl | ||
|
||
import com.agilogy.timetracking.domain.ProjectName | ||
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader | ||
import java.io.InputStream | ||
import java.time.Duration | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.ZoneId | ||
import java.time.temporal.ChronoUnit | ||
|
||
fun readTogglCsv(inputStream: InputStream, zoneId: ZoneId): List<Triple<ProjectName, ClosedRange<Instant>, ZoneId>> = | ||
csvReader().readAllWithHeader(inputStream).map { row -> | ||
val projectName = ProjectName(row.getValue("Project")) | ||
val startDate = LocalDate.parse(row.getValue("Start date")) | ||
val startTime = LocalTime.parse(row.getValue("Start time")) | ||
val parsedDuration = LocalTime.parse(row.getValue("Duration")) | ||
|
||
val startInstant = LocalDateTime.of(startDate, startTime).atZone(zoneId).toInstant() | ||
|
||
val duration = Duration.of(parsedDuration.toSecondOfDay().toLong(), ChronoUnit.SECONDS)!! | ||
val range = startInstant..startInstant.plus(duration) | ||
Triple(projectName, range, zoneId) | ||
} |
49 changes: 49 additions & 0 deletions
49
components/toggl/src/test/kotlin/com/agilogy/timetracking/toggl/TogglTest.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,49 @@ | ||
package com.agilogy.timetracking.toggl | ||
|
||
import com.agilogy.timetracking.domain.ProjectName | ||
import io.kotest.core.spec.style.FunSpec | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import java.time.Instant | ||
import java.time.ZoneId | ||
|
||
class TogglTest : FunSpec() { | ||
init { | ||
test("TODO") { | ||
this::class.java.getResourceAsStream("/togglTimeEntries.csv").use { inputStream -> | ||
val zoneId = ZoneId.of("Europe/Madrid") | ||
val result: List<Triple<ProjectName, ClosedRange<Instant>, ZoneId>> = readTogglCsv( | ||
inputStream!!, | ||
zoneId, | ||
) | ||
val expected: List<Triple<ProjectName, ClosedRange<Instant>, ZoneId>> = listOf( | ||
Triple( | ||
ProjectName("ProjectA"), | ||
Instant.parse("2023-05-12T06:30:00Z")..Instant.parse("2023-05-12T14:30:00Z"), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectB"), | ||
Instant.parse("2023-05-15T06:30:00Z")..Instant.parse("2023-05-15T14:30:00Z"), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectA"), | ||
Instant.parse("2023-05-15T14:30:00Z")..Instant.parse("2023-05-15T16:30:00Z"), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectB"), | ||
Instant.parse("2023-05-16T06:30:00Z")..Instant.parse("2023-05-16T14:30:00Z"), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectB"), | ||
Instant.parse("2023-05-17T06:30:00Z")..Instant.parse("2023-05-17T14:30:00Z"), | ||
zoneId, | ||
), | ||
) | ||
assertEquals(expected, result) | ||
} | ||
} | ||
} | ||
} |
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,6 @@ | ||
User,Email,Client,Project,Task,Description,Billable,Start date,Start time,End date,End time,Duration,Tags,Amount () | ||
JohnDoe,[email protected],,ProjectA,,"",No,2023-05-12,08:30:00,2023-05-12,16:30:00,08:00:00,, | ||
JohnDoe,[email protected],,ProjectB,,"",No,2023-05-15,08:30:00,2023-05-15,16:30:00,08:00:00,, | ||
JohnDoe,[email protected],,ProjectA,,"",No,2023-05-15,16:30:00,2023-05-15,18:30:00,02:00:00,, | ||
JohnDoe,[email protected],,ProjectB,,"",No,2023-05-16,08:30:00,2023-05-16,16:30:00,08:00:00,, | ||
JohnDoe,[email protected],,ProjectB,,"",No,2023-05-17,08:30:00,2023-05-17,16:30:00,08:00:00,, |