Skip to content

Instantly share code, notes, and snippets.

@Minikloon
Created August 1, 2017 07:50
Show Gist options
  • Save Minikloon/8d1822265b130124635eb12e9c549f2d to your computer and use it in GitHub Desktop.
Save Minikloon/8d1822265b130124635eb12e9c549f2d to your computer and use it in GitHub Desktop.
package net.minikloon.worktime
import edu.nyu.cs.javagit.api.DotGit
import edu.nyu.cs.javagit.api.commands.GitLogResponse
import java.text.SimpleDateFormat
import java.util.*
val gitDateFormat = SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z")
fun main(args: Array<String>) {
val git = DotGit.getInstance("Skywars")
val hoursOfDay = mutableMapOf<Int, Int>()
val cal = Calendar.getInstance()
git.log
.filter { commit -> commit.author.contains("Minikloon") && ageInDays(commit) < 60 }
.forEach { commit ->
cal.time = gitDateFormat.parse(commit.dateString)
val hourOfDay = cal.get(Calendar.HOUR_OF_DAY)
hoursOfDay.compute(hourOfDay) { k, v -> if (v == null) 1 else v + 1 }
}
for(i in 0..23) {
println("$i: ${hoursOfDay[i]}")
}
}
private fun ageInDays(commit: GitLogResponse.Commit) : Long {
return (System.currentTimeMillis() - gitDateFormat.parse(commit.dateString).time) / (1000 * 60 * 60 * 24)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment