works
This commit is contained in:
parent
a59a870d7c
commit
7520f1d57d
3
go.mod
Normal file
3
go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module git.schreifuchs.ch/schreifuchs/worktime
|
||||
|
||||
go 1.22.5
|
47
main.go
Normal file
47
main.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultFormat = "15:04"
|
||||
defaultGoal = "8.3h"
|
||||
)
|
||||
|
||||
func main() {
|
||||
format := flag.String("f", defaultFormat, "Set the input time format ")
|
||||
goalS := flag.String("g", defaultGoal, "Set the duration goal ")
|
||||
flag.Parse()
|
||||
|
||||
goal, err := time.ParseDuration(*goalS)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing \"%s\": %v", *goalS, err)
|
||||
eight := 8.3 * float64(time.Hour)
|
||||
goal = time.Duration(eight)
|
||||
}
|
||||
|
||||
acc := time.Second * 0
|
||||
for i, arg := range flag.Args() {
|
||||
t, err := time.Parse(*format, arg)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing \"%s\": %v", arg, err)
|
||||
continue
|
||||
}
|
||||
dur := time.Hour*time.Duration(t.Hour()) + time.Minute*time.Duration(t.Minute())
|
||||
|
||||
if i%2 == 0 {
|
||||
acc -= dur
|
||||
} else {
|
||||
acc += dur
|
||||
}
|
||||
}
|
||||
if len(flag.Args())%2 != 0 {
|
||||
diff := goal - acc
|
||||
fmt.Printf("You reached your goal of %v at: %s\n", goal, time.Time{}.Add(diff).Format(*format))
|
||||
} else {
|
||||
fmt.Printf("With these hour's you have worked: %v\n", acc)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user