Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Time Routines
[Brought To You By APR]


Data Structures

struct  switch_time_exp_t

Typedefs

typedef int64_t switch_time_t
typedef int64_t switch_interval_time_t
typedef switch_time_exp_t switch_time_exp_t

Functions

switch_time_t switch_time_make (switch_time_t sec, int32_t usec)
switch_time_t switch_time_now (void)
switch_status_t switch_time_exp_gmt_get (switch_time_t *result, switch_time_exp_t *input)
switch_status_t switch_strftime (char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
switch_status_t switch_rfc822_date (char *date_str, switch_time_t t)
switch_status_t switch_time_exp_gmt (switch_time_exp_t *result, switch_time_t input)
switch_status_t switch_time_exp_get (switch_time_t *result, switch_time_exp_t *input)
switch_status_t switch_time_exp_lt (switch_time_exp_t *result, switch_time_t input)
switch_status_t switch_time_exp_tz (switch_time_exp_t *result, switch_time_t input, switch_int32_t offs)
void switch_sleep (switch_interval_time_t t)


Typedef Documentation

typedef int64_t switch_interval_time_t
 

number of microseconds in the interval

typedef struct switch_time_exp_t switch_time_exp_t
 

a structure similar to ANSI struct tm with the following differences:

  • tm_usec isn't an ANSI field
  • tm_gmtoff isn't an ANSI field (it's a bsdism)

typedef int64_t switch_time_t
 

number of microseconds since 00:00:00 january 1, 1970 UTC


Function Documentation

switch_status_t switch_rfc822_date char *  date_str,
switch_time_t  t
 

switch_rfc822_date formats dates in the RFC822 format in an efficient manner. It is a fixed length format which requires the indicated amount of storage, including the trailing NUL terminator.

Parameters:
date_str String to write to.
t the time to convert
00260 {
00261         return apr_rfc822_date(date_str, t);
00262 }

void switch_sleep switch_interval_time_t  t  ) 
 

Sleep for the specified number of micro-seconds.

Parameters:
t desired amount of time to sleep.
Warning:
May sleep for longer than the specified time.
00140 {
00141 
00142 #if defined(HAVE_USLEEP)
00143         usleep(t);
00144 #elif defined(WIN32)
00145         Sleep((DWORD) ((t) / 1000));
00146 #else
00147         apr_sleep(t);
00148 #endif
00149 
00150 #if 0
00151 #if defined(HAVE_CLOCK_NANOSLEEP) && defined(SWITCH_USE_CLOCK_FUNCS)
00152         struct timespec ts;
00153         ts.tv_sec = t / APR_USEC_PER_SEC;
00154         ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
00155 
00156         clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
00157 
00158 #elif defined(HAVE_USLEEP)
00159         usleep(t);
00160 #elif defined(WIN32)
00161         Sleep((DWORD) ((t) / 1000));
00162 #else
00163         apr_sleep(t);
00164 #endif
00165 #endif
00166 
00167 }

switch_status_t switch_strftime char *  s,
switch_size_t retsize,
switch_size_t  max,
const char *  format,
switch_time_exp_t tm
 

formats the exploded time according to the format specified

Parameters:
s string to write to
retsize The length of the returned string
max The maximum length of the string
format The format for the time string
tm The time to convert
00106 {
00107         return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
00108 }

switch_status_t switch_time_exp_get switch_time_t result,
switch_time_exp_t input
 

Convert time value from human readable format to a numeric apr_time_t e.g. elapsed usec since epoch

Parameters:
result the resulting imploded time
input the input exploded time
00240 {
00241         return apr_time_exp_get(result, (apr_time_exp_t *) input);
00242 }

switch_status_t switch_time_exp_gmt switch_time_exp_t result,
switch_time_t  input
 

convert a time to its human readable components in GMT timezone

Parameters:
result the exploded time
input the time to explode
00255 {
00256         return apr_time_exp_gmt((apr_time_exp_t *) result, input);
00257 }

switch_status_t switch_time_exp_gmt_get switch_time_t result,
switch_time_exp_t input
 

Convert time value from human readable format to a numeric apr_time_t that always represents GMT

Parameters:
result the resulting imploded time
input the input exploded time
00235 {
00236         return apr_time_exp_gmt_get(result, (apr_time_exp_t *) input);
00237 }

switch_status_t switch_time_exp_lt switch_time_exp_t result,
switch_time_t  input
 

convert a time to its human readable components in local timezone

Parameters:
result the exploded time
input the time to explode
00245 {
00246         return apr_time_exp_lt((apr_time_exp_t *) result, input);
00247 }

switch_status_t switch_time_exp_tz switch_time_exp_t result,
switch_time_t  input,
switch_int32_t  offs
 

convert a time to its human readable components in a specific timezone with offset

Parameters:
result the exploded time
input the time to explode
00250 {
00251         return apr_time_exp_tz((apr_time_exp_t *) result, input, (apr_int32_t )offs);
00252 }

switch_time_t switch_time_make switch_time_t  sec,
int32_t  usec
 

00265 {
00266         return ((switch_time_t) (sec) * APR_USEC_PER_SEC + (switch_time_t) (usec));
00267 }

switch_time_t switch_time_now void   ) 
 

Returns:
the current time
00224 {
00225 #if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS)
00226         struct timespec ts;
00227         clock_gettime(CLOCK_REALTIME, &ts);
00228         return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000);
00229 #else
00230         return (switch_time_t) apr_time_now();
00231 #endif
00232 }


Generated on Fri Oct 10 11:24:22 2008 for FreeSWITCH by  doxygen 1.3.9.1