first commit
This commit is contained in:
48
cmd/ISOWeek/ISOWeek.go
Normal file
48
cmd/ISOWeek/ISOWeek.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
|
||||
Waarom?
|
||||
|
||||
We willen year-week, bijvoorbeeld 2025-52
|
||||
|
||||
Als de datum 1 januari 2027 is, dan geeft dit:
|
||||
|
||||
date +%Y-%V
|
||||
|
||||
... dit:
|
||||
|
||||
2027-53
|
||||
|
||||
Dat is fout. Het moet zijn:
|
||||
|
||||
2026-53
|
||||
|
||||
Dit programma geeft wel de juiste uitvoer.
|
||||
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/pebbe/util"
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
x = util.CheckErr
|
||||
)
|
||||
|
||||
func main() {
|
||||
// arg 1: aantal dagen opgeteld bij huidige datum
|
||||
d, err := strconv.Atoi(os.Args[1])
|
||||
x(err)
|
||||
|
||||
location, err := time.LoadLocation("Europe/Amsterdam")
|
||||
x(err)
|
||||
|
||||
year, week := time.Now().AddDate(0, 0, d).In(location).ISOWeek()
|
||||
fmt.Printf("%d-%02d\n", year, week)
|
||||
}
|
||||
Reference in New Issue
Block a user