From 6e985a5013eb1d30d5cfcc0b362073077b024cce Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Aug 2025 16:51:25 +0800 Subject: [PATCH] :art: New template functions `ISOYear`, `ISOMonth` and `ISOWeekDate` https://github.com/siyuan-note/siyuan/issues/15679 --- kernel/filesys/template.go | 1 + kernel/util/time.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/kernel/filesys/template.go b/kernel/filesys/template.go index 3184da077..2e22f416e 100644 --- a/kernel/filesys/template.go +++ b/kernel/filesys/template.go @@ -46,6 +46,7 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) { ret["ISOWeek"] = util.ISOWeek ret["ISOYear"] = util.ISOYear ret["ISOMonth"] = util.ISOMonth + ret["ISOWeekDate"] = util.ISOWeekDate ret["pow"] = pow ret["powf"] = powf ret["log"] = log diff --git a/kernel/util/time.go b/kernel/util/time.go index b13186516..933e88084 100644 --- a/kernel/util/time.go +++ b/kernel/util/time.go @@ -80,6 +80,19 @@ func ISOMonth(date time.Time) int { return int(monday.Month()) } +// ISOWeekDate returns the date of the specified day of the week in the ISO 8601 week of date. +// day: Monday=1, ..., Sunday=7. +func ISOWeekDate(date time.Time, day int) time.Time { + weekday := int(date.Weekday()) + if weekday == 0 { + weekday = 7 + } + + daysToMonday := weekday - 1 + monday := date.AddDate(0, 0, -daysToMonday) + return monday.AddDate(0, 0, day-1) +} + func Millisecond2Time(t int64) time.Time { sec := t / 1000 msec := t % 1000