mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
optionally start calendar weeks on sunday
This commit is contained in:
parent
d90d39933a
commit
3e467c5021
@ -1494,15 +1494,25 @@ Example:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- type: calendar
|
- type: calendar
|
||||||
|
start-sunday: false
|
||||||
```
|
```
|
||||||
|
|
||||||
Preview:
|
Preview:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
#### Properties
|
||||||
|
|
||||||
|
| Name | Type | Required | Default |
|
||||||
|
| ---- | ---- | -------- | ------- |
|
||||||
|
| start-sunday | boolean | no | false |
|
||||||
|
|
||||||
|
##### `start-sunday`
|
||||||
|
Whether calendar weeks start on Sunday or Monday.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!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
|
### Markets
|
||||||
Display a list of markets, their current value, change for the day and a small 21d chart. Data is taken from Yahoo Finance.
|
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>
|
||||||
|
|
||||||
<div class="flex flex-wrap size-h6 margin-top-10 color-subdue">
|
<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">Mo</div>
|
||||||
<div class="calendar-day">Tu</div>
|
<div class="calendar-day">Tu</div>
|
||||||
<div class="calendar-day">We</div>
|
<div class="calendar-day">We</div>
|
||||||
<div class="calendar-day">Th</div>
|
<div class="calendar-day">Th</div>
|
||||||
<div class="calendar-day">Fr</div>
|
<div class="calendar-day">Fr</div>
|
||||||
<div class="calendar-day">Sa</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>
|
||||||
|
|
||||||
<div class="flex flex-wrap">
|
<div class="flex flex-wrap">
|
||||||
|
@ -3,9 +3,8 @@ package feed
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// TODO: very inflexible, refactor to allow more customizability
|
// 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
|
// 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()
|
year, week := now.ISOWeek()
|
||||||
weekday := now.Weekday()
|
weekday := now.Weekday()
|
||||||
|
|
||||||
@ -23,7 +22,11 @@ func NewCalendar(now time.Time) *Calendar {
|
|||||||
previousMonthDays = daysInMonth(previousMonthNumber, year)
|
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)
|
days := make([]int, 21)
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Calendar struct {
|
type Calendar struct {
|
||||||
widgetBase `yaml:",inline"`
|
widgetBase `yaml:",inline"`
|
||||||
Calendar *feed.Calendar
|
Calendar *feed.Calendar
|
||||||
|
StartSunday bool `yaml:"start-sunday"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Calendar) Initialize() error {
|
func (widget *Calendar) Initialize() error {
|
||||||
@ -21,7 +22,7 @@ func (widget *Calendar) Initialize() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Calendar) Update(ctx context.Context) {
|
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()
|
widget.withError(nil).scheduleNextUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user