From fa4e1dbeccc152800ffa108175ba52a0b230d702 Mon Sep 17 00:00:00 2001 From: jeff-knurek Date: Thu, 3 Dec 2020 12:33:48 +0800 Subject: [PATCH] add 30 minute 'lunch' when working for 6 hours (#9) --- pkg/reporting/increment.go | 4 ++++ pkg/reporting/increment_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/reporting/increment.go b/pkg/reporting/increment.go index 0f3e15e..0e7c9dc 100644 --- a/pkg/reporting/increment.go +++ b/pkg/reporting/increment.go @@ -44,6 +44,10 @@ func incrementTime(data Years, t time.Time) (Years, int) { if data[y] != nil { if data[y][m] != nil { cur = data[y][m][d] + 1 + // if worked 6 hours, add a 30 minute "lunch" + if cur == 361 { + cur += 30 + } data[y][m][d] = cur } else { data[y][m] = Days{d: 1} diff --git a/pkg/reporting/increment_test.go b/pkg/reporting/increment_test.go index f8ee1f6..780fbdb 100644 --- a/pkg/reporting/increment_test.go +++ b/pkg/reporting/increment_test.go @@ -46,6 +46,20 @@ func Test_incrementTime(t *testing.T) { want: Years{"2020": {"December": {"31": 487}}, "2021": {"January": {"1": 1}}}, wantMinutes: 1, }, + { + name: "30 minute lunch", + y: Years{"2020": {"December": {"31": 360}}}, + t: sameHour, + want: Years{"2020": {"December": {"31": 391}}}, + wantMinutes: 391, + }, + { + name: "30 minute lunch was missed", + y: Years{"2020": {"December": {"31": 361}}}, + t: sameHour, + want: Years{"2020": {"December": {"31": 362}}}, + wantMinutes: 362, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {