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_DURATION_H 00017 #define GRU_DURATION_H 00018 00019 #include <math.h> 00020 #include <stdlib.h> 00021 00022 #if !defined(_WIN32) && !defined(_WIN64) 00023 #include <sys/time.h> 00024 #else 00025 #include <windows.h> 00026 #endif 00027 00028 #include "common/gru_portable.h" 00029 #include "gru_time_utils.h" 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00035 typedef struct gru_duration_t_ { 00036 struct timeval start; 00037 struct timeval end; 00038 } gru_duration_t; 00039 00040 00045 gru_export gru_duration_t gru_duration_new(); 00046 00053 gru_export gru_duration_t gru_duration_from_seconds(uint64_t seconds); 00054 00061 gru_export gru_duration_t gru_duration_from_minutes(uint64_t minutes); 00062 00069 gru_export uint64_t gru_duration_seconds(gru_duration_t duration); 00070 00077 gru_export uint64_t gru_duration_minutes(gru_duration_t duration, double *fractional); 00078 00079 00089 gru_export bool gru_duration_parse(gru_duration_t *out, const char *str); 00090 00091 #ifdef __cplusplus 00092 } 00093 #endif 00094 00095 #endif /* GRU_DURATION_H */