GRU - Generic Reusable Utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
gru_time_utils.h
Go to the documentation of this file.
1 /*
2  Copyright 2016 Otavio Rodolfo Piske
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 #ifndef GRU_TIME_UTILS_H
17 #define GRU_TIME_UTILS_H
18 
19 #include <ctype.h>
20 #include <inttypes.h>
21 #include <math.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 
25 #if !defined(_WIN32) && !defined(_WIN64)
26 #include <sys/time.h>
27 #include <unistd.h>
28 #else
29 #include <windows.h>
30 #endif
31 
32 #include "common/gru_alloc.h"
33 #include "common/gru_portable.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
42 typedef struct timeval gru_timestamp_t;
43 
49 gru_export void gru_time_add_seconds(gru_timestamp_t *t, uint64_t count);
50 
56 gru_export void gru_time_add_minutes(gru_timestamp_t *t, uint64_t count);
57 
67 
74 
80 
86 
94 
101 
107 gru_export uint64_t gru_time_to_milli(const gru_timestamp_t *ts);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* GRU_TIME_UTILS_H */
uint64_t gru_time_to_milli(const gru_timestamp_t *ts)
Converst a timestamp to milliseconds.
Definition: gru_time_utils.c:97
gru_timestamp_t gru_time_from_milli_char(const char *ts)
Converts an unformatted string of milliseconds since epoch to a timestamp.
Definition: gru_time_utils.c:91
struct timeval gru_timestamp_t
An alias to struct timeval.
Definition: gru_time_utils.h:42
uint64_t gru_time_now_milli()
Gets the current moment in time in milliseconds.
Definition: gru_time_utils.c:72
#define gru_export
Definition: gru_portable.h:19
gru_timestamp_t gru_time_read_str(const char *str)
Read a string in the format seconds.microseconds and return a struct timeval.
Definition: gru_time_utils.c:26
void gru_time_add_minutes(gru_timestamp_t *t, uint64_t count)
Add minutes to a timestamp object.
Definition: gru_time_utils.c:22
char * gru_time_write_str(const gru_timestamp_t *t)
Write a timeval structure to a string.
Definition: gru_time_utils.c:55
gru_timestamp_t gru_time_now()
Gets the current moment in time.
Definition: gru_time_utils.c:65
gru_timestamp_t gru_time_from_milli(int64_t timestamp)
Converts milliseconds since epoch to a timestamp.
Definition: gru_time_utils.c:78
void gru_time_add_seconds(gru_timestamp_t *t, uint64_t count)
Copyright 2016 Otavio Rodolfo Piske.
Definition: gru_time_utils.c:18