diff --git a/go.mod b/go.mod index f9ed364..07a38cf 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/Life-USTC/CLI go 1.26.0 require ( + github.com/Life-USTC/client-core v0.1.0 github.com/PuerkitoBio/goquery v1.13.0 github.com/charmbracelet/bubbles v1.0.0 github.com/charmbracelet/bubbletea v1.3.10 diff --git a/go.sum b/go.sum index 9c5449a..a44c64b 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/Life-USTC/client-core v0.1.0 h1:kAtPq/m/W7SEMiR9KG/m2F0ZRyBXnzkNbfoKa4mMDmc= +github.com/Life-USTC/client-core v0.1.0/go.mod h1:2SgYKZ3hbEFEigNGPdbfFS2m149evVw2t/mEjA/S/LM= github.com/PuerkitoBio/goquery v1.13.0 h1:mqHbjD7Jmnul4DTR24LKTjo1uUmHUh072kteGV+xpFM= github.com/PuerkitoBio/goquery v1.13.0/go.mod h1:Hip5mdBL8K2wEGKJdr27sRaNwIdDajmCwB/ExUPwW+g= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= diff --git a/internal/cmd/youngutil/youngutil.go b/internal/cmd/youngutil/youngutil.go index 8d05091..0e7b8e9 100644 --- a/internal/cmd/youngutil/youngutil.go +++ b/internal/cmd/youngutil/youngutil.go @@ -11,6 +11,7 @@ import ( "time" "github.com/Life-USTC/CLI/internal/cmd/cmdutil" + "github.com/Life-USTC/client-core/calendar" ) const ( @@ -249,20 +250,12 @@ func DateRange(view DateView, anchor string, now time.Time) (string, string, err return "", "", err } switch view { - case DateDay: - formatted := formatDate(date) - return formatted, formatted, nil - case DateWeek: - offset := (int(date.Weekday()) + 6) % 7 - start := date.AddDate(0, 0, -offset) - return formatDate(start), formatDate(start.AddDate(0, 0, 6)), nil - case DateMonth: - start := time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, Shanghai) - end := start.AddDate(0, 1, -1) - return formatDate(start), formatDate(end), nil + case DateDay, DateWeek, DateMonth: default: return "", "", fmt.Errorf("unsupported date view %q", view) } + bounds, err := calendar.Bounds(calendar.Period(view), date, time.Monday) + return bounds.From, bounds.To, err } func anchorDate(anchor string, now time.Time) (time.Time, error) { @@ -276,7 +269,3 @@ func anchorDate(anchor string, now time.Time) (time.Time, error) { } return date, nil } - -func formatDate(date time.Time) string { - return date.In(Shanghai).Format("2006-01-02") -}