diff options
author | Özgür Kesim <oec@codeblau.de> | 2024-11-28 22:36:51 +0100 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2024-11-28 22:36:51 +0100 |
commit | 22c56dee9b9a1d68c15ba395b223cad2900a8ebf (patch) | |
tree | 68ed913eff692c53e0f7136dba78ca9ba654027a /zeitgeist.go | |
parent | 467933483cc53febf2ff57a6eaaae9e9b19095d6 (diff) |
fix formatting for amounts; better blocked/holiday
Diffstat (limited to 'zeitgeist.go')
-rw-r--r-- | zeitgeist.go | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/zeitgeist.go b/zeitgeist.go index 12299c8..c77b970 100644 --- a/zeitgeist.go +++ b/zeitgeist.go @@ -40,7 +40,7 @@ type Project struct { Planning string Workpackages map[string]Workpackage Holidays map[Date]string - Blocked Timeline + Blocked map[Date]string Timeline Timeline Planned Timeline Today Date @@ -184,7 +184,7 @@ const ( ) func (u Amount) String() string { - if u < 1 { + if u*u < 1 { return "0" } r := "" @@ -194,9 +194,18 @@ func (u Amount) String() string { if m != 0 { r = fmt.Sprintf("%dM", m) d -= DaysInMonth * m + if d < 0 { + d = -d + } + if h < 0 { + h = -h + } } if d != 0 { r += fmt.Sprintf("%dd", d) + if h < 0 { + h = -h + } } if h != 0 { r += fmt.Sprintf("%dh", h) @@ -524,9 +533,10 @@ func (p *Project) readTimelogs(dir string) error { defer f.Close() scanner := bufio.NewScanner(f) - nr := 1 + nr := 0 last := time.Time{} for scanner.Scan() { + nr += 1 // # Ignore line // # Tab-separated fields // 2024-12-11 wp2:short 8h [comment] @@ -535,7 +545,7 @@ func (p *Project) readTimelogs(dir string) error { continue } - parts := min2w.Split(scanner.Text(), 3) + parts := min2w.Split(scanner.Text(), 4) d, e := time.Parse(time.DateOnly, parts[0]) if e != nil { @@ -586,7 +596,6 @@ func (p *Project) readTimelogs(dir string) error { entries = append(entries, entry) p.Timeline[Date(d)] = entries - nr += 1 } } return nil @@ -626,7 +635,8 @@ type FullDate struct { Planned Entries Worked Entries IsWorkday bool - IsHoliday bool + Holiday string + Blocked string } func (fd *FullDate) IsWeekend() bool { @@ -638,6 +648,11 @@ func (p *Project) IsHoliday(d Date) bool { return ok } +func (p *Project) IsBlocked(d Date) bool { + _, ok := p.Blocked[d] + return ok +} + func (f *FullDate) Difference() Amount { return f.Planned.Total() - f.Worked.Total() } @@ -702,12 +717,20 @@ func (p *Project) Days(ymd ...int) []FullDate { Planned: p.Planned[d], Worked: p.Timeline[d], IsWorkday: d.IsWorkday(), - IsHoliday: p.IsHoliday(d), + Holiday: p.Holidays[d], + Blocked: p.Blocked[d], }) } return dates } +type FullDates []FullDate + +func (f *FullDates) FilterUser(user string) *FullDates { + // TODO + return f +} + func (p *Project) monthCal(year, month int) []string { /* 2 9 16 23 30 |