From 1f2d0c1e1ec61d9108cf85c3d640b7b34d801f22 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 27 Dec 2023 18:25:56 +0100
Subject: [PATCH] simpler

---
 .../communication/website/agenda/event.rb     | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb
index 912fb496b..8f40c0bae 100644
--- a/app/models/communication/website/agenda/event.rb
+++ b/app/models/communication/website/agenda/event.rb
@@ -156,7 +156,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord
       title: "#{title} #{subtitle}",
       url: url,
       description: summary,
-      all_day: (from_hour.nil? && to_hour.nil?)
+      all_day: all_day?
     )
   end
 
@@ -172,15 +172,25 @@ class Communication::Website::Agenda::Event < ApplicationRecord
   end
 
   def to_time
-    if to_day.nil?
-      to_hour.nil?  ? nil # Pas de fin, ni jour ni heure
-                    : date_and_time(from_day, to_hour) # Heure de fin, donc on se base sur le jour de début
-    elsif to_day.present?
-      to_hour.nil?  ? to_day.to_time # Jour de fin seul
-                    : date_and_time(to_day, to_hour) # Jour et heure de fin
+    if to_day.nil? && to_hour.nil?
+      # Pas de fin
+      nil
+    elsif to_day.nil? && to_hour.present?
+      # Heure de fin, donc on se base sur le jour de début
+      date_and_time(from_day, to_hour)
+    elsif to_day.present? && to_hour.nil?
+      # Jour de fin seul
+      to_day.to_time
+    elsif to_day.present? && to_hour.nil?
+      # Jour et heure de fin
+      date_and_time(to_day, to_hour)
     end
   end
 
+  def all_day?
+    from_hour.nil? && to_hour.nil?
+  end
+
   def date_and_time(date, time)
     Time.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone)
   end
-- 
GitLab