Skip to content

Commit

Permalink
weekdays
Browse files Browse the repository at this point in the history
  • Loading branch information
kudrykv committed May 13, 2023
1 parent e241fef commit bafd1da
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/adapters/tex/texcalendar/calendar_little.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (r CalendarLittle) String() string {
tabular := tabularx.New(LineWidth{})
tabular.SetHeaderName(r.Month.Name())

tabular.AddRow(r.makeWeekdays()...)

for _, week := range r.Month.Weeks() {
cells := make([]tabularx.Cell, 0, len(week.Days)+1)

Expand All @@ -64,6 +66,24 @@ func (r CalendarLittle) String() string {
return tabular.Render()
}

func (r CalendarLittle) makeWeekdays() tabularx.Cells {
cells := make(tabularx.Cells, 0, 7)

weekday := r.Month.Weekday
for i := 0; i < 7; i++ {
cells = append(cells, tabularx.Cell{Text: NewWeekdayCalendarLittle(weekday)})
weekday = weekday.Next()
}

if r.Parameters.ShowWeekNumbers && r.Parameters.WeekNumberPlacement == entities.PlacementRight {
cells = append(cells, tabularx.Cell{Text: NewWeekNameCalendarLittle()})
} else {
cells = append([]tabularx.Cell{{Text: NewWeekNameCalendarLittle()}}, cells...)
}

return cells
}

type LineWidth struct{}

func (r LineWidth) String() string {
Expand Down
11 changes: 11 additions & 0 deletions internal/adapters/tex/texcalendar/week_name_calendar_little.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package texcalendar

type WeekNameCalendarLittle struct{}

func NewWeekNameCalendarLittle() WeekNameCalendarLittle {
return WeekNameCalendarLittle{}
}

func (r WeekNameCalendarLittle) String() string {
return `W`
}
15 changes: 15 additions & 0 deletions internal/adapters/tex/texcalendar/weekday_calendar_little.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package texcalendar

import "github.com/kudrykv/latex-yearly-planner/internal/core/calendar"

type WeekdayCalendarLittle struct {
Weekday calendar.Weekday
}

func NewWeekdayCalendarLittle(weekday calendar.Weekday) WeekdayCalendarLittle {
return WeekdayCalendarLittle{Weekday: weekday}
}

func (r WeekdayCalendarLittle) String() string {
return r.Weekday.String()[:1]
}
8 changes: 8 additions & 0 deletions internal/core/calendar/weekday.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ func (r Weekday) RightDistanceTo(weekday Weekday) int {
return int(left-right) % 7
}

func (r Weekday) String() string {
return r.Raw.String()
}

func (r Weekday) Next() Weekday {
return Weekday{Raw: (r.Raw + 1) % 7}
}

var (
Sunday = Weekday{Raw: time.Sunday}
Monday = Weekday{Raw: time.Monday}
Expand Down

0 comments on commit bafd1da

Please sign in to comment.