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

This commit is contained in:
Daniel 2025-08-27 10:17:50 +08:00
parent dcefed26eb
commit 1bc68efd3a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -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. // ISOMonth returns the month in which the first day of the ISO 8601 week of date occurs.
func ISOMonth(date time.Time) int { func ISOMonth(date time.Time) int {
year, week := date.ISOWeek() weekday := int(date.Weekday())
// ISO 8601 week starts from Monday if weekday == 0 {
isoWeekStart := time.Date(year, 0, (week-1)*7+ weekday = 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())
daysToMonday := weekday - 1
monday := date.AddDate(0, 0, -daysToMonday)
return int(monday.Month())
} }
func Millisecond2Time(t int64) time.Time { func Millisecond2Time(t int64) time.Time {