From 3dc72e25dab6f1f32d6cc39ec33d5b87c10c44f7 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Wed, 6 Dec 2023 08:56:00 +0800 Subject: [PATCH] =?UTF-8?q?Add=20a=20template=20function=20about=20date=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=B8=80=E4=B8=AA=E6=97=A5=E6=9C=9F=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=A8=A1=E6=9D=BF=E5=87=BD=E6=95=B0=20(#9815?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update time.go 添加一个与日期相关的模板函数,有「星期天」了 * Update template.go 添加一个日期相关的模板函数 --- kernel/model/template.go | 2 ++ kernel/util/time.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/kernel/model/template.go b/kernel/model/template.go index d7674335511..e3978c5bfd3 100644 --- a/kernel/model/template.go +++ b/kernel/model/template.go @@ -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) @@ -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{", "}") diff --git a/kernel/util/time.go b/kernel/util/time.go index 33c7b030472..2b1258171b1 100644 --- a/kernel/util/time.go +++ b/kernel/util/time.go @@ -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.