Last active
May 1, 2016 23:58
-
-
Save smagch/75a913ca69a241aea86d9beaacac45a2 to your computer and use it in GitHub Desktop.
伝助データジェネレーター
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
) | |
var ( | |
dateStart = "2016-05-02" | |
dateEnd = "2016-07-01" | |
layout = "2006-01-02" | |
kanjiMap = map[time.Weekday]string{ | |
time.Saturday: "土", | |
time.Sunday: "日", | |
} | |
times = []string{ | |
"午前", | |
"午後", | |
} | |
) | |
type timeSpan struct { | |
start, end time.Time | |
} | |
func parseTime(s string, t *time.Time) { | |
var err error | |
*t, err = time.Parse(layout, s) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
func main() { | |
span := timeSpan{} | |
parseTime(dateStart, &span.start) | |
parseTime(dateEnd, &span.end) | |
for d := span.start; d.Before(span.end); d = d.AddDate(0, 0, 1) { | |
w := d.Weekday() | |
kanji, ok := kanjiMap[w] | |
if !ok { | |
continue | |
} | |
s := d.Format("2006/01/02") | |
p := fmt.Sprintf("%s (%s)", s, kanji) | |
for _, t := range times { | |
fmt.Printf("%s %s\n", p, t) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment