diff options
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/events_helper.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 1e2e91dc..b14395ab 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb | |||
| @@ -13,6 +13,37 @@ module EventsHelper | |||
| 13 | 13 | ||
| 14 | def external_url_link(url) | 14 | def external_url_link(url) |
| 15 | return nil if url.blank? | 15 | return nil if url.blank? |
| 16 | url.match?(%r{\Ahttps?://}i) ? link_to(url, url) : h(url) | 16 | return h(url) unless url.match?(%r{\Ahttps?://}i) |
| 17 | link_to(url, url, :target => "_blank", :rel => "noopener") | ||
| 17 | end | 18 | end |
| 19 | |||
| 20 | def event_date_range(event) | ||
| 21 | return t("events.schedule.none") if event.start_time.blank? | ||
| 22 | |||
| 23 | from = event.start_time | ||
| 24 | to = event.end_time | ||
| 25 | |||
| 26 | return one_day_range(from, event.allday) if to.blank? || to.to_date == from.to_date | ||
| 27 | |||
| 28 | if !event.allday && (to - from) <= 12.hours | ||
| 29 | return t("events.schedule.evening", | ||
| 30 | :date => admin_date(from), | ||
| 31 | :from => I18n.l(from, :format => :time), | ||
| 32 | :to => I18n.l(to, :format => :time)) | ||
| 33 | end | ||
| 34 | |||
| 35 | key = from.year == to.year && from.month == to.month ? :same_month : :spanning | ||
| 36 | t("events.schedule.#{key}", | ||
| 37 | :from_day => from.day, :to_day => to.day, | ||
| 38 | :from_month => I18n.l(from, :format => :ccc_month), | ||
| 39 | :to_month => I18n.l(to, :format => :ccc_month), | ||
| 40 | :from_full => admin_date(from), :to_full => admin_date(to)) | ||
| 41 | end | ||
| 42 | |||
| 43 | private | ||
| 44 | |||
| 45 | def one_day_range(from, allday) | ||
| 46 | return admin_date(from) if allday | ||
| 47 | admin_datetime(from) | ||
| 48 | end | ||
| 18 | end | 49 | end |
