mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 New template functions ISOYear
, ISOMonth
and ISOWeekDate
https://github.com/siyuan-note/siyuan/issues/15679
This commit is contained in:
parent
174a7befbe
commit
6e985a5013
2 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue