From 56fd287b0f16369e6bdf7a658f3e66a53542103f Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 18 Feb 2026 10:52:54 +0100 Subject: [PATCH] show next 5 months if few moods recorded --- app/services/mood_calendar_service.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/services/mood_calendar_service.rb b/app/services/mood_calendar_service.rb index aafb52d..04553bb 100644 --- a/app/services/mood_calendar_service.rb +++ b/app/services/mood_calendar_service.rb @@ -6,16 +6,21 @@ class MoodCalendarService .pluck(:mode, :recorded_at) .map { |mode, recorded_at| { mode: mode, recorded_at: recorded_at } } - return [] if data.empty? - # Définir start_date par défaut comme le recorded_at du premier mood - start_date ||= data.first[:recorded_at].to_date - - # Convertir en Date si ce sont des DateTime ou Time - start_date = start_date.to_date - end_date = end_date.to_date + if data.empty? + start_date = Date.current + else + start_date ||= data.first[:recorded_at].to_date end + if end_date < (start_date + 5.months) + end_date = start_date + 5.months + end + + # Convertir en Date si ce sont des DateTime ou Time + start_date = start_date.to_date + end_date = end_date&.to_date + # Grouper par jour et garder le plus récent pour chaque jour data_by_date = data.group_by { |d| d[:recorded_at].to_date } .transform_values { |entries| entries.max_by { |e| e[:recorded_at] } }