From 1fdc71d7430ffed733e10bfea9598e05a7a12af9 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 20 Oct 2022 20:42:30 +0200 Subject: [PATCH] Kickoff --- .gitignore | 2 ++ Makefile | 5 ++++ woordklok.go | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 Makefile create mode 100644 woordklok.go diff --git a/.gitignore b/.gitignore index adf8f72..c3f2040 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ # Go workspace file go.work +# resulting binary +/woordklok diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c6b6bf --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +default: all +all: woordklok + +woordklok: woordklok.go + go build -o $@ $^ diff --git a/woordklok.go b/woordklok.go new file mode 100644 index 0000000..684807a --- /dev/null +++ b/woordklok.go @@ -0,0 +1,77 @@ +package main + +import ( + "fmt" + "strings" + "time" +) + +// Replace occurences of repl with their uppercase in str +func repl_upper(str string, repl []string) string { + ret := str + for _, r := range repl { + ret = strings.ReplaceAll(ret, r, strings.ToUpper(r)) + } + return ret +} + +func woordklok(tsp time.Time) string { + // minutes part + klok1 := "HETknISadvzvijftiengkwartbovervoormhalf" + // hours + klok2 := "yachtweezesdrielftienxzevenegenviertwaalfeenvijfuur" + + mm := tsp.Minute() + hh := tsp.Hour() % 12 + + // get the matching text + m := "uur" + if mm >= 55 { + m = "vijf voor" + } else if mm >= 50 { + m = "tien voor" + } else if mm >= 45 { + m = "kwart voor" + } else if mm >= 40 { + m = "tien over half" + } else if mm >= 35 { + m = "vijf over half" + } else if mm >= 30 { + m = "half" + } else if mm >= 25 { + m = "vijf voor half" + } else if mm >= 20 { + m = "tien voor half" + hh++ + } else if mm >= 15 { + m = "kwart over" + } else if mm >= 10 { + m = "tien over" + } else if mm >= 5 { + m = "vijf over" + } + + hours := []string{ + "twaalf", + "een", + "twee", + "drie", + "vier", + "vijf", + "zes", + "zeven", + "acht", + "negen", + "tien", + "elf", + } + hour := hours[hh] + + // and replace the matching text with the uppercase + return fmt.Sprintf("%s%s", repl_upper(klok1, strings.Split(m, " ")), repl_upper(klok2, strings.Split(hour, " "))) +} + +func main() { + woord := woordklok(time.Now()) + fmt.Println(woord) +}