ruby-changes:23791
From: nobu <ko1@a...>
Date: Wed, 30 May 2012 10:58:44 +0900 (JST)
Subject: [ruby-changes:23791] nobu:r35842 (trunk): utc offset in seconds
nobu 2012-05-30 10:58:34 +0900 (Wed, 30 May 2012) New Revision: 35842 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35842 Log: utc offset in seconds * time.c (utc_offset_arg): utc offset can be precision in seconds. e.g. old Europe/Lisbon (c.f. [ruby-dev:40066]) Modified files: trunk/ChangeLog trunk/test/ruby/test_time.rb trunk/time.c Index: time.c =================================================================== --- time.c (revision 35841) +++ time.c (revision 35842) @@ -2111,18 +2111,27 @@ { VALUE tmp; if (!NIL_P(tmp = rb_check_string_type(arg))) { - int n; + int n = 0; char *s = RSTRING_PTR(tmp); - if (!rb_enc_str_asciicompat_p(tmp) || - RSTRING_LEN(tmp) != 6 || - (s[0] != '+' && s[0] != '-') || - !ISDIGIT(s[1]) || - !ISDIGIT(s[2]) || - s[3] != ':' || - !ISDIGIT(s[4]) || - !ISDIGIT(s[5])) + if (!rb_enc_str_asciicompat_p(tmp)) { + invalid_utc_offset: rb_raise(rb_eArgError, "\"+HH:MM\" or \"-HH:MM\" expected for utc_offset"); - n = (s[1] * 10 + s[2] - '0' * 11) * 3600; + } + switch (RSTRING_LEN(tmp)) { + case 9: + if (s[6] != ':') goto invalid_utc_offset; + if (!ISDIGIT(s[7]) || !ISDIGIT(s[8])) goto invalid_utc_offset; + n += (s[7] * 10 + s[8] - '0' * 11); + case 6: + if (s[0] != '+' && s[0] != '-') goto invalid_utc_offset; + if (!ISDIGIT(s[1]) || !ISDIGIT(s[2])) goto invalid_utc_offset; + if (s[3] != ':') goto invalid_utc_offset; + if (!ISDIGIT(s[4]) || !ISDIGIT(s[5])) goto invalid_utc_offset; + break; + default: + goto invalid_utc_offset; + } + n += (s[1] * 10 + s[2] - '0' * 11) * 3600; n += (s[4] * 10 + s[5] - '0' * 11) * 60; if (s[0] == '-') n = -n; Index: ChangeLog =================================================================== --- ChangeLog (revision 35841) +++ ChangeLog (revision 35842) @@ -1,3 +1,8 @@ +Wed May 30 10:58:31 2012 Nobuyoshi Nakada <nobu@r...> + + * time.c (utc_offset_arg): utc offset can be precision in seconds. + e.g. old Europe/Lisbon (c.f. [ruby-dev:40066]) + Wed May 30 06:20:29 2012 Eric Hodel <drbrain@s...> * error.c (exc_set_backtrace): Updated documentation to indicate Index: test/ruby/test_time.rb =================================================================== --- test/ruby/test_time.rb (revision 35841) +++ test/ruby/test_time.rb (revision 35842) @@ -699,7 +699,7 @@ t = T2000.getlocal("+09:00:00") assert_equal("+0900", t.strftime("%z")) assert_equal("+09:00", t.strftime("%:z")) - assert_equal("+09:00:01", t.strftime("%::z")) + assert_equal("+09:00:00", t.strftime("%::z")) assert_equal("+09", t.strftime("%:::z")) t = T2000.getlocal("+09:00:01") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/