Skip to content
Snippets Groups Projects
Commit a9881930 authored by jrabbit's avatar jrabbit
Browse files

improve alarm handling

parent 7f884010
Branches
Tags
No related merge requests found
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
func Version() string { func Version() string {
return "0.0.1a4" return "0.0.1a4"
} }
var CurrentTimers []Timer var CurrentTimers []Timer
var CurrentAlarms map[string]Alarm var CurrentAlarms map[string]Alarm
...@@ -19,7 +18,6 @@ func Init() { ...@@ -19,7 +18,6 @@ func Init() {
CurrentAlarms = make(map[string]Alarm) CurrentAlarms = make(map[string]Alarm)
CurrentTimers = make([]Timer, 0) CurrentTimers = make([]Timer, 0)
} }
type Alarm struct { type Alarm struct {
Name string Name string
Early bool Early bool
...@@ -29,11 +27,9 @@ type Alarm struct { ...@@ -29,11 +27,9 @@ type Alarm struct {
Uuid uuid.UUID Uuid uuid.UUID
Creator string Creator string
} }
func (a *Alarm) String () string {
func (a *Alarm) String() {
return fmt.Sprintf("%v by %v" , a.Name, a.Creator) return fmt.Sprintf("%v by %v" , a.Name, a.Creator)
} }
type Timer struct { type Timer struct {
Name string Name string
Start time.Time Start time.Time
...@@ -67,6 +63,7 @@ func DemoTimer() { ...@@ -67,6 +63,7 @@ func DemoTimer() {
t.Countdown() t.Countdown()
} }
func debug(ty interface{}) { func debug(ty interface{}) {
fooType := reflect.TypeOf(ty) fooType := reflect.TypeOf(ty)
fmt.Println(fooType) fmt.Println(fooType)
...@@ -75,3 +72,4 @@ func debug(ty interface{}) { ...@@ -75,3 +72,4 @@ func debug(ty interface{}) {
fmt.Println(method.Name) fmt.Println(method.Name)
} }
} }
...@@ -57,18 +57,21 @@ func listTimers(ctx *macaron.Context) { ...@@ -57,18 +57,21 @@ func listTimers(ctx *macaron.Context) {
func newAlarm(req *http.Request, log *log.Logger) string { func newAlarm(req *http.Request, log *log.Logger) string {
//insert new alarm locally //insert new alarm locally
// log.Print(req.Form)
name := req.FormValue("name") name := req.FormValue("name")
early, err := strconv.ParseBool(req.FormValue("early")) early, err := strconv.ParseBool(req.FormValue("early"))
// time, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", req.FormValue("time")) log.Println(req.FormValue("time"))
targettime, err := time.ParseInLocation(time.Kitchen, req.FormValue("time"), time.Local)
active, err := strconv.ParseBool(req.FormValue("active")) active, err := strconv.ParseBool(req.FormValue("active"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
log.Println(targettime.Local())
// id := adormit.MakeAlarmId() // id := adormit.MakeAlarmId()
a := adormit.Alarm{Active: active, Early: early, Name: name} a := adormit.Alarm{Active: active, Early: early, Name: name, Time: targettime}
a.MakeId() a.MakeId()
g := a.SetAlarm() g := a.SetAlarm()
log.Printf("http/newAlarm: %s", a.Uuid) log.Printf("http/newAlarm: %s, %v", a.Uuid, a.Time)
return g return g
} }
func delAlarm(req *http.Request) string { func delAlarm(req *http.Request) string {
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment