package param

import (
	"fmt"
	"strings"
	"time"
)

type Date struct {
	time.Time
}

func (t Date) MarshalJSON() ([]byte, error) {
	date := t.Time.Format("2006-01-02")
	fmt.Println(date)
	date = fmt.Sprintf(`"%s"`, date)
	return []byte(date), nil
}

func (t *Date) UnmarshalJSON(b []byte) (err error) {
	s := strings.Trim(string(b), "\"")

	date, err := time.Parse("2006-01-02", s)
	if err != nil {
		return err
	}
	t.Time = date
	return
}
