58 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package tpl
 | |
| 
 | |
| import (
 | |
| 	"html/template"
 | |
| 	"strings"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| func (r *render) Methods() map[string]any {
 | |
| 	res := make(map[string]any, 1)
 | |
| 
 | |
| 	res["dateFormat"] = func(dt time.Time) template.HTML {
 | |
| 		return template.HTML(dt.Format(time.DateTime))
 | |
| 	}
 | |
| 
 | |
| 	res["today"] = func() template.HTML {
 | |
| 		return template.HTML(time.Now().Format("2006-01-02"))
 | |
| 	}
 | |
| 
 | |
| 	res["threeMonth"] = func() template.HTML {
 | |
| 		return template.HTML(time.Now().AddDate(0, 3, 0).Format("2006-01-02"))
 | |
| 	}
 | |
| 
 | |
| 	res["yearBegin"] = func() template.HTML {
 | |
| 		dt := time.Now()
 | |
| 		t := dt.AddDate(0, -int(dt.Month())+1, -dt.Day()+1)
 | |
| 		return template.HTML(t.Format("2006-01-02") + " 00:00:00")
 | |
| 	}
 | |
| 
 | |
| 	res["monthBegin"] = func() template.HTML {
 | |
| 		dt := time.Now()
 | |
| 		t := dt.AddDate(0, 0, -dt.Day()+1)
 | |
| 		return template.HTML(t.Format("2006-01-02") + " 00:00:00")
 | |
| 	}
 | |
| 
 | |
| 	res["monthEnd"] = func() template.HTML {
 | |
| 		dt := time.Now()
 | |
| 		t := dt.AddDate(0, 0, -dt.Day()+1).AddDate(0, 1, -1)
 | |
| 		return template.HTML(t.Format("2006-01-02") + " 23:59:59")
 | |
| 	}
 | |
| 
 | |
| 	res["trimSpace"] = func(s string) template.HTML {
 | |
| 		return template.HTML(strings.TrimSpace(s))
 | |
| 	}
 | |
| 
 | |
| 	res["expandTags"] = func(s []string) template.HTML {
 | |
| 		if len(s) == 0 {
 | |
| 			return template.HTML("")
 | |
| 		}
 | |
| 		if len(s) == 1 && s[0] == "all" {
 | |
| 			return template.HTML("")
 | |
| 		}
 | |
| 		return template.HTML(strings.Join(s, ","))
 | |
| 	}
 | |
| 
 | |
| 	return res
 | |
| }
 |