Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Fix for #2 #3

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
4 changes: 4 additions & 0 deletions ext/date_performance.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ rb_date_strptime(int argc, VALUE * argv, VALUE self)
VALUE str = (argc > 0 ? argv[0] : rb_str_new2("-4712-01-01")), VALUE str = (argc > 0 ? argv[0] : rb_str_new2("-4712-01-01")),
fmt = (argc > 1 ? argv[1] : DEFAULT_FORMAT), fmt = (argc > 1 ? argv[1] : DEFAULT_FORMAT),
sg = (argc > 2 ? argv[2] : ITALY); sg = (argc > 2 ? argv[2] : ITALY);

Check_Type(str, T_STRING);
Check_Type(fmt, T_STRING);

char * ps = RSTRING(str)->ptr; char * ps = RSTRING(str)->ptr;
char * pf = RSTRING(fmt)->ptr; char * pf = RSTRING(fmt)->ptr;
VALUE parts[4]; VALUE parts[4];
Expand Down
10 changes: 10 additions & 0 deletions test/extension_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def test_sys_strptime
assert_equal Date.new(1912, 6, 23), Date.sys_strptime("1912-06-23", "%Y-%m-%d") assert_equal Date.new(1912, 6, 23), Date.sys_strptime("1912-06-23", "%Y-%m-%d")
end end


def test_strptime_str_input_handling
assert_raise(TypeError) { Date.strptime(19120623, '%Y%m%d') }
assert_raise(TypeError) { Date.strptime(nil, '%Y%m%d') }
end

def test_strptime_fmt_input_handling
assert_raise(TypeError) { Date.strptime('19120623', 12345) }
assert_raise(TypeError) { Date.strptime('19120623', nil) }
end

# This falls back on Ruby's strptime on BSD systems because BSD's strptime doesn't # This falls back on Ruby's strptime on BSD systems because BSD's strptime doesn't
# handle years before 1900. # handle years before 1900.
def test_strptime_fallback def test_strptime_fallback
Expand Down