Ruby  3.4.0dev (2024-11-22 revision 0989400a925cd201defdca9eb28eb87200b30785)
Functions
time.h File Reference

(0989400a925cd201defdca9eb28eb87200b30785)

Public APIs related to rb_cTime. More...

#include "ruby/internal/config.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
Include dependency graph for time.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void rb_timespec_now (struct timespec *ts)
 Fills the current time into the given struct. More...
 
VALUE rb_time_new (time_t sec, long usec)
 Creates an instance of rb_cTime with the given time and the local timezone. More...
 
VALUE rb_time_nano_new (time_t sec, long nsec)
 Identical to rb_time_new(), except it accepts the time in nanoseconds resolution. More...
 
VALUE rb_time_timespec_new (const struct timespec *ts, int offset)
 Creates an instance of rb_cTime, with given time and offset. More...
 
VALUE rb_time_num_new (VALUE timev, VALUE off)
 Identical to rb_time_timespec_new(), except it takes Ruby values instead of C structs. More...
 
struct timeval rb_time_interval (VALUE num)
 Creates a "time interval". More...
 
struct timeval rb_time_timeval (VALUE time)
 Converts an instance of rb_cTime to a struct timeval that represents the identical point of time. More...
 
struct timespec rb_time_timespec (VALUE time)
 Identical to rb_time_timeval(), except for return type. More...
 
struct timespec rb_time_timespec_interval (VALUE num)
 Identical to rb_time_interval(), except for return type. More...
 
VALUE rb_time_utc_offset (VALUE time)
 Queries the offset, in seconds between the time zone of the time and the UTC. More...
 

Detailed Description

Public APIs related to rb_cTime.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file time.h.

Function Documentation

◆ rb_time_interval()

struct timeval rb_time_interval ( VALUE  num)

Creates a "time interval".

This basically converts an instance of rb_cNumeric into a struct timeval, but for instance negative time interval must not exist.

Parameters
[in]numAn instance of rb_cNumeric.
Exceptions
rb_eArgErrornum is negative.
rb_eRangeErrornum is out of range of timeval::tv_sec.
Returns
A struct that represents the identical time to num.

Definition at line 2773 of file time.c.

Referenced by rb_io_set_timeout(), rb_io_wait(), and rb_mutex_sleep().

◆ rb_time_nano_new()

VALUE rb_time_nano_new ( time_t  sec,
long  nsec 
)

Identical to rb_time_new(), except it accepts the time in nanoseconds resolution.

Parameters
[in]secSeconds since the UNIX epoch.
[in]nsecSubsecond part, in nanoseconds resolution.
Exceptions
rb_eRangeErrorCannot express the time.
Returns
An allocated instance of rb_cTime.

Definition at line 2744 of file time.c.

◆ rb_time_new()

VALUE rb_time_new ( time_t  sec,
long  usec 
)

Creates an instance of rb_cTime with the given time and the local timezone.

Parameters
[in]secSeconds since the UNIX epoch.
[in]usecSubsecond part, in microseconds resolution.
Exceptions
rb_eRangeErrorCannot express the time.
Returns
An allocated instance of rb_cTime.

Definition at line 2736 of file time.c.

◆ rb_time_num_new()

VALUE rb_time_num_new ( VALUE  timev,
VALUE  off 
)

Identical to rb_time_timespec_new(), except it takes Ruby values instead of C structs.

Parameters
[in]timevSomething numeric. Currently Integers, Rationals, and Floats are accepted.
[in]offOffset specifier. As of 2.7 this argument is heavily extended to take following kinds of objects:
  • RUBY_Qundef ... means UTC.
  • rb_cString ... "+12:34" etc.
  • A mysterious "zone" object. This is largely undocumented. However the initial intent was that we want to accept ActiveSupport::TimeZone here. Other gems could also be possible... But how to make an acceptable class is beyond this document.
Exceptions
rb_eArgErrorMalformed off.
Returns
An allocated instance of rb_cTime.

Definition at line 2773 of file time.c.

◆ rb_time_timespec()

struct timespec rb_time_timespec ( VALUE  time)

Identical to rb_time_timeval(), except for return type.

Parameters
[in]timeInstance of either rb_cTime or rb_cNumeric.
Exceptions
rb_eRangeErrortime is out of range of timeval::tv_sec.
Returns
A struct that represents the identical time to num.

Definition at line 2773 of file time.c.

◆ rb_time_timespec_interval()

struct timespec rb_time_timespec_interval ( VALUE  num)

Identical to rb_time_interval(), except for return type.

Parameters
[in]numAn instance of rb_cNumeric.
Exceptions
rb_eArgErrornum is negative.
rb_eRangeErrornum is out of range of timespec::tv_sec.
Returns
A struct that represents the identical time to num.

Definition at line 2773 of file time.c.

◆ rb_time_timespec_new()

VALUE rb_time_timespec_new ( const struct timespec ts,
int  offset 
)

Creates an instance of rb_cTime, with given time and offset.

Parameters
[in]tsTime specifier.
[in]offsetOffset specifier, can take following values:
  • INT_MAX: ts is in local time.
  • INT_MAX - 1: ts is in UTC.
  • -86400 to 86400: fixed timezone.
Exceptions
rb_eArgErrorMalformed offset.
Returns
An allocated instance of rb_cTime.

Definition at line 2750 of file time.c.

◆ rb_time_timeval()

struct timeval rb_time_timeval ( VALUE  time)

Converts an instance of rb_cTime to a struct timeval that represents the identical point of time.

It can also take something numeric; would consider it as a UNIX time then.

Parameters
[in]timeInstance of either rb_cTime or rb_cNumeric.
Exceptions
rb_eRangeErrortime is out of range of timeval::tv_sec.
Returns
A struct that represents the identical time to num.

Definition at line 2773 of file time.c.

Referenced by rb_thread_sleep().

◆ rb_time_utc_offset()

VALUE rb_time_utc_offset ( VALUE  time)

Queries the offset, in seconds between the time zone of the time and the UTC.

Parameters
[in]timeAn instance of rb_cTime.
Returns
Numeric offset.

Definition at line 5007 of file time.c.

◆ rb_timespec_now()

void rb_timespec_now ( struct timespec ts)

Fills the current time into the given struct.

Parameters
[out]tsReturn buffer.
Exceptions
rb_eSystemCallErrorAccess denied for hardware clock.
Postcondition
Current time is stored in *ts.

Definition at line 1947 of file time.c.