package handler

import (
	"net/http"
	"net/url"
	"time"

	"github.com/yuuki/dynamond/log"
	"github.com/yuuki/dynamond/timeparser"
)

const (
	DAYTIME = time.Duration(24 * 60 * 60) * time.Second
)

func Render(w http.ResponseWriter, r *http.Request) {
	until := time.Now()
	from := until.Add(-DAYTIME)

	if v := r.FormValue("from"); v != "" {
		t, err := timeparser.ParseAtTime(url.QueryEscape(v))
		if err != nil {
			BadRequest(w, err.Error())
			return
		}
		from = t
	}
	if v := r.FormValue("until"); v != "" {
		t, err := timeparser.ParseAtTime(url.QueryEscape(v))
		if err != nil {
			BadRequest(w, err.Error())
			return
		}
		until = t
	}
	log.Debugf("from:%d until:%d", from.Unix(), until.Unix())

	return
}

package handler

import (
	"net/http"
	"time"

	"github.com/yuuki/dynamond/log"
	"github.com/yuuki/dynamond/timeparser"
)

const (
	DAYTIME = time.Duration(24 * 60 * 60) * time.Second
)

func Render(w http.ResponseWriter, r *http.Request) {
	until := time.Now()
	from := until.Add(-DAYTIME)

	if v := r.FormValue("from"); v != "" {
		t, err := timeparser.ParseAtTime(v)
		if err != nil {
			BadRequest(w, err.Error())
			return
		}
		from = t
	}
	if v := r.FormValue("until"); v != "" {
		t, err := timeparser.ParseAtTime(v)
		if err != nil {
			BadRequest(w, err.Error())
			return
		}
		until = t
	}
	log.Debugf("from:%d until:%d", from.Unix(), until.Unix())

	return
}

--- 
+++ 
@@ -2,6 +2,7 @@
 
 import (
 	"net/http"
+	"net/url"
 	"time"
 
 	"github.com/yuuki/dynamond/log"
@@ -17,7 +18,7 @@
 	from := until.Add(-DAYTIME)
 
 	if v := r.FormValue("from"); v != "" {
-		t, err := timeparser.ParseAtTime(v)
+		t, err := timeparser.ParseAtTime(url.QueryEscape(v))
 		if err != nil {
 			BadRequest(w, err.Error())
 			return
@@ -25,7 +26,7 @@
 		from = t
 	}
 	if v := r.FormValue("until"); v != "" {
-		t, err := timeparser.ParseAtTime(v)
+		t, err := timeparser.ParseAtTime(url.QueryEscape(v))
 		if err != nil {
 			BadRequest(w, err.Error())
 			return
Fix to parse 'now+1y' becase FormValue has already unescaped
