Created
August 1, 2017 07:50
-
-
Save Minikloon/8d1822265b130124635eb12e9c549f2d to your computer and use it in GitHub Desktop.
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
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