changeset 47:5839919d7b2d

Fix timezone discrepancies
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 10 Dec 2016 17:53:28 +0100
parents 52ec77607624
children f81fa9a0f30e
files handler_remind.go sql/storage.go
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/handler_remind.go	Sat Dec 10 17:34:21 2016 +0100
+++ b/handler_remind.go	Sat Dec 10 17:53:28 2016 +0100
@@ -21,7 +21,7 @@
 )
 
 func parseReminderString(s string) time.Time {
-	now := time.Now().In(time.FixedZone("local", *flagLocalOffset))
+	now := time.Now()
 	log.Println(s)
 
 	if m := hhmmRE.FindStringSubmatch(s); len(m) >= 3 {
@@ -34,7 +34,8 @@
 			timeOfDay := time.Duration(nowH)*time.Hour + time.Duration(nowM)*time.Minute + time.Duration(nowS)*time.Second
 			midnight := now.Add(-timeOfDay)
 			// duration since midnight of alert time
-			alert := time.Duration(h)*time.Hour + time.Duration(m)*time.Minute
+			// timezone mucking-about because we're using UTC, but users are not
+			alert := time.Duration(h)*time.Hour + time.Duration(m)*time.Minute - (time.Duration(*flagLocalOffset) * time.Second)
 
 			if alert > timeOfDay { // later today
 				return midnight.Add(alert)
--- a/sql/storage.go	Sat Dec 10 17:34:21 2016 +0100
+++ b/sql/storage.go	Sat Dec 10 17:53:28 2016 +0100
@@ -32,6 +32,10 @@
 
 	log.Println("Successfully connected to database")
 
+	if _, err := db.Exec("SET TIME ZONE UTC"); err != nil {
+		log.Println("Couldn't set time zone!", err)
+	}
+
 	return &Storage{db: db, prepared: make(map[string]*sql.Stmt)}, nil
 }