diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-03-30 11:31:44 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-03-30 11:31:44 +0000 |
commit | 7bb7e17675846bd0caa7b3ad0ff1815cd313ed4f (patch) | |
tree | 70da01c74f0acc4466b9eade58dc79627a6fdcfc | |
parent | 7c34ed846fc29d34638857e4372e7b98c4f4fbe0 (diff) | |
download | ruby-7bb7e17675846bd0caa7b3ad0ff1815cd313ed4f.tar.gz |
* time.c (search_time_t): limit guess range by mktime if it is
availabe.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 10 | ||||
-rw-r--r-- | time.c | 9 |
3 files changed, 24 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Mar 30 20:25:34 2004 Tanaka Akira <akr@m17n.org> + + * time.c (search_time_t): limit guess range by mktime if it is + availabe. + Tue Mar 30 18:19:00 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> * eval.c (rb_eval): fix SEGV at retry in iterator's receiver. diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 0be7a7da96..000fd2e1b8 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -23,4 +23,14 @@ class TestTime < Test::Unit::TestCase assert_equal(Time.utc(2000, 3, 21, 0, 30) \ -Time.utc(2000, 3, 21, 3, 30), -3*3600) end + + def test_negative + begin + Time.at(-1) + rescue ArgumentError + return + end + assert_equal(-1, Time.utc(1969, 12, 31, 23, 59, 59).tv_sec) + assert_equal(-2, Time.utc(1969, 12, 31, 23, 59, 58).tv_sec) + end end @@ -444,6 +444,15 @@ search_time_t(tptr, utc_p) (1UL << (8 * sizeof(time_t) - 1)) - 1 : ~(time_t)0; +#if defined(HAVE_MKTIME) + if ((guess = mktime(tptr)) != -1) { + if (guess_lo < guess - 24 * 60 * 60) + guess_lo = guess - 24 * 60 * 60; + if (guess + 24 * 60 * 60 < guess_hi) + guess_hi = guess + 24 * 60 * 60; + } +#endif + tm = (utc_p ? gmtime : localtime)(&guess_lo); if (!tm) goto error; d = tmcmp(tptr, tm); |