Files
tiennm99 1763422570 feat(card): configurable start of week (#25)
* feat(card): configurable start of week for heatmap + weekday cards

New -start-of-week CLI flag (and start_of_week action input) rotates the
contribution-heatmap rows and the productive-weekday bars so users whose
calendars start on Monday (or any other day) get matching output. Default
stays Sunday to preserve existing renders.

* docs: note start-of-week in design-guidelines, codebase-summary, deployment-guide

- design-guidelines: heatmap row order + productive-weekday bar order now derive from Profile.WeekStart
- codebase-summary: list new weekday_start_test.go cases + TestParseWeekday
- deployment-guide: mention start_of_week as an optional action input in the workflow template
2026-04-21 20:57:21 +07:00

61 lines
1.5 KiB
Go

package main
import (
"strings"
"testing"
"time"
)
// TestParseWeekday covers the common case-insensitive inputs and confirms
// an unknown value errors (main.go then falls back to Sunday with a warn).
func TestParseWeekday(t *testing.T) {
ok := []struct {
in string
want time.Weekday
}{
{"", time.Sunday},
{"sunday", time.Sunday},
{"SUNDAY", time.Sunday},
{"Sun", time.Sunday},
{" monday ", time.Monday},
{"Mon", time.Monday},
{"saturday", time.Saturday},
}
for _, c := range ok {
got, err := parseWeekday(c.in)
if err != nil {
t.Errorf("parseWeekday(%q) err=%v", c.in, err)
}
if got != c.want {
t.Errorf("parseWeekday(%q)=%v want %v", c.in, got, c.want)
}
}
if _, err := parseWeekday("moonday"); err == nil {
t.Error("parseWeekday(moonday): want error, got nil")
}
}
// TestUTCOffsetLabel checks the compact format: integer hours drop the
// minutes suffix, non-zero offsets render as `UTC±H:MM`.
func TestUTCOffsetLabel(t *testing.T) {
cases := []struct {
zone string
want string // must appear in the label; exact value varies by DST
}{
{"UTC", "UTC+0"},
{"Asia/Saigon", "UTC+7"},
{"Asia/Kolkata", "UTC+5:30"}, // half-hour zone
{"Asia/Kathmandu", "UTC+5:45"}, // quarter-hour zone
}
for _, tc := range cases {
loc, err := time.LoadLocation(tc.zone)
if err != nil {
t.Skipf("%s unavailable: %v", tc.zone, err)
}
got := utcOffsetLabel(loc)
if !strings.Contains(got, tc.want) {
t.Errorf("utcOffsetLabel(%q) = %q, want prefix %q", tc.zone, got, tc.want)
}
}
}