Skip to content

Instantly share code, notes, and snippets.

@deadcheat
Created March 4, 2017 18:55
Show Gist options
  • Save deadcheat/d6c93b6e8ade8dbcf70c93eb09b4ac20 to your computer and use it in GitHub Desktop.
Save deadcheat/d6c93b6e8ade8dbcf70c93eb09b4ac20 to your computer and use it in GitHub Desktop.
なんか雑に書いた、与えられた年月の一月分を回すぜ.go
package main
import (
"flag"
"os"
"time"
"github.com/k0kubun/pp"
)
func main() {
var month string
flag.StringVar(&month, "m", "", "base month")
flag.Parse()
var base time.Time
var err error
lo := "200601"
if len(month) > 0 {
base, err = time.Parse(lo, month)
if err != nil {
os.Exit(1)
}
} else {
base = time.Now()
}
by, bm, _ := base.Date()
fd := time.Date(by, bm, 1, 0, 0, 0, 0, time.UTC)
ld := fd.AddDate(0, 1, -1)
spec := fd
for index := 0; index < ld.Day(); index++ {
pp.Println(spec, spec.Unix(), spec.UnixNano())
next := spec.AddDate(0, 0, 1)
spec = next
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment