diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-03-22 06:54:29 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-03-22 06:54:29 +0000 |
commit | 8f8a31b0e9972ea9495331980561d548d1ebd72e (patch) | |
tree | dcac67707a322a1e82023a1a0ef39e69b0bc43d8 | |
parent | e689d077e30d4680af140be5549a369590e3db39 (diff) | |
download | ruby-8f8a31b0e9972ea9495331980561d548d1ebd72e.tar.gz |
* time.c (make_time_t): try search_time_t if mktime/timegm is failed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | time.c | 51 |
2 files changed, 27 insertions, 30 deletions
@@ -1,7 +1,11 @@ +Sat Mar 22 15:50:29 2003 Tanaka Akira <akr@m17n.org> + + * time.c (make_time_t): try search_time_t if mktime/timegm is failed. + Sat Mar 22 13:26:33 2003 Tanaka Akira <akr@m17n.org> * lib/optparse.rb, lib/jcode.rb, ext/tk/lib/tk.rb: reorder character - class /[\]\[]/ to /[\[\]]/ to readability. + class /[\]\[]/ to /[\[\]]/ for readability. Sat Mar 22 12:44:15 2003 Tanaka Akira <akr@m17n.org> @@ -336,7 +336,6 @@ static VALUE time_gmtime _((VALUE)); static VALUE time_localtime _((VALUE)); static VALUE time_get_tm _((VALUE, int)); -#if !defined HAVE_TIMEGM static int tmcmp(a, b) struct tm *a; @@ -587,7 +586,6 @@ search_time_t(tptr, utc_p) rb_raise(rb_eArgError, "gmtime/localtime error"); return 0; /* not reached */ } -#endif static time_t make_time_t(tptr, utc_p) @@ -599,43 +597,38 @@ make_time_t(tptr, utc_p) buf = *tptr; if (utc_p) { #if defined(HAVE_TIMEGM) - t = timegm(&buf); - if (t == -1) { + if ((t = timegm(&buf)) != -1) + return t; #ifdef NEGATIVE_TIME_T - if (!(tmp = gmtime(&t)) || - tptr->tm_year != tmp->tm_year || - tptr->tm_mon != tmp->tm_mon || - tptr->tm_mday != tmp->tm_mday || - tptr->tm_hour != tmp->tm_hour || - tptr->tm_min != tmp->tm_min || - tptr->tm_sec != tmp->tm_sec) + if ((tmp = gmtime(&t)) && + tptr->tm_year == tmp->tm_year && + tptr->tm_mon == tmp->tm_mon && + tptr->tm_mday == tmp->tm_mday && + tptr->tm_hour == tmp->tm_hour && + tptr->tm_min == tmp->tm_min && + tptr->tm_sec == tmp->tm_sec) + return t; #endif - rb_raise(rb_eArgError, "gmtime error"); - } -#else - t = search_time_t(&buf, utc_p); #endif + return search_time_t(&buf, utc_p); } else { #if defined(HAVE_MKTIME) - t = mktime(&buf); - if (t == -1) { + if ((t = mktime(&buf)) != -1) + return t; #ifdef NEGATIVE_TIME_T - if (!(tmp = localtime(&t)) || - tptr->tm_year != tmp->tm_year || - tptr->tm_mon != tmp->tm_mon || - tptr->tm_mday != tmp->tm_mday || - tptr->tm_hour != tmp->tm_hour || - tptr->tm_min != tmp->tm_min || - tptr->tm_sec != tmp->tm_sec) + if ((tmp = localtime(&t)) && + tptr->tm_year == tmp->tm_year && + tptr->tm_mon == tmp->tm_mon && + tptr->tm_mday == tmp->tm_mday && + tptr->tm_hour == tmp->tm_hour && + tptr->tm_min == tmp->tm_min && + tptr->tm_sec == tmp->tm_sec) + return t; #endif - rb_raise(rb_eArgError, "localtime error"); - } -#else - t = search_time_t(&buf, utc_p); #endif + return search_time_t(&buf, utc_p); } - return t; } static VALUE |