all repos — homestead @ 610418737cec7dcd954f0080da40417b54f2e937

Code for my website

show per-day times for multi-day events

Alan Pearce
commit

610418737cec7dcd954f0080da40417b54f2e937

parent

6d30cc9ad4727ebb35c3c899358121255ee34caa

1 file changed, 28 insertions(+), 4 deletions(-)

changed files
M internal/calendar/calendar.gointernal/calendar/calendar.go
@@ -21,7 +21,8 @@ const Filename = "calendar.ics"
const Refresh = 30 * time.Minute type Options struct { - URL config.URL + URL config.URL + Timezone config.Timezone } type Calendar struct {
@@ -188,7 +189,7 @@ 0,
0, 0, 0, - now.Location(), + c.opts.Timezone.Location, ) days := count*7 + weekday + 1 dates := make([]Date, 0, days)
@@ -209,7 +210,7 @@ c.log.Debug("processing date", "date", date.DateOnly())
cd := &CalendarDate{Date: date} - evs, err := c.EventsBetween(date.Time, date.NextDay().Time) + evs, err := c.EventsBetween(date.Add(1*time.Second), date.EndOfDay().Time) if err != nil { return nil, errors.WithMessage(err, "could not get events") }
@@ -227,7 +228,7 @@ return cds, nil
} func (d Date) Between(lower, upper Date) bool { - return d.After(lower.Time) && d.Before(upper.Time) + return d.After(lower) && d.Before(upper) } func (d Date) Key() int {
@@ -251,6 +252,21 @@ ),
} } +func (d Date) EndOfDay() Date { + return Date{ + Time: time.Date( + d.Year(), + d.Month(), + d.Day(), + 23, + 59, + 59, + 999999999, + d.Location(), + ), + } +} + func (d Date) DateOnly() string { return d.Format(time.DateOnly) }
@@ -264,3 +280,11 @@
func (d Date) IsToday() bool { return d.Key() == Date{time.Now()}.Key() } + +func (d Date) Before(other Date) bool { + return d.Time.Before(other.Time) +} + +func (d Date) After(other Date) bool { + return d.Time.After(other.Time) +}