Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kudrykv committed Nov 8, 2024
1 parent 48bdd3b commit 4b55a11
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions lib/latex_yearly_planner/calendar/day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def strftime(format)
def ==(other)
other.is_a?(Day) && moment == other.moment && weekday_start == other.weekday_start
end

def <=>(other)
return 0 if moment == other.moment
return -1 if moment < other.moment

1
end
end
end
end
12 changes: 8 additions & 4 deletions lib/latex_yearly_planner/calendar/month.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def year
moment.year
end

def mon
moment.mon
end

def quarter
Quarter.new(weekday_start:, year: moment.year, number: ((moment.month - 1) / 3) + 1)
end
Expand All @@ -55,6 +51,14 @@ def hash
[moment, weekday_start].hash
end

def first_day
Day.new(weekday_start:, moment: moment.beginning_of_month)
end

def last_day
Day.new(weekday_start:, moment: moment.end_of_month)
end

alias eql? ==

private
Expand Down
6 changes: 3 additions & 3 deletions lib/latex_yearly_planner/planners/mos/pages/weekly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def format_day(day)
dayname = day.strftime('%A')
daynum = day.strftime('%-d')

first_day = params.months.first.moment.beginning_of_month
last_day = params.months.last.moment.end_of_month
first_day = params.months.first.first_day
last_day = params.months.last.last_day

if day.moment < first_day || day.moment > last_day
if day < first_day || day > last_day
return "[#{i18n.t("calendar.weekdays.full.#{dayname.downcase}")}, #{daynum}]"
end

Expand Down
4 changes: 0 additions & 4 deletions spec/latex_yearly_planner/calendar/month_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
it { expect(month.year).to eq(year) }
end

describe '#mon' do
it { expect(month.mon).to eq(month_number) }
end

describe '#quarter' do
let(:quarter) { Quarter.new(weekday_start:, year:, number: 3) }

Expand Down

0 comments on commit 4b55a11

Please sign in to comment.