Skip to content

Commit

Permalink
Parse Tyme app time entries
Browse files Browse the repository at this point in the history
  • Loading branch information
agile-jordi committed Jun 2, 2023
1 parent b11cfe6 commit 7d35d2f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/tyme/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Dependencies.kotlincsv

dependencies {
implementation(kotlincsv)
api(project(":domain"))
}
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)
}
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 components/tyme/src/test/resources/tyme_20230601-20230630.csv
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;""

0 comments on commit 7d35d2f

Please sign in to comment.