summaryrefslogtreecommitdiff
path: root/zeitgeist.go
diff options
context:
space:
mode:
Diffstat (limited to 'zeitgeist.go')
-rw-r--r--zeitgeist.go41
1 files changed, 38 insertions, 3 deletions
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())
+}