mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 New template functions ISOYear
and ISOMonth
https://github.com/siyuan-note/siyuan/issues/15679
This commit is contained in:
parent
d445163b2f
commit
d684bb41b1
2 changed files with 17 additions and 0 deletions
|
@ -44,6 +44,8 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
|
|||
ret["WeekdayCN"] = util.WeekdayCN
|
||||
ret["WeekdayCN2"] = util.WeekdayCN2
|
||||
ret["ISOWeek"] = util.ISOWeek
|
||||
ret["ISOYear"] = util.ISOYear
|
||||
ret["ISOMonth"] = util.ISOMonth
|
||||
ret["pow"] = pow
|
||||
ret["powf"] = powf
|
||||
ret["log"] = log
|
||||
|
|
|
@ -62,6 +62,21 @@ func ISOWeek(date time.Time) int {
|
|||
return week
|
||||
}
|
||||
|
||||
// ISOYear returns the ISO 8601 year in which date occurs.
|
||||
func ISOYear(date time.Time) int {
|
||||
year, _ := date.ISOWeek()
|
||||
return year
|
||||
}
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
||||
func Millisecond2Time(t int64) time.Time {
|
||||
sec := t / 1000
|
||||
msec := t % 1000
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue