@@ -28,7 +28,6 @@ import ( |
| 28 | 28 | ) |
| 29 | 29 | |
| 30 | 30 | const ( |
| 31 | | - profileContribWeeks = 53 |
| 32 | 31 | profileContribRepoLimit = 500 |
| 33 | 32 | profileContribMaxPerRepo = 5000 |
| 34 | 33 | profileReadmeMaxBytes = 1 * 1024 * 1024 |
@@ -211,7 +210,7 @@ func (h *Handlers) contributionCalendar(ctx context.Context, user usersdb.User, |
| 211 | 210 | windowEndDay = time.Date(selectedYear, time.December, 31, 0, 0, 0, 0, time.UTC) |
| 212 | 211 | period = "in " + strconv.Itoa(selectedYear) |
| 213 | 212 | } |
| 214 | | - gridStart := windowStart.AddDate(0, 0, -int(windowStart.Weekday())) |
| 213 | + gridStart, weekCount := contributionGrid(windowStart, windowEndDay) |
| 215 | 214 | windowEnd := windowEndDay.Add(24 * time.Hour) |
| 216 | 215 | activityMonth := time.Date(windowEndDay.Year(), windowEndDay.Month(), 1, 0, 0, 0, 0, time.UTC) |
| 217 | 216 | repos := h.profileContributionRepos(ctx, user, viewer, user.IncludePrivateContributions) |
@@ -254,13 +253,17 @@ func (h *Handlers) contributionCalendar(ctx context.Context, user usersdb.User, |
| 254 | 253 | } |
| 255 | 254 | } |
| 256 | 255 | |
| 257 | | - weeks := make([]contributionWeek, 0, profileContribWeeks) |
| 256 | + weeks := make([]contributionWeek, 0, weekCount) |
| 258 | 257 | total := 0 |
| 259 | 258 | monthCommitCount := 0 |
| 260 | | - for w := 0; w < profileContribWeeks; w++ { |
| 261 | | - week := contributionWeek{Days: make([]contributionDay, 0, 7)} |
| 259 | + for w := 0; w < weekCount; w++ { |
| 260 | + weekStart := gridStart.AddDate(0, 0, w*7) |
| 261 | + week := contributionWeek{ |
| 262 | + MonthLabel: contributionWeekMonthLabel(weekStart, w == 0), |
| 263 | + Days: make([]contributionDay, 0, 7), |
| 264 | + } |
| 262 | 265 | for d := 0; d < 7; d++ { |
| 263 | | - day := gridStart.AddDate(0, 0, w*7+d) |
| 266 | + day := weekStart.AddDate(0, 0, d) |
| 264 | 267 | key := day.Format("2006-01-02") |
| 265 | 268 | count := counts[key] |
| 266 | 269 | inWindow := !day.Before(windowStart) && !day.After(windowEndDay) |
@@ -270,9 +273,6 @@ func (h *Handlers) contributionCalendar(ctx context.Context, user usersdb.User, |
| 270 | 273 | monthCommitCount += count |
| 271 | 274 | } |
| 272 | 275 | } |
| 273 | | - if d == 0 && (day.Day() <= 7 || w == 0) { |
| 274 | | - week.MonthLabel = day.Format("Jan") |
| 275 | | - } |
| 276 | 276 | week.Days = append(week.Days, contributionDay{ |
| 277 | 277 | Date: key, |
| 278 | 278 | Title: contributionDayTitle(count, day), |
@@ -383,6 +383,29 @@ func selectedContributionYear(query url.Values, currentYear int) int { |
| 383 | 383 | return currentYear |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | +func contributionGrid(windowStart, windowEndDay time.Time) (time.Time, int) { |
| 387 | + gridStart := windowStart.AddDate(0, 0, -int(windowStart.Weekday())) |
| 388 | + gridEnd := windowEndDay.AddDate(0, 0, 6-int(windowEndDay.Weekday())) |
| 389 | + days := int(gridEnd.Sub(gridStart).Hours()/24) + 1 |
| 390 | + if days <= 0 { |
| 391 | + return gridStart, 0 |
| 392 | + } |
| 393 | + return gridStart, days / 7 |
| 394 | +} |
| 395 | + |
| 396 | +func contributionWeekMonthLabel(weekStart time.Time, firstWeek bool) string { |
| 397 | + for offset := 0; offset < 7; offset++ { |
| 398 | + day := weekStart.AddDate(0, 0, offset) |
| 399 | + if day.Day() == 1 { |
| 400 | + return day.Format("Jan") |
| 401 | + } |
| 402 | + } |
| 403 | + if firstWeek { |
| 404 | + return weekStart.Format("Jan") |
| 405 | + } |
| 406 | + return "" |
| 407 | +} |
| 408 | + |
| 386 | 409 | func contributionYears(username string, currentYear, selectedYear int) []contributionYear { |
| 387 | 410 | years := make([]contributionYear, 0, 4) |
| 388 | 411 | base := "/" + url.PathEscape(username) |