diff --git a/Gemfile b/Gemfile index 65781c3..2e3b2c0 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem "puma" gem "rails", "~> 7.1" gem "slim" gem "tenkit", git: "https://github.com/joelhawksley/tenkit", branch: "add-alerts" +gem "time_difference" gem "view_component" group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 85dc6a0..f4d5a78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -313,6 +313,8 @@ GEM temple (0.10.3) thor (1.3.0) tilt (2.3.0) + time_difference (0.5.0) + activesupport timeout (0.4.1) trailblazer-option (0.1.2) tzinfo (2.0.6) @@ -353,6 +355,7 @@ DEPENDENCIES sqlite3 standard tenkit! + time_difference vcr view_component webmock diff --git a/app/models/calendar_feed.rb b/app/models/calendar_feed.rb index 0d43768..7763d14 100644 --- a/app/models/calendar_feed.rb +++ b/app/models/calendar_feed.rb @@ -1,21 +1,31 @@ -# frozen_string_literal: true - class CalendarFeed def self.baby_age_event(birthdate = Date.parse(Timeframe::Application.config.local["birthdate"])) day_count = Date.today - birthdate week_count = (day_count / 7).to_i remainder = (day_count % 7).to_i - summary = - if remainder > 0 - if week_count > 0 - "#{week_count}w#{remainder}d" + if week_count > 24 + time_difference = TimeDifference.between(birthdate, Date.today).in_general + months = time_difference[:months] + weeks = time_difference[:weeks] + days = time_difference[:days] + + summary = "" + summary << "#{months}m" if months > 0 + summary << "#{weeks}w" if weeks > 0 + summary << "#{days}d" if days > 0 + else + summary = + if remainder > 0 + if week_count > 0 + "#{week_count}w#{remainder}d" + else + "#{remainder}d" + end else - "#{remainder}d" + "#{week_count}w" end - else - "#{week_count}w" - end + end CalendarEvent.new( id: "_baby_age",