Ruby  2.5.0dev(2017-10-22revision60238)
Macros | Typedefs | Functions | Variables
time.c File Reference
#include "internal.h"
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include <float.h>
#include <math.h>
#include "timev.h"
#include "id.h"

Go to the source code of this file.

Macros

#define _DEFAULT_SOURCE
 
#define _BSD_SOURCE
 
#define NDIV(x, y)   (-(-((x)+1)/(y))-1)
 
#define NMOD(x, y)   ((y)-(-((x)+1)%(y))-1)
 
#define DIV(n, d)   ((n)<0 ? NDIV((n),(d)) : (n)/(d))
 
#define MOD(n, d)   ((n)<0 ? NMOD((n),(d)) : (n)%(d))
 
#define VTM_WDAY_INITVAL   (7)
 
#define VTM_ISDST_INITVAL   (3)
 
#define TO_GMT_INITVAL   (3)
 
#define ne(x, y)   (!eq((x),(y)))
 
#define lt(x, y)   (cmp((x),(y)) < 0)
 
#define gt(x, y)   (cmp((x),(y)) > 0)
 
#define le(x, y)   (cmp((x),(y)) <= 0)
 
#define ge(x, y)   (cmp((x),(y)) >= 0)
 
#define neg(x)   (subv(INT2FIX(0), (x)))
 
#define mulquov(x, y, z)   (((y) == (z)) ? (x) : quov(mulv((x),(y)),(z)))
 
#define WIDEVALUE_IS_WIDER   0
 
#define UWIDEINT_MAX   ULONG_MAX
 
#define WIDEINT_MAX   LONG_MAX
 
#define WIDEINT_MIN   LONG_MIN
 
#define FIXWINT_P(v)   FIXNUM_P(v)
 
#define FIXWV_MAX   FIXNUM_MAX
 
#define FIXWV_MIN   FIXNUM_MIN
 
#define FIXWVABLE(i)   FIXABLE(i)
 
#define WINT2FIXWV(i)   WIDEVAL_WRAP(LONG2FIX(i))
 
#define FIXWV2WINT(w)   FIX2LONG(WIDEVAL_GET(w))
 
#define POSFIXWVABLE(wi)   ((wi) < FIXWV_MAX+1)
 
#define NEGFIXWVABLE(wi)   ((wi) >= FIXWV_MIN)
 
#define FIXWV_P(w)   FIXWINT_P(WIDEVAL_GET(w))
 
#define MUL_OVERFLOW_FIXWV_P(a, b)   MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXWV_MIN, FIXWV_MAX)
 
#define WIDEVAL_WRAP(v)   (v)
 
#define WIDEVAL_GET(w)   (w)
 
#define WINT2WV(wi)   WIDEVAL_WRAP(LONG2NUM(wi))
 
#define wne(x, y)   (!weq((x),(y)))
 
#define wlt(x, y)   (wcmp((x),(y)) < 0)
 
#define wgt(x, y)   (wcmp((x),(y)) > 0)
 
#define wle(x, y)   (wcmp((x),(y)) <= 0)
 
#define wge(x, y)   (wcmp((x),(y)) >= 0)
 
#define wmulquo(x, y, z)   ((WIDEVAL_GET(y) == WIDEVAL_GET(z)) ? (x) : wquo(wmul((x),(y)),(z)))
 
#define wmulquoll(x, y, z)   (((y) == (z)) ? (x) : wquo(wmul((x),WINT2WV(y)),WINT2WV(z)))
 
#define TIMET2WV(t)   timet2wv(t)
 
#define WV2TIMET(t)   wv2timet(t)
 
#define leap_year_v_p(y)   leap_year_p(NUM2LONG(modv((y), INT2FIX(400))))
 
#define LOCALTIME(tm, result)   (tzset(),rb_localtime_r((tm), &(result)))
 
#define GMTIME(tm, result)   rb_gmtime_r((tm), &(result))
 
#define GetTimeval(obj, tobj)   ((tobj) = get_timeval(obj))
 
#define GetNewTimeval(obj, tobj)   ((tobj) = get_new_timeval(obj))
 
