Merge pull request #267 from xendke/calendar-start-day
Optionally start calendar weeks on Sunday
This commit is contained in:
commit
4bd4921131
4 changed files with 25 additions and 11 deletions
|
@ -1597,15 +1597,25 @@ Example:
|
|||
|
||||
```yaml
|
||||
- type: calendar
|
||||
start-sunday: false
|
||||
```
|
||||
|
||||
Preview:
|
||||
|
||||

|
||||
|
||||
#### 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.
|
||||
|
|
|
@ -11,13 +11,18 @@
|
|||
</div>
|
||||
|
||||
<div class="flex flex-wrap size-h6 margin-top-10 color-subdue">
|
||||
{{ if .StartSunday }}
|
||||
<div class="calendar-day">Su</div>
|
||||
{{ end }}
|
||||
<div class="calendar-day">Mo</div>
|
||||
<div class="calendar-day">Tu</div>
|
||||
<div class="calendar-day">We</div>
|
||||
<div class="calendar-day">Th</div>
|
||||
<div class="calendar-day">Fr</div>
|
||||
<div class="calendar-day">Sa</div>
|
||||
<div class="calendar-day">Su</div>
|
||||
{{ if not .StartSunday }}
|
||||
<div class="calendar-day">Su</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap">
|
||||
|
|
|
@ -3,14 +3,12 @@ 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()
|
||||
|
||||
if weekday == 0 {
|
||||
weekday = 7
|
||||
if !startSunday {
|
||||
weekday = (weekday + 6) % 7 // Shift Monday to 0
|
||||
}
|
||||
|
||||
currentMonthDays := daysInMonth(now.Month(), year)
|
||||
|
@ -23,7 +21,7 @@ func NewCalendar(now time.Time) *Calendar {
|
|||
previousMonthDays = daysInMonth(previousMonthNumber, year)
|
||||
}
|
||||
|
||||
startDaysFrom := now.Day() - int(weekday+6)
|
||||
startDaysFrom := now.Day() - int(weekday) - 7
|
||||
|
||||
days := make([]int, 21)
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue