Browse Source

Digest week working even with no week number

remotes/origin/master
echarp 3 years ago
parent
commit
8da40221cf
  1. 2
      app/controllers/digests_controller.rb
  2. 5
      app/models/event.rb
  3. 2
      app/views/digests/markdown.html.haml

2
app/controllers/digests_controller.rb

@ -20,6 +20,8 @@ class DigestsController < ApplicationController
private
def set_week
return unless params[:period][:week].present?
@week = Date.commercial params[:period][:year].to_i,
params[:period][:week].to_i
end

5
app/models/event.rb

@ -58,7 +58,10 @@ class Event < ApplicationRecord
start_date.to_date.end_of_month.end_of_week.end_of_day
end)
scope :period, (lambda do |year, week|
start_date = Date.commercial(year.to_i, week.to_i)
start_date = Date.commercial(
year.to_i,
(week || (Time.zone.today + 7.days).cweek).to_i
)
where '? <= end_time and start_time <= ?',
start_date, start_date.end_of_week.end_of_day
end)

2
app/views/digests/markdown.html.haml

@ -1,4 +1,4 @@
- title = t '.title', week: @week.cweek, year: @week.year
- title = t '.title', week: @week.cweek, year: (@week + 4.days).year
- description = capture_haml do
= t '.week', count: @events.count, count_by_country: count_by_country(@events)

Loading…
Cancel
Save