mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
a375610ba6
commit
b45ea9c8a0
5 changed files with 63 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Sun Dec 30 18:04:07 2001 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* 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 <eban@ruby-lang.org>
|
Sun Dec 30 00:59:16 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* ext/extmk.rb.in, lib/mkmf.rb (have_library): accept -lm
|
* ext/extmk.rb.in, lib/mkmf.rb (have_library): accept -lm
|
||||||
|
|
1
MANIFEST
1
MANIFEST
|
@ -185,6 +185,7 @@ lib/telnet.rb
|
||||||
lib/tempfile.rb
|
lib/tempfile.rb
|
||||||
lib/thread.rb
|
lib/thread.rb
|
||||||
lib/thwait.rb
|
lib/thwait.rb
|
||||||
|
lib/time.rb
|
||||||
lib/timeout.rb
|
lib/timeout.rb
|
||||||
lib/tracer.rb
|
lib/tracer.rb
|
||||||
lib/weakref.rb
|
lib/weakref.rb
|
||||||
|
|
|
@ -284,6 +284,14 @@ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd chroot\
|
||||||
getpgrp setpgrp getpgid setpgid getgroups getpriority getrlimit\
|
getpgrp setpgrp getpgid setpgid getgroups getpriority getrlimit\
|
||||||
dlopen sigprocmask sigaction _setjmp setsid telldir seekdir fchmod)
|
dlopen sigprocmask sigaction _setjmp setsid telldir seekdir fchmod)
|
||||||
AC_STRUCT_TIMEZONE
|
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_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
|
||||||
[AC_TRY_LINK([#include <time.h>
|
[AC_TRY_LINK([#include <time.h>
|
||||||
int i;],
|
int i;],
|
||||||
|
|
|
@ -54,6 +54,7 @@ telnet.rb obsolete - use net/telnet
|
||||||
tempfile.rb temporary file with automatic removal
|
tempfile.rb temporary file with automatic removal
|
||||||
thread.rb thread support
|
thread.rb thread support
|
||||||
thwait.rb thread syncronization class
|
thwait.rb thread syncronization class
|
||||||
|
time.rb RFC2822, RFC2616, ISO8601 style time formatting/parsing
|
||||||
timeout.rb provides timeout
|
timeout.rb provides timeout
|
||||||
tracer.rb execution tracer
|
tracer.rb execution tracer
|
||||||
weakref.rb weak reference class
|
weakref.rb weak reference class
|
||||||
|
|
45
time.c
45
time.c
|
@ -877,6 +877,48 @@ time_zone(time)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static VALUE
|
||||||
time_to_a(time)
|
time_to_a(time)
|
||||||
VALUE time;
|
VALUE time;
|
||||||
|
@ -1131,6 +1173,9 @@ Init_Time()
|
||||||
rb_define_method(rb_cTime, "isdst", time_isdst, 0);
|
rb_define_method(rb_cTime, "isdst", time_isdst, 0);
|
||||||
rb_define_method(rb_cTime, "dst?", 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, "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, "utc?", time_utc_p, 0);
|
||||||
rb_define_method(rb_cTime, "gmt?", time_utc_p, 0);
|
rb_define_method(rb_cTime, "gmt?", time_utc_p, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue