Kickoff
This commit is contained in:
parent
905858c795
commit
1fdc71d743
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -21,3 +21,5 @@
|
|||
# Go workspace file
|
||||
go.work
|
||||
|
||||
# resulting binary
|
||||
/woordklok
|
||||
|
|
5
Makefile
Normal file
5
Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
default: all
|
||||
all: woordklok
|
||||
|
||||
woordklok: woordklok.go
|
||||
go build -o $@ $^
|
77
woordklok.go
Normal file
77
woordklok.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Reference in a new issue