hivedav

A curlable free/busy scheduler with CalDAV integration
git clone https://git.in0rdr.ch/hivedav.git
Log | Files | Refs | Pull requests | README | LICENSE

commit e8ba5865ce32e74b7381660d34fc3f5515dfdc22
parent 52627a00f3ced37817693ce60bc07aa05ba313ac
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Wed, 13 Sep 2023 22:07:53 +0200

improve availability display

Diffstat:
Mserver.go | 52++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/server.go b/server.go @@ -36,12 +36,34 @@ var create_availability_1 = `CREATE TABLE IF NOT EXISTS availability_1 ( start DATETIME NOT NULL, end DATETIME NOT NULL, tz TEXT NOT NULL);` -var a = `SELECT * FROM availability WHERE - start BETWEEN '2023-01-30 15:00' AND '2023-01-30 16:00' OR - end BETWEEN '2023-01-30 15:00' AND '2023-01-30 16:00';` + +// e ? ? +// - | | false +// s e ? +// - + | false +// s ? e ? +// - | - | true (2) +// s ? e +// - | + true (2) +// s ? ? e +// - | | - true (3) +// s e ? +// + - | true (1) +// s e +// + + true (2) +// s ? e +// + | - true (1) +// ? s e +// | - + true (1) +// ? s ? e +// | - | - true (1) +// ? s e +// | + - false + +// TODO: Select only id var available = `SELECT * FROM availability WHERE - (start BETWEEN ? AND ?) OR - (end BETWEEN ? AND ?) OR + (start >= ? AND start < ?) OR + (end > ? AND end <= ?) OR (start <= ? AND end >= ?);` func (s *Server) NewServer(c *config.Config) (*Server, error) { @@ -114,13 +136,11 @@ func (s *Server) available(start string, end string) (bool, error) { err = stmt.QueryRow(start, end, start, end, start, end).Scan(&id, &rowStart, &rowEnd, &tz) if err != nil { if err == sql.ErrNoRows { - log.Println("AVAILABLE") return true, nil } log.Printf("Different error: %v\n", err) return false, err } - log.Println("NOT AVAILABLE") return false, nil } @@ -152,19 +172,30 @@ func (s *Server) Week(w http.ResponseWriter, req *http.Request, ps httprouter.Pa io.WriteString(w, ansistyle.BgRed.Open+"hive!"+ansistyle.BgBlue.Close+"\n") io.WriteString(w, fmt.Sprintf("Serving week %d of year %d\n", week, year)) - pt := prettytable.New([]string{"Time ", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}) + // TODO: Make heading date format configurable, start of week, etc.. + pt := prettytable.New([]string{ + "Time ", + fmt.Sprintf("Mon %s", monday.Format("02.01.")), + fmt.Sprintf("Tue %s", monday.Add(time.Hour).Format("02.01.")), + fmt.Sprintf("Wed %s", monday.Add(time.Hour*24*2).Format("02.01.")), + fmt.Sprintf("Thu %s", monday.Add(time.Hour*24*3).Format("02.01.")), + fmt.Sprintf("Fri %s", monday.Add(time.Hour*24*4).Format("02.01.")), + }) monTime:= dayOfISOWeek(1, week, year) + // TODO: use timeIt to go through the loops below, remove the static arrays timeIt := time.Date(monTime.Year(), monTime.Month(), monTime.Day(), 0, 0, 0, 0, time.UTC) // Working hours - Eight to Five - for _, h := range[]int{8,9,10,11,12,13,14,15,16} { + for _, h := range []int{8,9,10,11,12,13,14,15,16} { var availability [5]string // Working days - Monday through Friday for _, d := range []int{1,2,3,4,5} { start := timeIt.Add(time.Hour * time.Duration((d-1)*24 + h)).Format(sqlDateFmt) - end := timeIt.Add(time.Hour * time.Duration(h+1)).Format(sqlDateFmt) + end := timeIt.Add(time.Hour * time.Duration((d-1)*24 + h+1)).Format(sqlDateFmt) avi, err := s.available(start, end) + log.Printf("Start: %s, End: %s\n", start, end) + log.Printf("Avail: %v\n", avi) if err != nil { log.Printf("Error getting availability on day '%d' hour '%d'\n", d, h) return @@ -175,6 +206,7 @@ func (s *Server) Week(w http.ResponseWriter, req *http.Request, ps httprouter.Pa availability[d-1] = "X" } } + log.Printf("Avail Array: %v\n", availability) pt.AddRow(fmt.Sprintf("%02d:00 - %02d:00", h, h+1), availability[0], availability[1],