Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a template function about date #9815

Merged
merged 2 commits into from
Dec 6, 2023
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
2 changes: 2 additions & 0 deletions kernel/model/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func RenderGoTemplate(templateContent string) (ret string, err error) {
tmpl = tmpl.Funcs(template.FuncMap{
"Weekday": util.Weekday,
"WeekdayCN": util.WeekdayCN,
"WeekdayCN2": util.WeekdayCN2,
"ISOWeek": util.ISOWeek,
})
tpl, err := tmpl.Parse(templateContent)
Expand Down Expand Up @@ -249,6 +250,7 @@ func renderTemplate(p, id string, preview bool) (string, error) {
}
funcMap["Weekday"] = util.Weekday
funcMap["WeekdayCN"] = util.WeekdayCN
funcMap["WeekdayCN2"] = util.WeekdayCN2
funcMap["ISOWeek"] = util.ISOWeek

goTpl := template.New("").Delims(".action{", "}")
Expand Down
8 changes: 8 additions & 0 deletions kernel/util/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ func WeekdayCN(date time.Time) string {
return weekdayCN[week]
}

// WeekdayCN2 returns the day of the week specified by date.
// Sunday=天, Monday=一, ..., Saturday=六.
func WeekdayCN2(date time.Time) string {
week := Weekday(date)
weekdayCN2 := []string{"天", "一", "二", "三", "四", "五", "六"}
return weekdayCN2[week]
}

// ISOWeek returns the ISO 8601 year and week number in which date occurs.
// Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to week 52 or 53 of year n-1,
// and Dec 29 to Dec 31 might belong to week 1 of year n+1.
Expand Down
Loading