1
0
Fork 0
mirror of https://github.com/vbatts/freezing-octo-hipster.git synced 2024-11-26 08:45:40 +00:00
random-utils/cmd/next-note/main.go

43 lines
936 B
Go
Raw Normal View History

2014-07-02 19:02:56 +00:00
package main
import (
"flag"
"fmt"
"path"
"time"
)
var (
flDir = flag.String("dir", "", "Base directory for tasks")
flDate = flag.Bool("d", false, "print current date")
flPrevWeek = flag.Bool("p", false, "print previous week's filename")
flCurrWeek = flag.Bool("c", false, "print current week's filename")
)
var FileDate = "20060102"
func main() {
flag.Parse()
if *flDate {
2014-07-02 19:12:49 +00:00
// this intentionally has no '\n'
fmt.Printf("## %s", time.Now().Format(time.UnixDate))
2014-07-02 19:02:56 +00:00
return
}
var sunday int
2014-07-02 19:02:56 +00:00
t := time.Now()
if *flCurrWeek {
sunday = -1 * int(t.Weekday())
2014-07-02 19:02:56 +00:00
} else if *flPrevWeek {
sunday = -1*int(t.Weekday()) - 7
2014-07-02 19:02:56 +00:00
} else {
sunday = -1*int(t.Weekday()) + 7
2014-07-02 19:02:56 +00:00
}
saturday := sunday + 6
startDate := t.AddDate(0, 0, sunday).Format(FileDate)
endDate := t.AddDate(0, 0, saturday).Format(FileDate)
filename := fmt.Sprintf("Tasks-%s-%s.md", startDate, endDate)
2014-07-02 19:02:56 +00:00
fmt.Println(path.Join(*flDir, filename))
}