Skip to content

Instantly share code, notes, and snippets.

@mizukmb
Created March 7, 2015 19:22
Show Gist options
  • Save mizukmb/22cb922eac7dfdb87f2d to your computer and use it in GitHub Desktop.
Save mizukmb/22cb922eac7dfdb87f2d to your computer and use it in GitHub Desktop.
13日の金曜日をjson形式で出力します
package main
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
)
type Jason struct {
Year int
Month []int
}
func yobi(year int, month int) (int, error) {
if year < 0 {
return 0, errors.New("input error!!")
}
if month == 1 || month == 2 {
year -= 1
month += 12
}
return (year + year/4 - year/100 + year/400 + (13*month+8)/5 + 1) % 7, nil
}
func EncodingJSON(jason Jason) []byte {
bdata, err := json.Marshal(jason)
if err != nil {
fmt.Println(err)
return nil
}
return bdata
}
func main() {
var (
year int
pyobi int
jasonMonth []int
err error
)
fmt.Printf("Please, input year.->")
fmt.Scan(&year)
for month := 1; month <= 12; month++ {
pyobi, err = yobi(year, month)
if err != nil {
fmt.Println(err)
return
}
if pyobi == 0 {
jasonMonth = append(jasonMonth, month)
}
}
jason := Jason{year, jasonMonth}
bdata := EncodingJSON(jason)
os.Stdout.Write(bdata)
content := []byte(bdata)
ioutil.WriteFile("jason.json", content, os.ModePerm)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment