Skip to content
Merged
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
26 changes: 18 additions & 8 deletions ext/date/date_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ VALUE
date_zone_to_diff(VALUE str)
{
VALUE offset = Qnil;
VALUE vbuf = 0;
long l = RSTRING_LEN(str);
const char *s = RSTRING_PTR(str);

Expand All @@ -439,16 +438,27 @@ date_zone_to_diff(VALUE str)
l -= w;
dst = 1;
}

{
const char *zn = s;
long sl = shrunk_size(s, l);
if (sl > 0 && sl <= MAX_WORD_LENGTH) {
VALUE vbuf = 0;
const struct zone *z = 0;

if (sl <= 0) {
sl = l;
}
else if (sl <= MAX_WORD_LENGTH) {
char *d = ALLOCV_N(char, vbuf, sl);
l = shrink_space(d, s, l);
s = d;
sl = shrink_space(d, s, l);
zn = d;
}
}
if (l > 0 && l <= MAX_WORD_LENGTH) {
const struct zone *z = zonetab(s, (unsigned int)l);

if (sl > 0 && sl <= MAX_WORD_LENGTH) {
z = zonetab(zn, (unsigned int)sl);
}
ALLOCV_END(vbuf);

if (z) {
int d = z->offset;
if (dst)
Expand All @@ -457,6 +467,7 @@ date_zone_to_diff(VALUE str)
goto ok;
}
}

{
char *p;
int sign = 0;
Expand Down Expand Up @@ -542,7 +553,6 @@ date_zone_to_diff(VALUE str)
}
RB_GC_GUARD(str);
ok:
ALLOCV_END(vbuf);
return offset;
}

Expand Down
2 changes: 2 additions & 0 deletions test/date/test_date_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def test__parse
[['19990523235521.123[-9]',false],[1999,5,23,23,55,21,'-9',-(9*3600),nil], __LINE__],
[['19990523235521.123[+9]',false],[1999,5,23,23,55,21,'+9',+(9*3600),nil], __LINE__],
[['19990523235521.123[9]',false],[1999,5,23,23,55,21,'9',+(9*3600),nil], __LINE__],
[['19990523235521.123[9 ]',false],[1999,5,23,23,55,21,'9 ',+(9*3600),nil], __LINE__],
[['19990523235521.123[-9.50]',false],[1999,5,23,23,55,21,'-9.50',-(9*3600+30*60),nil], __LINE__],
[['19990523235521.123[+9.50]',false],[1999,5,23,23,55,21,'+9.50',+(9*3600+30*60),nil], __LINE__],
[['19990523235521.123[-5:EST]',false],[1999,5,23,23,55,21,'EST',-5*3600,nil], __LINE__],
Expand All @@ -140,6 +141,7 @@ def test__parse
[['235521.123',false],[nil,nil,nil,23,55,21,nil,nil,nil], __LINE__],
[['235521.123[-9]',false],[nil,nil,nil,23,55,21,'-9',-9*3600,nil], __LINE__],
[['235521.123[+9]',false],[nil,nil,nil,23,55,21,'+9',+9*3600,nil], __LINE__],
[['235521.123[-9 ]',false],[nil,nil,nil,23,55,21,'-9 ',-9*3600,nil], __LINE__],
[['235521.123[-5:EST]',false],[nil,nil,nil,23,55,21,'EST',-5*3600,nil], __LINE__],
[['235521.123[+9:JST]',false],[nil,nil,nil,23,55,21,'JST',+9*3600,nil], __LINE__],

Expand Down