aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/carlosgoce/calendar.rb10
-rw-r--r--lib/carlosgoce/layout/layouts.rb4
-rw-r--r--spec/calendar_spec.rb3
3 files changed, 12 insertions, 5 deletions
diff --git a/lib/carlosgoce/calendar.rb b/lib/carlosgoce/calendar.rb
index 48f0071..4445d1f 100644
--- a/lib/carlosgoce/calendar.rb
+++ b/lib/carlosgoce/calendar.rb
@@ -29,9 +29,13 @@ module CarlosGoce
}
# Formatted days creation
- days_before_week_start = Date.new(@year, 1, h[1][:days].first).wday
- empty_days = [''] * (days_before_week_start - 1)
- h[month][:formatted_days] = empty_days + h[1][:days]
+ # @todo First day defaults to Sunday but I should be able to change it to Monday
+ day_of_week = Date.new(@year, month, h[1][:days].first).wday
+ # Fix to change to spanish
+ days_before_week_start = if day_of_week == 0 then 6 else day_of_week -1 end
+
+ empty_days = [''] * days_before_week_start
+ h[month][:formatted_days] = empty_days + h[month][:days]
end
end
}
diff --git a/lib/carlosgoce/layout/layouts.rb b/lib/carlosgoce/layout/layouts.rb
index 6a18513..e4be1c5 100644
--- a/lib/carlosgoce/layout/layouts.rb
+++ b/lib/carlosgoce/layout/layouts.rb
@@ -12,8 +12,8 @@ module CarlosGoce
data[:months].each do |k, month|
days = month[:formatted_days]
- cells = days.to_a.each_slice(6).to_a
- cells.unshift %w(L M X V S D)
+ cells = days.to_a.each_slice(7).to_a
+ cells.unshift %w(L M X J V S D)
cells.unshift [month[:name]]
tables << make_table(cells, cell_style: {align: :center, size: 7, border_width: 0})
diff --git a/spec/calendar_spec.rb b/spec/calendar_spec.rb
index 815f1b1..6a8e22a 100644
--- a/spec/calendar_spec.rb
+++ b/spec/calendar_spec.rb
@@ -46,6 +46,9 @@ describe 'Calendar' do
it 'return the days available formated as array leaving blank days for the starting week\'s day' do
days_for_january_2015 = ['', '', ''] + (1..31).to_a
expect(@calendar.to_h[:months][1][:formatted_days]).to eq days_for_january_2015
+
+ days_for_february_2015 = ['', '', '', '', '', ''] + (1..28).to_a
+ expect(@calendar.to_h[:months][2][:formatted_days]).to eq days_for_february_2015
end
end