#define IsTimeval(obj)   rb_typeddata_is_kind_of((obj), &time_data_type)
 
#define TIME_INIT_P(tobj)   ((tobj)->gmt != TO_GMT_INITVAL)
 
#define TIME_UTC_P(tobj)   ((tobj)->gmt == 1)
 
#define TIME_SET_UTC(tobj)   ((tobj)->gmt = 1)
 
#define TIME_LOCALTIME_P(tobj)   ((tobj)->gmt == 0)
 
#define TIME_SET_LOCALTIME(tobj)   ((tobj)->gmt = 0)
 
#define TIME_FIXOFF_P(tobj)   ((tobj)->gmt == 2)
 
#define TIME_SET_FIXOFF(tobj, off)
 
#define TIME_COPY_GMT(tobj1, tobj2)
 
#define MAKE_TM(time, tobj)
 
#define validate_vtm_range(mem, b, e)
 
#define DEBUG_REPORT_GUESSRANGE
 
#define DEBUG_FIND_TIME_NUMGUESS_INC
 
#define GUESS(p)   (DEBUG_FIND_TIME_NUMGUESS_INC (utc_p ? gmtime_with_leapsecond((p), &result) : LOCALTIME((p), result)))
 
#define strftimev(fmt, time, enc)   strftime_cstr((fmt), rb_strlen_lit(fmt), (time), (enc))
 
#define time_succ   rb_time_succ
 
#define wday_p(n)
 
#define get_attr(attr, iffound)
 
#define rb_intern(str)   rb_intern_const(str)
 

Typedefs

typedef unsigned long uwideint_t
 
typedef long wideint_t
 
typedef VALUE WIDEVALUE
 
typedef SIGNED_VALUE SIGNED_WIDEVALUE
 
typedef WIDEVALUE wideval_t
 

Functions

 PACKED_STRUCT_UNALIGNED (struct time_object { wideval_t timew;struct vtm vtm;uint8_t gmt:3;uint8_t tm_got:1;})
 
void rb_timespec_now (struct timespec *ts)
 
VALUE rb_time_new (time_t sec, long usec)
 
VALUE rb_time_nano_new (time_t sec, long nsec)
 
VALUE rb_time_timespec_new (const struct timespec *ts, int offset)
 Returns a time object with UTC/localtime/fixed offset. More...
 
VALUE rb_time_num_new (VALUE timev, VALUE off)
 
struct timeval rb_time_interval (VALUE num)
 
struct timeval rb_time_timeval (VALUE time)
 
struct timespec rb_time_timespec (VALUE time)
 
VALUE rb_time_succ (VALUE time)
 
void Init_Time (void)
 

Variables

VALUE rb_cTime
 

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE

Definition at line 13 of file time.c.

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE

Definition at line 12 of file time.c.

◆ DEBUG_FIND_TIME_NUMGUESS_INC

#define DEBUG_FIND_TIME_NUMGUESS_INC

Definition at line 2681 of file time.c.

◆ DEBUG_REPORT_GUESSRANGE

#define DEBUG_REPORT_GUESSRANGE

Definition at line 2669 of file time.c.

◆ DIV

#define DIV (   n,
 
)    ((n)<0 ? NDIV((n),(d)) : (n)/(d))

Definition at line 43 of file time.c.

◆ FIXWINT_P

#define FIXWINT_P (   v)    FIXNUM_P(v)

Definition at line 211 of file time.c.

◆ FIXWV2WINT

#define FIXWV2WINT (   w)    FIX2LONG(WIDEVAL_GET(w))

Definition at line 216 of file time.c.

◆ FIXWV_MAX

#define FIXWV_MAX   FIXNUM_MAX

Definition at line 212 of file time.c.

◆ FIXWV_MIN

#define FIXWV_MIN   FIXNUM_MIN

Definition at line 213 of file time.c.

◆ FIXWV_P

#define FIXWV_P (   w)    FIXWINT_P(WIDEVAL_GET(w))

Definition at line 221 of file time.c.

◆ FIXWVABLE

#define FIXWVABLE (   i)    FIXABLE(i)

Definition at line 214 of file time.c.

◆ ge

#define ge (   x,
 
)    (cmp((x),(y)) >= 0)

