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
2 changes: 1 addition & 1 deletion strftime.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len,
else {
off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
}
if (off < 0) {
if (off < 0 || (gmt && (flags & BIT_OF(LEFT)))) {
off = -off;
sign = -1;
}
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,17 @@ def test_strfimte_zoneoffset
assert_equal("+09:00", t.strftime("%:z"))
assert_equal("+09:00:01", t.strftime("%::z"))
assert_equal("+09:00:01", t.strftime("%:::z"))

assert_equal("+0000", t2000.strftime("%z"))
assert_equal("-0000", t2000.strftime("%-z"))
assert_equal("-00:00", t2000.strftime("%-:z"))
assert_equal("-00:00:00", t2000.strftime("%-::z"))

t = t2000.getlocal("+00:00")
assert_equal("+0000", t.strftime("%z"))
assert_equal("+0000", t.strftime("%-z"))
assert_equal("+00:00", t.strftime("%-:z"))
assert_equal("+00:00:00", t.strftime("%-::z"))
end

def test_strftime_padding
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_time_tz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def test_utc_names
assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "UTC"), :utc?)
assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "utc"), :utc?)
assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "Z"), :utc?)
assert_predicate(Time.new(2019, 1, 1, 0, 0, 0, "-00:00"), :utc?)
assert_not_predicate(Time.new(2019, 1, 1, 0, 0, 0, "+00:00"), :utc?)
end

def test_military_names
Expand Down
4 changes: 3 additions & 1 deletion time.c
Original file line number Diff line number Diff line change
Expand Up @@ -2150,8 +2150,10 @@ utc_offset_arg(VALUE arg)
if (s[0] != '+' && s[0] != '-') goto invalid_utc_offset;
if (!ISDIGIT(s[1]) || !ISDIGIT(s[2])) goto invalid_utc_offset;
n += (s[1] * 10 + s[2] - '0' * 11) * 3600;
if (s[0] == '-')
if (s[0] == '-') {
if (n == 0) return UTC_ZONE;
n = -n;
}
return INT2FIX(n);
}
else {
Expand Down