Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: New template functions `ISOYear` and `ISOMonth` https://github.com/siyuan-note/siyuan/issues/15679

Daniel1bc68efd3a8b
diff --git a/kernel/util/time.go b/kernel/util/time.go
index 5a49b88d69..b131865164 100644
--- a/kernel/util/time.go
+++ b/kernel/util/time.go
@@ -70,11 +70,14 @@ func ISOYear(date time.Time) int {
// ISOMonth returns the month in which the first day of the ISO 8601 week of date occurs.
func ISOMonth(date time.Time) int {
- year, week := date.ISOWeek()
- // ISO 8601 week starts from Monday
- isoWeekStart := time.Date(year, 0, (week-1)*7+
- 1-(int(time.Date(year, 0, (week-1)*7+1, 0, 0, 0, 0, time.Local).Weekday())+6)%7, 0, 0, 0, 0, time.Local)
- return int(isoWeekStart.Month())
+ weekday := int(date.Weekday())
+ if weekday == 0 {
+ weekday = 7
+ }
+
+ daysToMonday := weekday - 1
+ monday := date.AddDate(0, 0, -daysToMonday)
+ return int(monday.Month())
}
func Millisecond2Time(t int64) time.Time {