summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2024-11-28 23:56:54 +0100
committerÖzgür Kesim <oec@codeblau.de>2024-11-28 23:56:54 +0100
commitb2819fbcf4f96a29404ab24d4a38eba1e6380888 (patch)
treec30ba520a5d1d791dd76bd49ca1e615722111aca
parent19a162d481acdbe8140c4a3aada3a25d1ad1dbfc (diff)
added DaysRemaining
-rw-r--r--templates/report.t3
-rw-r--r--zeitgeist.go41
2 files changed, 40 insertions, 4 deletions
diff --git a/templates/report.t b/templates/report.t
index 1f6de14..39e2a19 100644
--- a/templates/report.t
+++ b/templates/report.t
@@ -12,7 +12,8 @@ Budgeted : {{ printf "%8s" $totals.Budgeted }}
Planned : {{ printf "%8s" $totals.Planned }}{{with $totals.Unaccounted}}
! Open !: {{ printf "%8s" . }}{{end}}
Done : {{ printf "%8s" $totals.Done }}{{ with $totals.Open }}
- ! Todo !: {{ printf "%8s" . }}{{end}}
+ ! Todo !: {{ printf "%8s" . }}
+Time left: {{ printf "%8s" ($p.AsDaysAmount (len $p.DaysRemaining)) }} * {{len $p.Users}}{{end}}
{{ range .ParallelWPTotals }}{{.}}
{{ end }}
diff --git a/zeitgeist.go b/zeitgeist.go
index c77b970..eb47ea6 100644
--- a/zeitgeist.go
+++ b/zeitgeist.go
@@ -171,6 +171,14 @@ func (d Date) Year() int {
return (time.Time(d)).Year()
}
+func (d Date) Month() int {
+ return int((time.Time(d)).Month())
+}
+
+func (d Date) Day() int {
+ return (time.Time(d)).Day()
+}
+
func (a Date) After(b Date) bool {
return (time.Time(a)).After(time.Time(b))
}
@@ -658,6 +666,18 @@ func (f *FullDate) Difference() Amount {
}
func (p *Project) Days(ymd ...int) []FullDate {
+ return p.days(false, ymd...)
+}
+
+func (p *Project) Workdays(ymd ...int) []FullDate {
+ return p.days(true, ymd...)
+}
+
+func (p *Project) AsDaysAmount(i int) Amount {
+ return Amount(i * HoursInDay)
+}
+
+func (p *Project) days(workonly bool, ymd ...int) []FullDate {
dates := []FullDate{}
start := time.Time(p.Start)
end := time.Time(p.End)
@@ -677,7 +697,7 @@ func (p *Project) Days(ymd ...int) []FullDate {
if month < 0 && day < 0 {
s := time.Date(year, time.January, 1, 0, 0, 0, 0, time.UTC)
- e := s.AddDate(1, 0, -1)
+ e := s.AddDate(1, 0, 0)
if s.Before(start) {
slog.Error("year out of range", "year", year)
return nil
@@ -688,7 +708,7 @@ func (p *Project) Days(ymd ...int) []FullDate {
}
} else if day < 0 {
s := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC)
- e := s.AddDate(0, 1, -1)
+ e := s.AddDate(0, 1, 0)
if s.Before(start) {
slog.Error("year and month out of range", "year", year, "month", month, "start", start, "s", s)
return nil
@@ -704,13 +724,24 @@ func (p *Project) Days(ymd ...int) []FullDate {
return nil
}
start = s
- end = s
}
}
for d := start; !d.Equal(end); d = d.AddDate(0, 0, 1) {
d := Date(d)
+ if workonly {
+ if !d.IsWorkday() {
+ continue
+ }
+ if _, ok := p.Holidays[d]; ok {
+ continue
+ }
+ if _, ok := p.Blocked[d]; ok {
+ continue
+ }
+ }
+
dates = append(dates,
FullDate{
Date: d,
@@ -981,3 +1012,7 @@ func (p *Project) ParallelWPTotals(tmpl ...string) ([]string, error) {
}
return renderParallel(content...), nil
}
+
+func (p *Project) DaysRemaining() []FullDate {
+ return p.Workdays(p.Today.Year(), p.Today.Month(), p.Today.Day())
+}