package main

import (
	"flag"
	"github.com/phss/fcal/calendar"
	"log"
	"strings"
	"time"
)

func main() {
	date := parseOptions()
	c := calendar.CalendarMonthFrom(date)
	calendar.PrintMonth(c)
}

func parseOptions() time.Time {
	format := "2006-01-02"

	var dateStr string
	flag.StringVar(&dateStr, "d", time.Now().Format(format), "ISO date of the day or month to be displayed")
	flag.Parse()

	if strings.Count(dateStr, "-") == 1 {
		format = "2006-01"
	}

	date, err := time.Parse(format, dateStr)

	if err != nil {
		log.Fatal(err)
	}

	return date
}

package main

import (
	"flag"
	"github.com/phss/fcal/calendar"
	"log"
	"time"
)

func main() {
	date := parseOptions()
	c := calendar.CalendarMonthFrom(date)
	calendar.PrintMonth(c)
}

func parseOptions() time.Time {
	var dateStr string
	flag.StringVar(&dateStr, "d", time.Now().Format("2006-01-02"), "ISO date of the day or month to be displayed")
	flag.Parse()

	date, err := time.Parse("2006-01-02", dateStr)

	if err != nil {
		log.Fatal(err)
	}

	return date
}

--- 
+++ 
@@ -4,6 +4,7 @@
 	"flag"
 	"github.com/phss/fcal/calendar"
 	"log"
+	"strings"
 	"time"
 )
 
@@ -14,11 +15,17 @@
 }
 
 func parseOptions() time.Time {
+	format := "2006-01-02"
+
 	var dateStr string
-	flag.StringVar(&dateStr, "d", time.Now().Format("2006-01-02"), "ISO date of the day or month to be displayed")
+	flag.StringVar(&dateStr, "d", time.Now().Format(format), "ISO date of the day or month to be displayed")
 	flag.Parse()
 
-	date, err := time.Parse("2006-01-02", dateStr)
+	if strings.Count(dateStr, "-") == 1 {
+		format = "2006-01"
+	}
+
+	date, err := time.Parse(format, dateStr)
 
 	if err != nil {
 		log.Fatal(err)
Allow date to be year and month
