mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/date/date_core.c (datetime_s_now): [ruby-core:43256].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db68d5ba7b
commit
f24d9fcd75
2 changed files with 45 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Mar 14 07:48:36 2012 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* ext/date/date_core.c (datetime_s_now): [ruby-core:43256].
|
||||
|
||||
Tue Mar 13 22:00:14 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* compile.c (iseq_set_arguments): keyword rest arg without keyword args.
|
||||
|
|
|
@ -3583,6 +3583,15 @@ date_s_nth_kday(int argc, VALUE *argv, VALUE klass)
|
|||
#endif
|
||||
|
||||
#if !defined(HAVE_GMTIME_R)
|
||||
static struct tm*
|
||||
gmtime_r(const time_t *t, struct tm *tm)
|
||||
{
|
||||
auto struct tm *tmp = gmtime(t);
|
||||
if (tmp)
|
||||
*tm = *tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static struct tm*
|
||||
localtime_r(const time_t *t, struct tm *tm)
|
||||
{
|
||||
|
@ -3623,6 +3632,7 @@ date_s_today(int argc, VALUE *argv, VALUE klass)
|
|||
|
||||
if (time(&t) == -1)
|
||||
rb_sys_fail("time");
|
||||
tzset();
|
||||
if (!localtime_r(&t, &tm))
|
||||
rb_sys_fail("localtime");
|
||||
|
||||
|
@ -7838,6 +7848,7 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
|
|||
rb_sys_fail("gettimeofday");
|
||||
sec = tv.tv_sec;
|
||||
#endif
|
||||
tzset();
|
||||
if (!localtime_r(&sec, &tm))
|
||||
rb_sys_fail("localtime");
|
||||
|
||||
|
@ -7851,8 +7862,37 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass)
|
|||
s = 59;
|
||||
#ifdef HAVE_STRUCT_TM_TM_GMTOFF
|
||||
of = tm.tm_gmtoff;
|
||||
#elif defined(HAVE_VAR_TIMEZONE)
|
||||
#ifdef HAVE_VAR_ALTZONE
|
||||
of = (long)((tm.tm_isdst > 0) ? altzone : timezone);
|
||||
#else
|
||||
of = -timezone;
|
||||
of = (long)-timezone;
|
||||
if (tm.tm_isdst) {
|
||||
time_t sec2;
|
||||
|
||||
tm.tm_isdst = 0;
|
||||
sec2 = mktime(&tm);
|
||||
of += (long)difftime(sec2, sec);
|
||||
}
|
||||
#endif
|
||||
#elif defined(HAVE_TIMEGM)
|
||||
{
|
||||
time_t sec2;
|
||||
|
||||
sec2 = timegm(&tm);
|
||||
of = (long)difftime(sec2, sec);
|
||||
}
|
||||
#else
|
||||
{
|
||||
struct tm tm2;
|
||||
time_t sec2;
|
||||
|
||||
if (!gmtime_r(&sec, &tm2))
|
||||
rb_sys_fail("gmtime");
|
||||
tm2.tm_isdst = tm.tm_isdst;
|
||||
sec2 = mktime(&tm2);
|
||||
of = (long)difftime(sec, sec2);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
sf = ts.tv_nsec;
|
||||
|
|
Loading…
Reference in a new issue