Asterisk - The Open Source Telephony Project
18.5.0
|
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 | |
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... | |
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 onverting 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.
#define MAX_UNIT_LABELS 3 |
Definition at line 43 of file time.c.
Referenced by ast_time_str_to_unit().
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 94 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 112 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, TIME_UNIT_YEAR, and time_unit_labels::unit.
Referenced by AST_TEST_DEFINE(), ast_time_create_by_unit_str(), and drop_packets_data_update().
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 142 of file time.c.
References ast_time_create_by_unit(), ast_time_str_to_unit(), and time_unit_labels::unit.
Referenced by AST_TEST_DEFINE(), and handle_cli_rtp_drop_incoming_packets().
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, miscroseconds, or even microsecondvals
Matching is also not case sensitive.
unit | The string to map to an enumeration |
Definition at line 65 of file time.c.
References MAX_UNIT_LABELS, TIME_UNIT_ERROR, time_unit_labels::unit, and unit_labels_size.
Referenced by AST_TEST_DEFINE(), and ast_time_create_by_unit_str().
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 89 of file time.c.
Referenced by AST_TEST_DEFINE(), and drop_packets_data_update().
|
static |
Create a timeval first onverting the given microsecond value into seconds and microseconds.
usec | microsecond value |
Definition at line 107 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 |
const unsigned int unit_labels_size = sizeof(unit_labels) / sizeof(0[unit_labels]) |
Definition at line 63 of file time.c.
Referenced by ast_time_str_to_unit().