00001 /* 00002 Copyright 2016 Otavio Rodolfo Piske 00003 00004 Licensed under the Apache License, Version 2.0 (the "License"); 00005 you may not use this file except in compliance with the License. 00006 You may obtain a copy of the License at 00007 00008 http://www.apache.org/licenses/LICENSE-2.0 00009 00010 Unless required by applicable law or agreed to in writing, software 00011 distributed under the License is distributed on an "AS IS" BASIS, 00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 See the License for the specific language governing permissions and 00014 limitations under the License. 00015 */ 00016 #ifndef GRU_TIME_UTILS_H 00017 #define GRU_TIME_UTILS_H 00018 00019 #include <ctype.h> 00020 #include <inttypes.h> 00021 #include <math.h> 00022 #include <stdint.h> 00023 #include <stdlib.h> 00024 00025 #if !defined(_WIN32) && !defined(_WIN64) 00026 #include <sys/time.h> 00027 #include <unistd.h> 00028 #else 00029 #include <windows.h> 00030 #endif 00031 00032 #include "common/gru_alloc.h" 00033 #include "common/gru_portable.h" 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif 00038 00042 typedef struct timeval gru_timestamp_t; 00043 00049 gru_export void gru_time_add_seconds(gru_timestamp_t *t, uint64_t count); 00050 00056 gru_export void gru_time_add_minutes(gru_timestamp_t *t, uint64_t count); 00057 00066 gru_export gru_timestamp_t gru_time_read_str(const char *str); 00067 00073 gru_export char *gru_time_write_str(const gru_timestamp_t *t); 00074 00079 gru_export gru_timestamp_t gru_time_now(); 00080 00085 gru_export uint64_t gru_time_now_milli(); 00086 00093 gru_export gru_timestamp_t gru_time_from_milli_char(const char *ts); 00094 00100 gru_export gru_timestamp_t gru_time_from_milli(int64_t timestamp); 00101 00107 gru_export uint64_t gru_time_to_milli(const gru_timestamp_t *ts); 00108 00109 #ifdef __cplusplus 00110 } 00111 #endif 00112 00113 #endif /* GRU_TIME_UTILS_H */