GRU - Generic Reusable Utilities
|
#include <ctype.h>
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include "common/gru_alloc.h"
#include "common/gru_portable.h"
#include "gru_localtime.h"
Go to the source code of this file.
Macros | |
#define | GRU_TS_STRING_SEC_MAX 16 |
Maximum size for the second part for a GRU-parseable timestamp string. More... | |
#define | GRU_TS_STRING_USEC_MAX 7 |
Maximum size for the microsecond part for a GRU-parseable timestamp string. More... | |
#define | GRU_TS_STRING_MAX GRU_TS_STRING_SEC_MAX + GRU_TS_STRING_USEC_MAX + 1 |
Maximum size for a GRU-parseable timestamp string (ie.: seconds.microseconds) More... | |
Typedefs | |
typedef struct timeval | gru_timestamp_t |
An alias to struct timeval. More... | |
Functions | |
gru_export void | gru_time_add_microseconds (gru_timestamp_t *t, uint64_t count) |
Add microseconds to a timestamp object. More... | |
gru_export void | gru_time_add_seconds (gru_timestamp_t *t, uint64_t count) |
Add seconds to a timestamp object. More... | |
gru_export void | gru_time_add_minutes (gru_timestamp_t *t, uint64_t count) |
Add minutes to a timestamp object. More... | |
gru_export void | gru_time_add_hours (gru_timestamp_t *t, uint64_t count) |
Add hours to a timestamp object. More... | |
gru_export void | gru_time_add_days (gru_timestamp_t *t, uint64_t count) |
Add days to a timestamp object. More... | |
gru_export gru_timestamp_t | gru_time_read_str (const char *str) |
Read a string in the format seconds.microseconds and return a struct timeval. More... | |
gru_export char * | gru_time_write_str (const gru_timestamp_t *t) |
Write a timeval structure to a string. More... | |
gru_export char * | gru_time_write_format (const gru_timestamp_t *t, const char *format, gru_status_t *status) |
Writes the input timestamp value according to the given format. More... | |
gru_export gru_timestamp_t | gru_time_now () |
Gets the current moment in time. More... | |
gru_export uint64_t | gru_time_now_milli () |
Gets the current moment in time in milliseconds. More... | |
gru_export gru_timestamp_t | gru_time_from_milli_char (const char *ts) |
Converts an unformatted string of milliseconds since epoch to a timestamp. More... | |
gru_export gru_timestamp_t | gru_time_from_milli (int64_t timestamp) |
Converts milliseconds since epoch to a timestamp. More... | |
gru_export int64_t | gru_time_to_milli (const gru_timestamp_t *ts) |
Converts a timestamp to milliseconds. More... | |
gru_export int64_t | gru_time_elapsed_secs (gru_timestamp_t start, gru_timestamp_t end) |
Calculates the elapsed time between two timestamps. More... | |
gru_export int64_t | gru_time_elapsed_milli (gru_timestamp_t start, gru_timestamp_t end) |
Calculates the elapsed time between two timestamps. More... | |
#define GRU_TS_STRING_MAX GRU_TS_STRING_SEC_MAX + GRU_TS_STRING_USEC_MAX + 1 |
Maximum size for a GRU-parseable timestamp string (ie.: seconds.microseconds)
#define GRU_TS_STRING_SEC_MAX 16 |
Maximum size for the second part for a GRU-parseable timestamp string.
#define GRU_TS_STRING_USEC_MAX 7 |
Maximum size for the microsecond part for a GRU-parseable timestamp string.
typedef struct timeval gru_timestamp_t |
An alias to struct timeval.
gru_export void gru_time_add_days | ( | gru_timestamp_t * | t, |
uint64_t | count | ||
) |
Add days to a timestamp object.
t | timestamp |
count | number of days to add |
gru_export void gru_time_add_hours | ( | gru_timestamp_t * | t, |
uint64_t | count | ||
) |
Add hours to a timestamp object.
t | timestamp |
count | number of hours to add |
gru_export void gru_time_add_microseconds | ( | gru_timestamp_t * | t, |
uint64_t | count | ||
) |
Add microseconds to a timestamp object.
t | timestamp |
count | number of microseconds to add |
Add microseconds to a timestamp object.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
gru_export void gru_time_add_minutes | ( | gru_timestamp_t * | t, |
uint64_t | count | ||
) |
Add minutes to a timestamp object.
t | timestamp |
count | number of minutes to add |
gru_export void gru_time_add_seconds | ( | gru_timestamp_t * | t, |
uint64_t | count | ||
) |
Add seconds to a timestamp object.
t | timestamp |
count | number of seconds to add |
gru_export int64_t gru_time_elapsed_milli | ( | gru_timestamp_t | start, |
gru_timestamp_t | end | ||
) |
Calculates the elapsed time between two timestamps.
start | Start time |
end | End time |
gru_export int64_t gru_time_elapsed_secs | ( | gru_timestamp_t | start, |
gru_timestamp_t | end | ||
) |
Calculates the elapsed time between two timestamps.
start | Start time |
end | End time |
gru_export gru_timestamp_t gru_time_from_milli | ( | int64_t | timestamp | ) |
Converts milliseconds since epoch to a timestamp.
timestamp | milliseconds since Epoch |
gru_export gru_timestamp_t gru_time_from_milli_char | ( | const char * | ts | ) |
Converts an unformatted string of milliseconds since epoch to a timestamp.
ts | A numeric string representing the milliseconds since epoch (ie.: 1484719545264) |
gru_export gru_timestamp_t gru_time_now | ( | ) |
Gets the current moment in time.
gru_export uint64_t gru_time_now_milli | ( | ) |
Gets the current moment in time in milliseconds.
gru_export gru_timestamp_t gru_time_read_str | ( | const char * | str | ) |
Read a string in the format seconds.microseconds and return a struct timeval.
The microseconds represents the fraction of the seconds value and should not be equal or greater than 1000000. Otherwise, the code will only consider the first 6 bytes of the microseconds string.
str | The string in the format seconds.microseconds |
gru_export int64_t gru_time_to_milli | ( | const gru_timestamp_t * | ts | ) |
Converts a timestamp to milliseconds.
ts | A pointer to a timestamp structure |
gru_export char * gru_time_write_format | ( | const gru_timestamp_t * | t, |
const char * | format, | ||
gru_status_t * | status | ||
) |
Writes the input timestamp value according to the given format.
t | Input timestamp structure |
format | output format |
status | status structure that may contain error details in case of failure |
gru_export char * gru_time_write_str | ( | const gru_timestamp_t * | t | ) |
Write a timeval structure to a string.
t | the timeval structure |