Skip to content

Commit

Permalink
keep baby age in months until 2y
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhawksley committed Oct 31, 2024
1 parent 019d5d9 commit 63181cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
22 changes: 19 additions & 3 deletions app/models/calendar_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def baby_age_event(birthdate = Date.parse(Timeframe::Application.config.local["b
day_count = today - 1.day - birthdate
week_count = (day_count / 7).to_i

if week_count > 24
if week_count > 104
time_difference = TimeDifference.between(birthdate, today).in_general
months = time_difference[:months]
weeks = time_difference[:weeks]
Expand All @@ -15,8 +15,24 @@ def baby_age_event(birthdate = Date.parse(Timeframe::Application.config.local["b
summary = ""
summary << "#{years}y" if years > 0
summary << "#{months}m" if months > 0
summary << "#{weeks}w" if weeks > 0
summary << "#{days}d" if days > 0

if birthdate.day != today.day
summary << "#{weeks}w" if weeks > 0
summary << "#{days}d" if days > 0
end
elsif week_count > 24
time_difference = TimeDifference.between(birthdate, today).in_general
months = time_difference[:months] + (time_difference[:years] * 12)
weeks = time_difference[:weeks]
days = time_difference[:days]

summary = ""
summary << "#{months}m" if months > 0

if birthdate.day != today.day
summary << "#{weeks}w" if weeks > 0
summary << "#{days}d" if days > 0
end
else
remainder = (day_count % 7).to_i

Expand Down
18 changes: 17 additions & 1 deletion test/models/calendar_feed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ def test_baby_age_event_1_yr
travel_to DateTime.new(2024, 7, 11, 8, 0, 0, "-0600") do
result = CalendarFeed.new.baby_age_event(Date.new(2023, 7, 11))

assert_equal("1y", result.summary)
assert_equal("12m", result.summary)
end
end

def test_baby_age_event_18_mos
travel_to DateTime.new(2025, 1, 11, 8, 0, 0, "-0600") do
result = CalendarFeed.new.baby_age_event(Date.new(2023, 7, 11))

assert_equal("18m", result.summary)
end
end

def test_baby_age_event_36_mos
travel_to DateTime.new(2026, 7, 11, 8, 0, 0, "-0600") do
result = CalendarFeed.new.baby_age_event(Date.new(2023, 7, 11))

assert_equal("3y", result.summary)
end
end

Expand Down

0 comments on commit 63181cd

Please sign in to comment.