Implement "First day is monday" and "Only show work days" properties.
parent
3c93de7789
commit
f432c5424a
|
@ -3,7 +3,9 @@ package latex
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jinzhu/now"
|
||||||
"github.com/nicksnyder/go-i18n/i18n"
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
|
||||||
"git.dekart811.net/icedream/workreportmgr/project"
|
"git.dekart811.net/icedream/workreportmgr/project"
|
||||||
|
@ -32,8 +34,27 @@ func (e *Exporter) Export(prj *project.Project, w io.Writer) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exportTemplate.Funcs(template.FuncMap{
|
now.FirstDayMonday = prj.FirstDayMonday
|
||||||
|
|
||||||
|
exportTemplate = exportTemplate.Funcs(template.FuncMap{
|
||||||
"T": T,
|
"T": T,
|
||||||
|
"beginofweek": func(date project.Date) project.Date {
|
||||||
|
day := now.New(date.Time).BeginningOfWeek()
|
||||||
|
if prj.OnlyShowWorkDays && !now.FirstDayMonday {
|
||||||
|
day = day.Add(time.Hour * 24)
|
||||||
|
}
|
||||||
|
return project.Date{Time: day}
|
||||||
|
},
|
||||||
|
"endofweek": func(date project.Date) project.Date {
|
||||||
|
day := now.New(date.Time).EndOfWeek()
|
||||||
|
if prj.OnlyShowWorkDays {
|
||||||
|
day = day.Add(time.Hour * -24)
|
||||||
|
if now.FirstDayMonday {
|
||||||
|
day = day.Add(time.Hour * -24)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return project.Date{Time: day}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
|
|
|
@ -17,16 +17,16 @@ var exportTemplate = template.Must(template.
|
||||||
New("latex_export").
|
New("latex_export").
|
||||||
Funcs(template.FuncMap{
|
Funcs(template.FuncMap{
|
||||||
"T": i18n.IdentityTfunc,
|
"T": i18n.IdentityTfunc,
|
||||||
|
"beginofweek": func(date project.Date) project.Date {
|
||||||
|
return project.Date{Time: now.New(date.Time).BeginningOfWeek()}
|
||||||
|
},
|
||||||
|
"endofweek": func(date project.Date) project.Date {
|
||||||
|
return project.Date{Time: now.New(date.Time).EndOfWeek()}
|
||||||
|
},
|
||||||
"escape": stringutil.TexEscape,
|
"escape": stringutil.TexEscape,
|
||||||
"add": func(a, b int) int {
|
"add": func(a, b int) int {
|
||||||
return a + b
|
return a + b
|
||||||
},
|
},
|
||||||
"beginofweek": func(date project.Date) project.Date {
|
|
||||||
return project.Date{now.New(date.Time).BeginningOfWeek()}
|
|
||||||
},
|
|
||||||
"endofweek": func(date project.Date) project.Date {
|
|
||||||
return project.Date{now.New(date.Time).EndOfWeek()}
|
|
||||||
},
|
|
||||||
}).
|
}).
|
||||||
Delims("<", ">").
|
Delims("<", ">").
|
||||||
Parse(`% !TeX
|
Parse(`% !TeX
|
||||||
|
|
|
@ -4,6 +4,8 @@ package project
|
||||||
type Project struct {
|
type Project struct {
|
||||||
Name string `json:"Name"`
|
Name string `json:"Name"`
|
||||||
Department string `json:"Department"`
|
Department string `json:"Department"`
|
||||||
|
FirstDayMonday bool `json:"First day is monday"`
|
||||||
|
OnlyShowWorkDays bool `json:"Only show work days"`
|
||||||
Begin Date `json:"Begin"`
|
Begin Date `json:"Begin"`
|
||||||
End Date `json:"End"`
|
End Date `json:"End"`
|
||||||
Weeks []Week `json:"Weeks"`
|
Weeks []Week `json:"Weeks"`
|
||||||
|
|
Loading…
Reference in New Issue