From 3e467c502157f60b15c4751b8d2f4f3320c51bed Mon Sep 17 00:00:00 2001 From: Juan Xavier Gomez Date: Mon, 25 Nov 2024 13:04:52 -0500 Subject: [PATCH] optionally start calendar weeks on sunday --- docs/configuration.md | 12 +++++++++++- internal/assets/templates/calendar.html | 7 ++++++- internal/feed/calendar.go | 9 ++++++--- internal/widget/calendar.go | 7 ++++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 6f9d602..20156d7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1494,15 +1494,25 @@ Example: ```yaml - type: calendar + start-sunday: false ``` Preview: ![](images/calendar-widget-preview.png) +#### Properties + +| Name | Type | Required | Default | +| ---- | ---- | -------- | ------- | +| start-sunday | boolean | no | false | + +##### `start-sunday` +Whether calendar weeks start on Sunday or Monday. + > [!NOTE] > -> There is currently no customizability available for the calendar. Extra features will be added in the future. +> There is currently little customizability available for the calendar. Extra features will be added in the future. ### Markets Display a list of markets, their current value, change for the day and a small 21d chart. Data is taken from Yahoo Finance. diff --git a/internal/assets/templates/calendar.html b/internal/assets/templates/calendar.html index af15e5a..020d6ac 100644 --- a/internal/assets/templates/calendar.html +++ b/internal/assets/templates/calendar.html @@ -11,13 +11,18 @@
+ {{ if .StartSunday }} +
Su
+ {{ end }}
Mo
Tu
We
Th
Fr
Sa
-
Su
+ {{ if not .StartSunday }} +
Su
+ {{ end }}
diff --git a/internal/feed/calendar.go b/internal/feed/calendar.go index f7ec5d4..a4beae3 100644 --- a/internal/feed/calendar.go +++ b/internal/feed/calendar.go @@ -3,9 +3,8 @@ package feed import "time" // TODO: very inflexible, refactor to allow more customizability -// TODO: allow changing first day of week // TODO: allow changing between showing the previous and next week and the entire month -func NewCalendar(now time.Time) *Calendar { +func NewCalendar(now time.Time, startSunday bool) *Calendar { year, week := now.ISOWeek() weekday := now.Weekday() @@ -23,7 +22,11 @@ func NewCalendar(now time.Time) *Calendar { previousMonthDays = daysInMonth(previousMonthNumber, year) } - startDaysFrom := now.Day() - int(weekday+6) + var offset time.Weekday = 6 + if startSunday { + offset = 7 + } + startDaysFrom := now.Day() - int(weekday+offset) days := make([]int, 21) diff --git a/internal/widget/calendar.go b/internal/widget/calendar.go index a126353..5bfbf37 100644 --- a/internal/widget/calendar.go +++ b/internal/widget/calendar.go @@ -10,8 +10,9 @@ import ( ) type Calendar struct { - widgetBase `yaml:",inline"` - Calendar *feed.Calendar + widgetBase `yaml:",inline"` + Calendar *feed.Calendar + StartSunday bool `yaml:"start-sunday"` } func (widget *Calendar) Initialize() error { @@ -21,7 +22,7 @@ func (widget *Calendar) Initialize() error { } func (widget *Calendar) Update(ctx context.Context) { - widget.Calendar = feed.NewCalendar(time.Now()) + widget.Calendar = feed.NewCalendar(time.Now(), widget.StartSunday) widget.withError(nil).scheduleNextUpdate() }