Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 50b6764

Browse files
committedDec 30, 2013
Merge pull request travisjeffery#111 from yaauie/more-issue-108
Provide correct defaults for Date::strptime
2 parents c6d0db0 + 34a01ee commit 50b6764

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

Diff for: ‎lib/timecop/time_extensions.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ def today_with_mock_date
4343

4444
alias_method :strptime_without_mock_date, :strptime
4545

46-
def strptime_with_mock_date(str, fmt)
46+
def strptime_with_mock_date(str = '-4712-01-01', fmt = '%F', start = Date::ITALY)
47+
unless start == Date::ITALY
48+
raise ArgumentError, "Timecop's #{self}::#{__method__} only " +
49+
"supports Date::ITALY for the start argument."
50+
end
51+
4752
Time.strptime(str, fmt).to_date
4853
end
4954

Diff for: ‎test/timecop_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ def test_date_strptime_without_year
494494
end
495495
end
496496

497+
def test_date_strptime_without_specifying_format
498+
Timecop.freeze(Time.new(1984,2,28)) do
499+
assert_equal Date.strptime('1999-04-14'), Date.new(1999, 4, 14)
500+
end
501+
end
502+
497503
private
498504

499505
def with_safe_mode(enabled=true)

0 commit comments

Comments
 (0)
This repository has been archived.