Skip to content

Commit

Permalink
Fix Date strptime implementation for %j
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacronemeyer committed Nov 30, 2020
1 parent d418b23 commit 48e0670
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/timecop/time_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def strptime_with_mock_date(str = '-4712-01-01', fmt = '%F', start = Date::ITALY
Date.new(year, mon, d[:mday])
elsif d[:wday]
Date.new(year, mon, now.mday) + (d[:wday] - now.wday)
elsif d[:yday]
Date.new(year).next_day(d[:yday] - 1)
else
Date.new(year, mon)
end
Expand Down
6 changes: 3 additions & 3 deletions test/date_strptime_scenarios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def test_strptime_converts_back_and_forth_between_date_and_string_for_many_forma
'%Y %m %d',
'%C %y %m %d',

#TODO Support these formats
# '%Y %j',
# '%C %y %j',
'%Y %j',
'%C %y %j',

#TODO Support these formats
# '%G %V %w',
# '%G %V %u',
# '%C %g %V %w',
Expand Down

0 comments on commit 48e0670

Please sign in to comment.