Definition at line 76 of file time.c.

◆ get_attr

#define get_attr (   attr,
  iffound 
)
Value:
attr = rb_attr_delete(str, id_##attr); \
if (!NIL_P(attr)) { \
iffound; \
}
VALUE rb_attr_delete(VALUE, ID)
Definition: variable.c:1266
#define NIL_P(v)
Definition: ruby.h:451

◆ GetNewTimeval

#define GetNewTimeval (   obj,
  tobj 
)    ((tobj) = get_new_timeval(obj))

Definition at line 1608 of file time.c.

◆ GetTimeval

#define GetTimeval (   obj,
  tobj 
)    ((tobj) = get_timeval(obj))

Definition at line 1607 of file time.c.

Referenced by rb_time_succ(), rb_time_timespec(), and rb_time_timeval().

◆ GMTIME

#define GMTIME (   tm,
  result 
)    rb_gmtime_r((tm), &(result))

Definition at line 700 of file time.c.

◆ gt

#define gt (   x,
 
)    (cmp((x),(y)) > 0)

Definition at line 74 of file time.c.

◆ GUESS

#define GUESS (   p)    (DEBUG_FIND_TIME_NUMGUESS_INC (utc_p ? gmtime_with_leapsecond((p), &result) : LOCALTIME((p), result)))

◆ IsTimeval

#define IsTimeval (   obj)    rb_typeddata_is_kind_of((obj), &time_data_type)

Definition at line 1610 of file time.c.

Referenced by rb_time_timespec(), and rb_time_timeval().

◆ le

#define le (   x,
 
)    (cmp((x),(y)) <= 0)

Definition at line 75 of file time.c.

◆ leap_year_v_p

#define leap_year_v_p (   y)    leap_year_p(NUM2LONG(modv((y), INT2FIX(400))))

Definition at line 648 of file time.c.

◆ LOCALTIME

#define LOCALTIME (   tm,
  result 
)    (tzset(),rb_localtime_r((tm), &(result)))

Definition at line 681 of file time.c.

◆ lt

#define lt (   x,
 
)    (cmp((x),(y)) < 0)

Definition at line 73 of file time.c.

◆ MAKE_TM

#define MAKE_TM (   time,
  tobj 
)
Value:
do { \
if ((tobj)->tm_got == 0) { \
time_get_tm((time), (tobj)); \
} \
} while (0)

Definition at line 1631 of file time.c.

◆ MOD

#define MOD (   n,
 
)    ((n)<0 ? NMOD((n),(d)) : (n)%(d))

Definition at line 44 of file time.c.

◆ MUL_OVERFLOW_FIXWV_P

#define MUL_OVERFLOW_FIXWV_P (   a,
 
)    MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXWV_MIN, FIXWV_MAX)

Definition at line 222 of file time.c.

◆ mulquov

#define mulquov (   x,
  y,
 
)    (((y) == (z)) ? (x) : quov(mulv((x),(y)),(z)))

Definition at line 156 of file time.c.

◆ NDIV

#define NDIV (   x,
 
)    (-(-((x)+1)/(y))-1)

Definition at line 41 of file time.c.

Referenced by rb_time_new().

◆ ne

#define ne (   x,
 
)    (!eq((x),(y)))

Definition at line 72 of file time.c.

Referenced by VpAlloc(), and VpDtoV().

◆ neg

#define neg (   x)    (subv(INT2FIX(0), (x)))

Definition at line 131 of file time.c.

Referenced by asinh(), atanh(), rb_fix2str(), rb_int2big(), and rb_math_sqrt().

◆ NEGFIXWVABLE

#define NEGFIXWVABLE (   wi)    ((wi) >= FIXWV_MIN)

Definition at line 220 of file time.c.

◆ NMOD

#define NMOD (   x,
 
)    ((y)-(-((x)+1)%(y))-1)

Definition at line 42 of file time.c.

◆ POSFIXWVABLE

#define POSFIXWVABLE (   wi)    ((wi) < FIXWV_MAX+1)

Definition at line 219 of file time.c.

◆ rb_intern

#define rb_intern (   str)    rb_intern_const(str)

Referenced by Init_Time().

◆ strftimev

#define strftimev (   fmt,
  time,
  enc 
)    strftime_cstr((fmt), rb_strlen_lit(fmt), (time), (enc))

Definition at line 3576 of file time.c.

◆ TIME_COPY_GMT

#define TIME_COPY_GMT (   tobj1,
  tobj2 
)
Value:
((tobj1)->gmt = (tobj2)->gmt, \
(tobj1)->vtm.utc_offset = (tobj2)->vtm.utc_offset, \
(tobj1)->vtm.zone = (tobj2)->vtm.zone)

Definition at line 1625 of file time.c.

◆ TIME_FIXOFF_P

#define TIME_FIXOFF_P (   tobj)    ((tobj)->gmt == 2)

Definition at line 1619 of file time.c.

◆ TIME_INIT_P

#define TIME_INIT_P (   tobj)    ((tobj)->gmt != TO_GMT_INITVAL)

Definition at line 1611 of file time.c.

◆ TIME_LOCALTIME_P

#define TIME_LOCALTIME_P (   tobj)    ((tobj)->gmt == 0)

Definition at line 1616 of file time.c.

◆ TIME_SET_FIXOFF

#define TIME_SET_FIXOFF (   tobj,
  off 
)
Value:
((tobj)->gmt = 2, \
(tobj)->vtm.utc_offset = (off), \
(tobj)->vtm.zone = NULL)
#define NULL
Definition: _sdbm.c:102

Definition at line 1620 of file time.c.

◆ TIME_SET_LOCALTIME

#define TIME_SET_LOCALTIME (   tobj)    ((tobj)->gmt = 0)

Definition at line 1617 of file time.c.

◆ TIME_SET_UTC

#define TIME_SET_UTC (   tobj)    ((tobj)->gmt = 1)

Definition at line 1614 of file time.c.

◆ time_succ

#define time_succ   rb_time_succ

Definition at line 3731 of file time.c.

◆ TIME_UTC_P

#define TIME_UTC_P (   tobj)    ((tobj)->gmt == 1)

Definition at line 1613 of file time.c.

◆ TIMET2WV

#define TIMET2WV (   t)    timet2wv(t)

Definition at line 599 of file time.c.

◆ TO_GMT_INITVAL

#define TO_GMT_INITVAL   (3)

Definition at line 47 of file time.c.

◆ UWIDEINT_MAX

#define UWIDEINT_MAX   ULONG_MAX

Definition at line 208 of file time.c.

◆ validate_vtm_range

#define validate_vtm_range (   mem,
  b,
 
)
Value:
((vtm->mem < b || vtm->mem > e) ? \
rb_raise(rb_eArgError, #mem" out of range") : (void)0)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
VALUE rb_eArgError
Definition: error.c:802

◆ VTM_ISDST_INITVAL

#define VTM_ISDST_INITVAL   (3)

Definition at line 46 of file time.c.

◆ VTM_WDAY_INITVAL

#define VTM_WDAY_INITVAL   (7)

Definition at line 45 of file time.c.

◆ wday_p

#define wday_p (   n)
Value:
{\
struct time_object *tobj;\
GetTimeval(time, tobj);\
MAKE_TM(time, tobj);\
return (tobj->vtm.wday == (n)) ? Qtrue : Qfalse;\
}
#define Qtrue
Definition: ruby.h:437
#define Qfalse
Definition: ruby.h:436

Definition at line 3963 of file time.c.

◆ wge

#define wge (   x,
 
)    (wcmp((x),(y)) >= 0)

Definition at line 344 of file time.c.

◆ wgt

#define wgt (   x,
 
)    (wcmp((x),(y)) > 0)

Definition at line 342 of file time.c.

◆ WIDEINT_MAX

#define WIDEINT_MAX   LONG_MAX

Definition at line 209 of file time.c.

◆ WIDEINT_MIN

#define WIDEINT_MIN   LONG_MIN

Definition at line 210 of file time.c.

◆ WIDEVAL_GET

#define WIDEVAL_GET (   w)    (w)

Definition at line 235 of file time.c.

◆ WIDEVAL_WRAP

#define WIDEVAL_WRAP (   v)    (v)

Definition at line 234 of file time.c.

◆ WIDEVALUE_IS_WIDER

#define WIDEVALUE_IS_WIDER   0

Definition at line 207 of file time.c.

◆ WINT2FIXWV

#define WINT2FIXWV (   i)    WIDEVAL_WRAP(LONG2FIX(i))

Definition at line 215 of file time.c.

◆ WINT2WV

#define WINT2WV (   wi)    WIDEVAL_WRAP(LONG2NUM(wi))

Definition at line 249 of file time.c.

◆ wle

#define wle (   x,
 
)    (wcmp((x),(y)) <= 0)

Definition at line 343 of file time.c.

◆ wlt

#define wlt (   x,
 
)    (wcmp((x),(y)) < 0)

Definition at line 341 of file time.c.

◆ wmulquo

#define wmulquo (   x,
  y,
 
)    ((WIDEVAL_GET(y) == WIDEVAL_GET(z)) ? (x) : wquo(wmul((x),(y)),(z)))

Definition at line 400 of file time.c.

◆ wmulquoll

#define wmulquoll (   x,
  y,
 
)    (((y) == (z)) ? (x) : wquo(wmul((x),WINT2WV(y)),WINT2WV(z)))

Definition at line 401 of file time.c.

◆ wne

#define wne (   x,
 
)    (!weq((x),(y)))

Definition at line 340 of file time.c.

◆ WV2TIMET

#define WV2TIMET (   t)    wv2timet(t)

Definition at line 622 of file time.c.

Typedef Documentation

◆ SIGNED_WIDEVALUE

Definition at line 206 of file time.c.

◆ uwideint_t

typedef unsigned long uwideint_t

Definition at line 203 of file time.c.

◆ wideint_t

typedef long wideint_t

Definition at line 204 of file time.c.

◆ wideval_t

Definition at line 233 of file time.c.

◆ WIDEVALUE

typedef VALUE WIDEVALUE

Definition at line 205 of file time.c.

Function Documentation

◆ Init_Time()

void Init_Time ( void  )

Definition at line 4833 of file time.c.

References id_quo, and rb_intern.

◆ PACKED_STRUCT_UNALIGNED()

PACKED_STRUCT_UNALIGNED ( struct time_object { wideval_t timew;struct vtm vtm;uint8_t gmt:3;uint8_t tm_got:1;}  )

◆ rb_time_interval()

struct timeval rb_time_interval ( VALUE  num)

Definition at line 2299 of file time.c.

Referenced by rb_mutex_sleep().

◆ rb_time_nano_new()

VALUE rb_time_nano_new ( time_t  sec,
long  nsec 
)

Definition at line 2170 of file time.c.

◆ rb_time_new()

VALUE rb_time_new ( time_t  sec,
long  usec 
)

Definition at line 2143 of file time.c.

References NDIV, rb_eRangeError, and rb_raise().

◆ rb_time_num_new()

VALUE rb_time_num_new ( VALUE  timev,
VALUE  off 
)

Definition at line 2204 of file time.c.

◆ rb_time_succ()

VALUE rb_time_succ ( VALUE  time)

Definition at line 3718 of file time.c.

References GetTimeval, and rb_warn().

◆ rb_time_timespec()

struct timespec rb_time_timespec ( VALUE  time)

Definition at line 2322 of file time.c.

References GetTimeval, and IsTimeval.

◆ rb_time_timespec_new()

VALUE rb_time_timespec_new ( const struct timespec ts,
int  offset 
)

Returns a time object with UTC/localtime/fixed offset.

offset is -86400 < fixoff < 86400 or INT_MAX (localtime) or INT_MAX-1 (utc)

Definition at line 2181 of file time.c.

◆ rb_time_timeval()

struct timeval rb_time_timeval ( VALUE  time)

Definition at line 2305 of file time.c.

References GetTimeval, and IsTimeval.

Referenced by rb_thread_sleep().

◆ rb_timespec_now()

void rb_timespec_now ( struct timespec ts)

Variable Documentation

◆ rb_cTime

VALUE rb_cTime

Definition at line 624 of file time.c.