weekadd
This commit is contained in:
50
cmd/weekadd/weekadd.go
Normal file
50
cmd/weekadd/weekadd.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
ww "git.web.rug.nl/p209327/nlnieuws/internal/week"
|
||||
|
||||
e "codeberg.org/pebbe/errors"
|
||||
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
x = e.ExitErr
|
||||
)
|
||||
|
||||
func syntax(w io.Writer) {
|
||||
fmt.Fprintf(w, `
|
||||
Usage: %s yyyy.ww n
|
||||
|
||||
`, os.Args[0])
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
syntax(os.Stdout)
|
||||
return
|
||||
}
|
||||
|
||||
aa := strings.Split(os.Args[1], ".")
|
||||
if len(aa) != 2 {
|
||||
syntax(os.Stderr)
|
||||
return
|
||||
}
|
||||
year, err := strconv.Atoi(aa[0])
|
||||
x(err)
|
||||
week, err := strconv.Atoi(aa[1])
|
||||
x(err)
|
||||
|
||||
n, err := strconv.Atoi(os.Args[2])
|
||||
x(err)
|
||||
|
||||
t, err := ww.WeekDate(year, week)
|
||||
x(err)
|
||||
|
||||
y, w := t.AddDate(0, 0, n*7).ISOWeek()
|
||||
fmt.Printf("%d.%02d\n", y, w)
|
||||
}
|
||||
Reference in New Issue
Block a user