hivedav

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

commit 13bca4961da42b3730f782da64340148001a1463
parent 8325c344cbf6e16289f87bda99c472c873768518
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Fri, 15 Sep 2023 22:56:24 +0200

chore: comments

Diffstat:
Mserver.go | 53++++++++---------------------------------------------
1 file changed, 8 insertions(+), 45 deletions(-)

diff --git a/server.go b/server.go @@ -110,6 +110,7 @@ func (s *Server) available(start string, end string) (bool, error) { err = stmt.QueryRow(start, end, start, end, start, end).Scan(&id) if err != nil { if err == sql.ErrNoRows { + // We are available if we cannot find any rows return true, nil } return false, err @@ -118,8 +119,7 @@ func (s *Server) available(start string, end string) (bool, error) { } func (s *Server) Week(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { - // TODO: make display timezone configurable - // display in local time + // TODO: make display timezone configurable, display in local time localLocation, err := time.LoadLocation("Local") if err != nil { return @@ -176,6 +176,7 @@ func (s *Server) Week(w http.ResponseWriter, req *http.Request, ps httprouter.Pa //for d := 0; d < 5; d++ { for _, d := range []int{1,2,3,4,5} { // add/remove 1 minute to make the sql time query in available() below behave correctly + // convert to read/compare in UTC from db start := timeIt.Add(time.Hour * time.Duration((d-1)*24 + h)).Add(1 * time.Minute).UTC().Format(sqlDateFmt) end := timeIt.Add(time.Hour * time.Duration((d-1)*24 + h+1)).Add(-1 * time.Minute).UTC().Format(sqlDateFmt) avi, err := s.available(start, end) @@ -234,6 +235,11 @@ func (s *Server) updateAvailability(calData []caldav.CalData) error { //tzOffsetFrom string // offset which is in use in this time zone observance tzOffsetTo string + // TODO:TZOFFSETFROM is the local time offset from GMT + // when daylight saving time is in operation, + // TZOFFSETTO is the local time offset from GMT when + // standard time is in operation + // https://stackoverflow.com/questions/3872178/what-does-tzoffsetfrom-and-tzoffsetto-mean ) if err != nil { @@ -265,10 +271,6 @@ func (s *Server) updateAvailability(calData []caldav.CalData) error { tzOffsetDurationInt, _ := strconv.Atoi(matches[1]) tzOffsetDuration = time.Hour * time.Duration(tzOffsetDurationInt) log.Printf("Found time zone offset: %v\n", tzOffsetDuration) - // when the TIMEZONE comp is given, the DTSTART usually references the comp - // and we don't have to mess with the offset at all - //tzOffsetDuration = time.Duration(0) - // reset to UTC tzOffsetDuration = time.Hour * time.Duration(-1 * tzOffsetDurationInt) } @@ -352,45 +354,6 @@ func (s *Server) updateAvailability(calData []caldav.CalData) error { // parse time from local time zone and return UTC time for sqlite db func parseTime(timeStr string, offset time.Duration) (time.Time, error){ - //var ( - // localTime *time.Location - // err error - //) - - //re := regexp.MustCompile(`^(\(*([A-Za-z]+)|[A-Za-z/]+).*`) - //matches := re.FindStringSubmatch(tz) - //if len(matches) == 0 { - // log.Printf("Cannot time.LoadLocation() with empty TZID, reverting to UTC") - // // https://pkg.go.dev/time#LoadLocation - // // TODO: Would "Local" fallback be better here? - // // TODO: make fallback timezone for events from server configurable - // localTime, err = time.LoadLocation("Local") - //} else { - // log.Println("Found timezone: ", matches[0]) - // localTime, err = time.LoadLocation(matches[0]) - //} - - //if err != nil { - // log.Printf("Cannot time.LoadLocation() with uknown TZID '%s', reverting to UTC", tz) - // // TODO: Would "Local" fallback be better here? - // // TODO: make fallback timezone for events from server configurable - // localTime, err = time.LoadLocation("Local") - // if err != nil { - // return time.Time{}, err - // } - //} - - //t, err := time.ParseInLocation("20060102T150405Z", timeStr, localTime) - //if err != nil { - // t, err = time.ParseInLocation("20060102T150405", timeStr, localTime) - //} - //if err != nil { - // t, err = time.ParseInLocation("20060102", timeStr, localTime) - //} - //if err != nil { - // return time.Time{}, err - //} - //return t.UTC(), nil t, err := time.Parse("20060102T150405Z", timeStr) if err != nil { t, err = time.Parse("20060102T150405", timeStr)