mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
fix<Statistics>: fix getting current week commits
This commit is contained in:
parent
94ef2a9b69
commit
94bacb7384
1 changed files with 3 additions and 10 deletions
|
@ -41,8 +41,8 @@ namespace SourceGit.Views {
|
||||||
|
|
||||||
var mapCommitterWeek = new Dictionary<string, Models.StatisticSample>();
|
var mapCommitterWeek = new Dictionary<string, Models.StatisticSample>();
|
||||||
var mapCommitterMonth = new Dictionary<string, Models.StatisticSample>();
|
var mapCommitterMonth = new Dictionary<string, Models.StatisticSample>();
|
||||||
var week = today.DayOfWeek;
|
var weekStart = today.AddDays(-(int)today.DayOfWeek).AddSeconds(-today.Hour * 3600 - today.Minute * 60 - today.Second);
|
||||||
var month = today.Month;
|
var weekEnd = weekStart.AddDays(7);
|
||||||
|
|
||||||
var limits = $"--branches --remotes --since=\"{today.ToString("yyyy-MM-01 00:00:00")}\"";
|
var limits = $"--branches --remotes --since=\"{today.ToString("yyyy-MM-01 00:00:00")}\"";
|
||||||
var commits = new Commands.Commits(repo, limits).Result();
|
var commits = new Commands.Commits(repo, limits).Result();
|
||||||
|
@ -50,7 +50,7 @@ namespace SourceGit.Views {
|
||||||
var totalCommitsWeek = 0;
|
var totalCommitsWeek = 0;
|
||||||
foreach (var c in commits) {
|
foreach (var c in commits) {
|
||||||
var commitTime = DateTime.Parse(c.Committer.Time);
|
var commitTime = DateTime.Parse(c.Committer.Time);
|
||||||
if (IsSameWeek(today, commitTime)) {
|
if (commitTime.CompareTo(weekStart) >= 0 && commitTime.CompareTo(weekEnd) < 0) {
|
||||||
mapsWeek[(int)commitTime.DayOfWeek].Count++;
|
mapsWeek[(int)commitTime.DayOfWeek].Count++;
|
||||||
if (mapCommitterWeek.ContainsKey(c.Committer.Name)) {
|
if (mapCommitterWeek.ContainsKey(c.Committer.Name)) {
|
||||||
mapCommitterWeek[c.Committer.Name].Count++;
|
mapCommitterWeek[c.Committer.Name].Count++;
|
||||||
|
@ -108,12 +108,5 @@ namespace SourceGit.Views {
|
||||||
txtCommitCountMonth.Text = App.Text("Statistics.TotalCommitsCount", totalCommitsMonth);
|
txtCommitCountMonth.Text = App.Text("Statistics.TotalCommitsCount", totalCommitsMonth);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsSameWeek(DateTime t1, DateTime t2) {
|
|
||||||
double diffDay = t1.Subtract(t2).Duration().TotalDays;
|
|
||||||
if (diffDay >= 7) return false;
|
|
||||||
|
|
||||||
return t1.CompareTo(t2) > 0 ? (t1.DayOfWeek >= t2.DayOfWeek) : t1.DayOfWeek <= t2.DayOfWeek;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue