mirror of
https://github.com/Xevion/glance.git
synced 2025-12-15 08:11:59 -06:00
Merge pull request #267 from xendke/calendar-start-day
Optionally start calendar weeks on Sunday
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user