# HG changeset patch # User anatofuz # Date 1585765164 -32400 # Node ID 9b4d166e6a7e6d19b3624b3ef04b0ce4254dda31 # Parent cc568d791a2832818d60ed21f2579dfe38031a89 add util diff -r cc568d791a28 -r 9b4d166e6a7e util.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util.go Thu Apr 02 03:19:24 2020 +0900 @@ -0,0 +1,39 @@ +package lectable + +import ( + "os" + "path/filepath" + "strconv" + "time" + + "github.com/pkg/errors" +) + +//CreateGetSyllabus is constructor and initialize from now time +func guessOutputDir() string { + tm := time.Now() + year := tm.Year() + + var term string + + if tm.Month() < 7 { + term = "previous" + } else { + term = "latter" + } + + outputdir := filepath.Join(strconv.Itoa(year), term) + return outputdir +} + +//CheckAndMkdirBuilddir is builld 2019/early dir +func checkAndMkdirBuilddir(outputdir string) error { + if f, err := os.Stat(outputdir); os.IsNotExist(err) || !f.IsDir() { + err := os.MkdirAll(outputdir, 0755) + if err != nil { + return errors.Wrap(err, "failed mkdir") + } + return nil + } + return nil +}