Skip to content

Commit d21c694

Browse files
committed
Fix misplaced time zone offset checks
1 parent f62bf0a commit d21c694

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ext/date/date_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ date_zone_to_diff(VALUE str)
486486
#define out_of_range(v, min, max) ((v) < (min) || (max) < (v))
487487
hour = STRTOUL(s, &p, 10);
488488
if (*p == ':') {
489-
if (out_of_range(sec, 0, 59)) return Qnil;
489+
if (out_of_range(hour, 0, 23)) return Qnil;
490490
s = ++p;
491491
min = STRTOUL(s, &p, 10);
492492
if (out_of_range(min, 0, 59)) return Qnil;
493493
if (*p == ':') {
494494
s = ++p;
495495
sec = STRTOUL(s, &p, 10);
496-
if (out_of_range(hour, 0, 23)) return Qnil;
496+
if (out_of_range(sec, 0, 59)) return Qnil;
497497
}
498498
}
499499
else if (*p == ',' || *p == '.') {

test/date/test_date_strptime.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ def test__strptime__fail
296296
assert_not_nil(Date._strptime('Januari', '%B'))
297297
assert_nil(Date._strptime('Sundai,', '%A,'))
298298
assert_nil(Date._strptime('Januari,', '%B,'))
299+
300+
assert_nil(Date._strptime('+24:00', '%Z')[:offset])
301+
assert_nil(Date._strptime('+23:60', '%Z')[:offset])
302+
assert_nil(Date._strptime('+23:00:60', '%Z')[:offset])
303+
assert_nil(Date._strptime('+23:00:60', '%Z')[:offset])
299304
end
300305

301306
def test_strptime

0 commit comments

Comments
 (0)