summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-06 10:12:12 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-06 10:12:12 +0000
commitf2ba46eefaacbd786e0cd4bff8ed904008c15291 (patch)
treee8e6f9b4257a9812c4abb589d23456c4a9cceb98 /time.c
parent121de31d0331bd5310aad3d89cc0ad3883273d69 (diff)
Merge changes from ruby_1_8:
* ext/digest/lib/md5.rb (MD5::new, MD5::md5): Do not modify Digest::MD5. * ext/digest/lib/sha1.rb (SHA1::new, SHA1::sha1): Ditto. * lib/shell/process-controller.rb: fix thread synchronization problem for [ruby-dev:30477]. * ext/digest/lib/md5.rb (MD5::new, MD5::md5): Catch up with Digest's API changes; noted by: Kazuhiro Yoshida <moriq AT moriq.com> in [ruby-dev:30500]. * ext/digest/lib/sha1.rb (SHA1::new, SHA1::sha1): Ditto. * time.c (time_to_s): Back out the format changes; discussed in [ruby-dev:30495]. * ext/tk/sample/irbtkw.rbw: fails to exit process. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@12008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/time.c b/time.c
index dd5153db62..f1719b6d44 100644
--- a/time.c
+++ b/time.c
@@ -1239,11 +1239,11 @@ time_asctime(time)
* time.to_s => string
*
* Returns a string representing <i>time</i>. Equivalent to calling
- * <code>Time#strftime</code> with a format string of ``<code>%a,</code>
- * <code>%d</code> <code>%b</code> <code>%H:%M:%S</code>
- * <code>%Z</code> <code>%Y</code>'' (the RFC 2822 style).
+ * <code>Time#strftime</code> with a format string of ``<code>%a</code>
+ * <code>%b</code> <code>%d</code> <code>%H:%M:%S</code>
+ * <code>%Z</code> <code>%Y</code>''.
*
- * Time.now.to_s #=> "Wed 09 Apr 08:56:04 CDT 2003"
+ * Time.now.to_s #=> "Wed Apr 09 08:56:04 CDT 2003"
*/
static VALUE
@@ -1253,30 +1253,32 @@ time_to_s(time)
struct time_object *tobj;
char buf[128];
int len;
- time_t off;
- char buf2[32];
- char sign = '+';
-#if !defined(HAVE_STRUCT_TM_TM_GMTOFF)
- VALUE tmp;
-#endif
GetTimeval(time, tobj);
if (tobj->tm_got == 0) {
time_get_tm(time, tobj->gmt);
}
+ if (tobj->gmt == 1) {
+ len = strftime(buf, 128, "%a %b %d %H:%M:%S UTC %Y", &tobj->tm);
+ }
+ else {
+ time_t off;
+ char buf2[32];
+ char sign = '+';
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
- off = tobj->tm.tm_gmtoff;
+ off = tobj->tm.tm_gmtoff;
#else
- tmp = time_utc_offset(time);
- off = NUM2INT(tmp);
+ VALUE tmp = time_utc_offset(time);
+ off = NUM2INT(tmp);
#endif
- if (off < 0) {
- sign = '-';
- off = -off;
+ if (off < 0) {
+ sign = '-';
+ off = -off;
+ }
+ sprintf(buf2, "%%a %%b %%d %%H:%%M:%%S %c%02d%02d %%Y",
+ sign, (int)(off/3600), (int)(off%3600/60));
+ len = strftime(buf, 128, buf2, &tobj->tm);
}
- sprintf(buf2, "%%a, %%d %%b %%Y %%H:%%M:%%S %c%02d%02d",
- sign, (int)(off/3600), (int)(off%3600/60));
- len = strftime(buf, 128, buf2, &tobj->tm);
return rb_str_new(buf, len);
}