commit d059c1c1012abc1784e0ff117ca3131aa0b13aaa
parent 9fc695154a792d0e89f9d3187947c8be742cd987
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Thu, 9 Nov 2023 22:55:18 +0100
feat(config): HORIZON to cap recurring events
Diffstat:
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -50,6 +50,7 @@ The application is configurable through environment variables or the
#HIVEDAV_LISTEN_ADDRESS=127.0.0.1
#HIVEDAV_LISTEN_PORT=3737
#HIVEDAV_CALENDAR=0
+#HIVEDAV_HORIZON=0
#HIVEDAV_BOOKING_SUBJ="HiveDAV Booking"
#HIVEDAV_BOOKING_REMINDER=15
#HIVEDAV_SMTP_PORT=587
@@ -74,6 +75,11 @@ There is an example config file provided in `./app.env.example`.
collection in the ["calendar home
set"](https://www.rfc-editor.org/rfc/rfc4791.html#section-6.2.1) which should
be used to read availability data
+* The `HIVEDAV_HORIZON` is the number of years to show (until 31.12.) from now
+ in the calendar. 0 means that only the current year is shown. This sets the
+limit for recurring events without end time. Setting it to >0 is possible, but
+has no effect, since the program only allows to show/book by calendar week of
+the current year.
* `HIVEDAV_BOOKING_SUBJ` is the subject of the calendar invite for new booking
requests
* `HIVEDAV_BOOKING_REMINDER` is the reminder time in minutes before the start
diff --git a/config/config.go b/config/config.go
@@ -11,6 +11,7 @@ type Config struct {
ListenPort int `mapstructure:"HIVEDAV_LISTEN_PORT"`
CaldavUri string `mapstructure:"HIVEDAV_CALDAV_URI"`
Calendar int `mapstructure:"HIVEDAV_CALENDAR"`
+ Horizon int `mapstructure:"HIVEDAV_HORIZON"`
CaldavUser string `mapstructure:"HIVEDAV_CALDAV_USER"`
CaldavPassword string `mapstructure:"HIVEDAV_CALDAV_PASSWORD"`
RefreshInterval int `mapstructure:"HIVEDAV_REFRESH_INTERVAL"`
@@ -36,6 +37,7 @@ func (c *Config) LoadConfig(path string) (*Config, error) {
viper.SetDefault("HIVEDAV_LISTEN_PORT", 3737)
viper.SetDefault("HIVEDAV_LISTEN_ADDRESS", "[::]")
viper.SetDefault("HIVEDAV_CALENDAR", 0)
+ viper.SetDefault("HIVEDAV_HORIZON", 0)
viper.SetDefault("HIVEDAV_REFRESH_INTERVAL", 30)
viper.SetDefault("HIVEDAV_BOOKING_SUMMARY", "HiveDAV Booking")
viper.SetDefault("HIVEDAV_BOOKING_LOCATION", "https://meet.jit.si")
@@ -75,6 +77,9 @@ func (c *Config) LoadConfig(path string) (*Config, error) {
if viper.IsSet("CALENDAR") {
c.Calendar = viper.GetInt("CALENDAR")
}
+ if viper.IsSet("HORIZON") {
+ c.Calendar = viper.GetInt("HORIZON")
+ }
if viper.IsSet("CALDAV_USER") {
c.CaldavUser = viper.GetString("CALDAV_USER")
}
diff --git a/server.go b/server.go
@@ -348,10 +348,10 @@ func (s *Server) Index(w http.ResponseWriter, req *http.Request, _ httprouter.Pa
}
func (s *Server) UpdateAvailability(calData []caldav.CalData) error {
- // TODO: Make max for recurring events without end time configurable
- rrLimit := time.Date(2024, 12, 31, 0, 0, 0, 0, time.Local)
localNow := time.Now()
isDSTNow := localNow.IsDST()
+ // set limit to recurring events based on configured time horizon
+ rrLimit := time.Date(localNow.Year()+s.config.Horizon, 12, 31, 0, 0, 0, 0, time.Local)
// Walk through events and store start/end time in the database
for _, event := range calData {