Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CWeek DateTime format #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/timecop/time_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def parse_with_mock_date(*args)
case
when date_hash[:year] && date_hash[:mon]
parsed_date
when date_hash[:cwyear] && date_hash[:cweek]
parsed_date
when date_hash[:mon] && date_hash[:mday]
DateTime.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
when date_hash[:mday]
Expand Down
8 changes: 8 additions & 0 deletions test/date_time_parse_scenarios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def test_date_time_parse_wday_with_hour
assert_equal DateTime.parse("2008-09-06T13:00:00"), DateTime.parse('Saturday 13:00')
end

def test_date_time_parse_cweek_date
assert_equal DateTime.parse("1977-01-01T00:00:00"), DateTime.parse('1976-W53-6')
end

def test_date_time_parse_cweek_date_time
assert_equal DateTime.parse("1977-01-01T13:00:01"), DateTime.parse('1976-W53-6 13:00:01')
end

def test_date_time_parse_non_string_raises_expected_error
assert_raises(TypeError) { DateTime.parse(Object.new) }
end
Expand Down
Loading