Asterisk - The Open Source Telephony Project GIT-master-d856a3e
|
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. More... | |
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.
time_t ast_string_to_time_t | ( | const char * | str | ) |
Returns a time_t from a string containing seconds since the epoch.
Definition at line 163 of file time.c.
Referenced by bucket_file_expired(), evaluate_equal(), evaluate_greater_than(), and evaluate_less_than().
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_TEST_DEFINE(), 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(), normalize_and_create(), TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MICROSECOND, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_MONTH, TIME_UNIT_NANOSECOND, TIME_UNIT_SECOND, TIME_UNIT_WEEK, and TIME_UNIT_YEAR.
Referenced by AST_TEST_DEFINE(), and 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().
Referenced by AST_TEST_DEFINE().
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.
References MAX_UNIT_LABELS, TIME_UNIT_ERROR, time_unit_labels::unit, unit_labels, and unit_labels_size.
Referenced by AST_TEST_DEFINE(), and 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.
References buf, and localtime_r.
Referenced by ast_sip_format_contact_ami(), bucket_file_set_expiration(), caldav_add_event(), check_expiration_thread(), display_single_entry(), expiration_struct2str(), icalendar_add_event(), odbc_obj_connect(), persistence_expires_struct2str(), and sprint_list_entry().
ast_suseconds_t ast_time_tv_to_usec | ( | const struct timeval * | tv | ) |
Convert a timeval structure to microseconds.
tv | The timeval to convert |
Definition at line 90 of file time.c.
Referenced by AST_TEST_DEFINE().
|
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().
const char* microsecond_labels[] = {"us", "usec", "microsecond"} |
const char* millisecond_labels[] = {"ms", "msec", "millisecond"} |
const char* nanosecond_labels[] = {"ns", "nsec", "nanosecond"} |
|
static |
Definition at line 51 of file time.c.
Referenced by ast_time_str_to_unit().
const unsigned int unit_labels_size = sizeof(unit_labels) / sizeof(0[unit_labels]) |
Definition at line 64 of file time.c.
Referenced by ast_time_str_to_unit().