Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
19 changes: 4 additions & 15 deletions internal/cmd/youngutil/youngutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/Life-USTC/CLI/internal/cmd/cmdutil"
"github.com/Life-USTC/client-core/calendar"
)

const (
Expand Down Expand Up @@ -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) {
Expand All @@ -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")
}
Loading