-
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
1 parent
b11cfe6
commit 7d35d2f
Showing
4 changed files
with
78 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,6 @@ | ||
import Dependencies.kotlincsv | ||
|
||
dependencies { | ||
implementation(kotlincsv) | ||
api(project(":domain")) | ||
} |
17 changes: 17 additions & 0 deletions
17
components/tyme/src/main/kotlin/com/agilogy/timetracking/toggl/TymeImporter.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,17 @@ | ||
package com.agilogy.timetracking.toggl | ||
|
||
import com.agilogy.timetracking.domain.ProjectName | ||
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader | ||
import java.io.InputStream | ||
import java.lang.Long.parseLong | ||
import java.time.Instant | ||
import java.time.ZoneId | ||
|
||
fun readTymeCsv(inputStream: InputStream, zoneId: ZoneId): List<Triple<ProjectName, ClosedRange<Instant>, ZoneId>> = | ||
csvReader { delimiter = ';' }.readAllWithHeader(inputStream).map { row -> | ||
val projectName = ProjectName(row.getValue("project")) | ||
val unixStart = parseLong(row.getValue("unix_start")) | ||
val unixEnd = parseLong(row.getValue("unix_end")) | ||
val range = Instant.ofEpochSecond(unixStart)..Instant.ofEpochSecond(unixEnd) | ||
Triple(projectName, range, zoneId) | ||
} |
49 changes: 49 additions & 0 deletions
49
components/tyme/src/test/kotlin/com/agilogy/timetracking/toggl/TymeTest.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 TymeTest : FunSpec() { | ||
init { | ||
test("Parse the export CSV file generated by TymeApp") { | ||
this::class.java.getResourceAsStream("/tyme_20230601-20230630.csv").use { inputStream -> | ||
val zoneId = ZoneId.of("Europe/Madrid") | ||
val result: List<Triple<ProjectName, ClosedRange<Instant>, ZoneId>> = readTymeCsv( | ||
inputStream!!, | ||
zoneId, | ||
) | ||
val expected: List<Triple<ProjectName, ClosedRange<Instant>, ZoneId>> = listOf( | ||
Triple( | ||
ProjectName("ProjectA"), | ||
Instant.ofEpochSecond(1685603340)..Instant.ofEpochSecond(1685622300), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectA"), | ||
Instant.ofEpochSecond(1685625655)..Instant.ofEpochSecond(1685635185), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectA"), | ||
Instant.ofEpochSecond(1685689440)..Instant.ofEpochSecond(1685693700), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectB"), | ||
Instant.ofEpochSecond(1685693700)..Instant.ofEpochSecond(1685709000), | ||
zoneId, | ||
), | ||
Triple( | ||
ProjectName("ProjectB"), | ||
Instant.ofEpochSecond(1685710800)..Instant.ofEpochSecond(1685712666), | ||
zoneId, | ||
), | ||
) | ||
assertEquals(expected, result) | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
components/tyme/src/test/resources/tyme_20230601-20230630.csv
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 @@ | ||
type;date;unix_start;unix_end;day;start;end;category;project;task;subtask;amount;amount_decimal;rate;sum;rounding_minutes;rounding_method;note | ||
timed;1/6/23;1685603340;1685622300;Thursday;09:09;14:25;;ProjectA;TaskA1;;05:16;5,26666667;;;1;NEAREST;"" | ||
timed;1/6/23;1685625655;1685635185;Thursday;15:20;17:59;;ProjectA;TaskA2;;02:39;2,65;;;1;NEAREST;"" | ||
timed;2/6/23;1685689440;1685693700;Friday;09:04;10:15;;ProjectA;TaskA1;;01:11;1,18333333;;;1;NEAREST;"" | ||
timed;2/6/23;1685693700;1685709000;Friday;10:15;14:30;;ProjectB;TaskB1;;04:15;4,25;;;1;NEAREST;"" | ||
timed;2/6/23;1685710800;1685712666;Friday;15:00;15:31;;ProjectB;TaskB2;;00:31;0,51666667;;;1;NEAREST;"" |