Asterisk - The Open Source Telephony Project
21.4.1
|
Date/Time utility functions. More...
Go to the source code of this file.
Data Structures | |
struct | time_unit_labels |
Macros | |
#define | MAX_UNIT_LABELS 3 |
Functions | |
time_t | ast_string_to_time_t (const char *str) |
Returns a time_t from a string containing seconds since the epoch. | |
struct timeval | ast_time_create (ast_time_t sec, ast_suseconds_t usec) |
Create a timeval object initialized to given values. More... | |
struct timeval | ast_time_create_by_unit (unsigned long val, enum TIME_UNIT unit) |
Convert the given unit value, and create a timeval object from it. More... | |
struct timeval | ast_time_create_by_unit_str (unsigned long val, const char *unit) |
Convert the given unit value, and create a timeval object from it. More... | |
enum TIME_UNIT | ast_time_str_to_unit (const char *unit) |
Convert a string to a time unit enumeration value. More... | |
int | ast_time_t_to_string (time_t time, char *buf, size_t length) |
Returns a string representation of a time_t as decimal seconds since the epoch. More... | |
ast_suseconds_t | ast_time_tv_to_usec (const struct timeval *tv) |
Convert a timeval structure to microseconds. More... | |
static struct timeval | normalize_and_create (unsigned long usec) |
Create a timeval first converting the given microsecond value into seconds and microseconds. More... | |
Variables | |
const char * | day_labels [] = {"d", "", "day"} |
const char * | hour_labels [] = {"h", "hr", "hour"} |
const char * | microsecond_labels [] = {"us", "usec", "microsecond"} |
const char * | millisecond_labels [] = {"ms", "msec", "millisecond"} |
const char * | minute_labels [] = {"m", "min", "minute"} |
const char * | month_labels [] = {"mo", "mth", "month"} |
const char * | nanosecond_labels [] = {"ns", "nsec", "nanosecond"} |
const char * | second_labels [] = {"s", "sec", "second"} |
static struct time_unit_labels | unit_labels [] |
const unsigned int | unit_labels_size = sizeof(unit_labels) / sizeof(0[unit_labels]) |
const char * | week_labels [] = {"w", "wk", "week"} |
const char * | year_labels [] = {"y", "yr", "year"} |
Date/Time utility functions.
Definition in file time.c.
struct timeval ast_time_create | ( | ast_time_t | sec, |
ast_suseconds_t | usec | ||
) |
Create a timeval object initialized to given values.
sec | The timeval seconds value |
usec | The timeval microseconds value |
Definition at line 95 of file time.c.
References ast_tv().
Referenced by ast_time_create_by_unit(), and normalize_and_create().
struct timeval ast_time_create_by_unit | ( | unsigned long | val, |
enum TIME_UNIT | unit | ||
) |
Convert the given unit value, and create a timeval object from it.
val | The value to convert to a timeval |
unit | The time unit type of val |
Definition at line 113 of file time.c.
References ast_time_create(), and normalize_and_create().
Referenced by ast_time_create_by_unit_str().
struct timeval ast_time_create_by_unit_str | ( | unsigned long | val, |
const char * | unit | ||
) |
Convert the given unit value, and create a timeval object from it.
This will first attempt to convert the unit from a string to a TIME_UNIT enumeration. If that conversion fails then a zeroed out timeval object is returned.
val | The value to convert to a timeval |
unit | The time unit type of val |
Definition at line 143 of file time.c.
References ast_time_create_by_unit(), and ast_time_str_to_unit().
enum TIME_UNIT ast_time_str_to_unit | ( | const char * | unit | ) |
Convert a string to a time unit enumeration value.
This method attempts to be as flexible, and forgiving as possible when converting. In most cases the algorithm will match on the beginning of up to three strings (short, medium, long form). So that means if the given string at least starts with one of the form values it will match.
For example: us, usec, microsecond will all map to TIME_UNIT_MICROSECOND. So will uss, usecs, microseconds, or even microsecondvals
Matching is also not case sensitive.
unit | The string to map to an enumeration |
Definition at line 66 of file time.c.
Referenced by ast_time_create_by_unit_str().
int ast_time_t_to_string | ( | time_t | time, |
char * | buf, | ||
size_t | length | ||
) |
Returns a string representation of a time_t as decimal seconds since the epoch.
Converts to a string representation of a time_t as decimal seconds since the epoch. Returns -1 on failure, zero otherwise.
Definition at line 152 of file time.c.
Referenced by display_single_entry(), and sprint_list_entry().
ast_suseconds_t ast_time_tv_to_usec | ( | const struct timeval * | tv | ) |
|
static |
Create a timeval first converting the given microsecond value into seconds and microseconds.
usec | microsecond value |
Definition at line 108 of file time.c.
References ast_time_create().
Referenced by ast_time_create_by_unit().