summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-30 09:11:15 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-30 09:11:15 +0000
commitb45ea9c8a0618424894910c72786dd9bb83026ef (patch)
tree4450e3dfb1cea5a1dc9cfea835ada3b1cb1a3f8e
parenta375610ba6332e60a2994b2e7ce3e8e75ecc4896 (diff)
* time.c (time_utc_offset): new function.
* time.c (Init_Time): new method gmtoff, gmt_offset and utc_offset. * lib/time.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--MANIFEST1
-rw-r--r--configure.in8
-rw-r--r--lib/README1
-rw-r--r--time.c45
5 files changed, 63 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 86ecd14985..05d256feb2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Dec 30 18:04:07 2001 Tanaka Akira <[email protected]>
+
+ * time.c (time_utc_offset): new function.
+
+ * time.c (Init_Time): new method gmtoff, gmt_offset and utc_offset.
+
+ * lib/time.rb: new file.
+
Sun Dec 30 00:59:16 2001 WATANABE Hirofumi <[email protected]>
* ext/extmk.rb.in, lib/mkmf.rb (have_library): accept -lm
diff --git a/MANIFEST b/MANIFEST
index 71a0a1cb9e..b82cbae0c1 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -185,6 +185,7 @@ lib/telnet.rb
lib/tempfile.rb
lib/thread.rb
lib/thwait.rb
+lib/time.rb
lib/timeout.rb
lib/tracer.rb
lib/weakref.rb
diff --git a/configure.in b/configure.in
index 060e5f6d1e..e007e4caf9 100644
--- a/configure.in
+++ b/configure.in
@@ -284,6 +284,14 @@ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd chroot\
getpgrp setpgrp getpgid setpgid getgroups getpriority getrlimit\
dlopen sigprocmask sigaction _setjmp setsid telldir seekdir fchmod)
AC_STRUCT_TIMEZONE
+AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
+ [AC_TRY_COMPILE([#include <time.h>],
+ [struct tm t; t.tm_gmtoff = 3600;],
+ [rb_cv_member_struct_tm_tm_gmtoff=yes],
+ [rb_cv_member_struct_tm_tm_gmtoff=no])])
+if test "$rb_cv_member_struct_tm_tm_gmtoff" = yes; then
+ AC_DEFINE(HAVE_STRUCT_TM_TM_GMTOFF)
+fi
AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
[AC_TRY_LINK([#include <time.h>
int i;],
diff --git a/lib/README b/lib/README
index f5dc1d6e8e..01c812d15e 100644
--- a/lib/README
+++ b/lib/README
@@ -54,6 +54,7 @@ telnet.rb obsolete - use net/telnet
tempfile.rb temporary file with automatic removal
thread.rb thread support
thwait.rb thread syncronization class
+time.rb RFC2822, RFC2616, ISO8601 style time formatting/parsing
timeout.rb provides timeout
tracer.rb execution tracer
weakref.rb weak reference class
diff --git a/time.c b/time.c
index 7cd87a26a4..763b86edef 100644
--- a/time.c
+++ b/time.c
@@ -878,6 +878,48 @@ time_zone(time)
}
static VALUE
+time_utc_offset(time)
+ VALUE time;
+{
+ struct time_object *tobj;
+
+ GetTimeval(time, tobj);
+ if (tobj->tm_got == 0) {
+ time_get_tm(time, tobj->gmt);
+ }
+
+ if (tobj->gmt == 1) {
+ return INT2FIX(0);
+ }
+ else {
+#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
+ return INT2NUM(tobj->tm.tm_gmtoff);
+#else
+ struct tm *u, *l;
+ time_t t;
+ int off;
+ l = &tobj->tm;
+ t = tobj->tv.tv_sec;
+ u = gmtime(&t);
+ if (!u)
+ rb_raise(rb_eArgError, "gmtime error");
+ if (l->tm_year != u->tm_year)
+ off = l->tm_year < u->tm_year ? -1 : 1;
+ else if (l->tm_mon != u->tm_mon)
+ off = l->tm_mon < u->tm_mon ? -1 : 1;
+ else if (l->tm_mday != u->tm_mday)
+ off = l->tm_mday < u->tm_mday ? -1 : 1;
+ else
+ off = 0;
+ off = off * 24 + l->tm_hour - u->tm_hour;
+ off = off * 60 + l->tm_min - u->tm_min;
+ off = off * 60 + l->tm_sec - u->tm_sec;
+ return INT2FIX(off);
+#endif
+ }
+}
+
+static VALUE
time_to_a(time)
VALUE time;
{
@@ -1131,6 +1173,9 @@ Init_Time()
rb_define_method(rb_cTime, "isdst", time_isdst, 0);
rb_define_method(rb_cTime, "dst?", time_isdst, 0);
rb_define_method(rb_cTime, "zone", time_zone, 0);
+ rb_define_method(rb_cTime, "gmtoff", time_utc_offset, 0);
+ rb_define_method(rb_cTime, "gmt_offset", time_utc_offset, 0);
+ rb_define_method(rb_cTime, "utc_offset", time_utc_offset, 0);
rb_define_method(rb_cTime, "utc?", time_utc_p, 0);
rb_define_method(rb_cTime, "gmt?", time_utc_p, 0);