Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
time_util.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
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 
21 #ifndef TIME_UTIL_H
22 #define TIME_UTIL_H
23 
24 #include <time.h>
25 
26 #include "typedefs.h"
28 
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 
46 GRASSROOTS_UTIL_API bool ConvertCompactStringToTime (const char * const time_s, struct tm *time_p, int *offset_p);
47 
48 
58 GRASSROOTS_UTIL_API bool ConvertCompactStringToEpochTime (const char * const time_s, time_t *time_p);
59 
60 
61 
72 GRASSROOTS_UTIL_API bool ConvertDropboxStringToTime (const char * const time_s, struct tm *time_p, int *offset_p);
73 
74 
84 GRASSROOTS_UTIL_API bool ConvertDropboxStringToEpochTime (const char * const time_s, time_t *time_p);
85 
86 
87 
95 GRASSROOTS_UTIL_API bool GetPresentTime (struct tm *tm_p);
96 
97 
98 
113 GRASSROOTS_UTIL_API char *GetTimeAsString (const struct tm * const time_p, const bool include_time_flag, const char *time_delimiter_p);
114 
123 GRASSROOTS_UTIL_API void FreeTimeString (char *time_s);
124 
125 
134 GRASSROOTS_UTIL_API bool SetTimeFromString (struct tm * const time_p, const char *time_s);
135 
136 
137 
146 GRASSROOTS_UTIL_API bool SetTimeFromDDMMYYYYString (struct tm * const time_p, const char *time_s);
147 
148 
149 
150 GRASSROOTS_UTIL_API struct tm *GetTimeFromString (const char *time_s);
151 
152 
160 GRASSROOTS_UTIL_API void AddIntervalToTime (struct tm *time_p, const int days);
161 
162 
171 GRASSROOTS_UTIL_API struct tm *AllocateTime (void);
172 
173 
180 GRASSROOTS_UTIL_API void FreeTime (struct tm *time_p);
181 
182 
190 GRASSROOTS_UTIL_API void CopyTime (const struct tm *src_p, struct tm *dest_p);
191 
200 GRASSROOTS_UTIL_API struct tm *DuplicateTime (const struct tm *src_p);
201 
202 
211 GRASSROOTS_UTIL_API void SetDateValuesForTime (struct tm *time_p, const int year, const int month, const int day);
212 
213 
214 GRASSROOTS_UTIL_API void ClearTime (struct tm *time_p);
215 
216 
217 GRASSROOTS_UTIL_API bool IsValidDate (struct tm *time_p);
218 
219 
231 GRASSROOTS_UTIL_API int CompareDates (const struct tm *time_0_p, const struct tm *time_1_p, const bool dates_only_flag);
232 
233 
234 
235 GRASSROOTS_UTIL_API bool MayStringIncludeTime (const char * const time_s);
236 
237 
238 GRASSROOTS_UTIL_API void FreeTimeArray (struct tm **values_pp, const size_t num_values);
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 
245 #endif /* #ifndef TIME_UTIL_H */
246 
GetPresentTime
bool GetPresentTime(struct tm *tm_p)
Get the current time.
AllocateTime
struct tm * AllocateTime(void)
Allocate a struct tm variable and set all of its values to 0.
grassroots_util_library.h
DuplicateTime
struct tm * DuplicateTime(const struct tm *src_p)
Make a deep copy of a struct tm.
FreeTime
void FreeTime(struct tm *time_p)
Free a struct tm variable allocated by AllocateTime().
SetTimeFromDDMMYYYYString
bool SetTimeFromDDMMYYYYString(struct tm *const time_p, const char *time_s)
Set the time from a string of the form DD-MM-YYYY.
SetDateValuesForTime
void SetDateValuesForTime(struct tm *time_p, const int year, const int month, const int day)
Set the year, month and day values for a struct tm.
GetTimeFromString
struct tm * GetTimeFromString(const char *time_s)
GetTimeAsString
char * GetTimeAsString(const struct tm *const time_p, const bool include_time_flag, const char *time_delimiter_p)
Get a time as a string in the ISO 8601 format.
AddIntervalToTime
void AddIntervalToTime(struct tm *time_p, const int days)
Add a number of days to a time.
ConvertDropboxStringToTime
bool ConvertDropboxStringToTime(const char *const time_s, struct tm *time_p, int *offset_p)
Convert a string that is of the form "Sat, 21 Aug 2010 22:31:20 +0000" ("%a, %d %b %Y %H:%M:%S %z") i...
CopyTime
void CopyTime(const struct tm *src_p, struct tm *dest_p)
Copy the values from one struct tm to another.
ConvertCompactStringToEpochTime
bool ConvertCompactStringToEpochTime(const char *const time_s, time_t *time_p)
Convert a string that is of the form YYYYMMDD or YYYYMMDDhhmmss into a time_t.
typedefs.h
IsValidDate
bool IsValidDate(struct tm *time_p)
FreeTimeString
void FreeTimeString(char *time_s)
Free a string previsouly-generated from GetTimeAsString().
ClearTime
void ClearTime(struct tm *time_p)
ConvertDropboxStringToEpochTime
bool ConvertDropboxStringToEpochTime(const char *const time_s, time_t *time_p)
Convert a string that is of the form "Sat, 21 Aug 2010 22:31:20 +0000" ("%a, %d %b %Y %H:%M:%S %z") i...
ConvertCompactStringToTime
bool ConvertCompactStringToTime(const char *const time_s, struct tm *time_p, int *offset_p)
Convert a string that is of the form YYYYMMDD or YYYYMMDDhhmmss into a struct tm.
SetTimeFromString
bool SetTimeFromString(struct tm *const time_p, const char *time_s)
Set the time from a string in the ISO 8601 format.
FreeTimeArray
void FreeTimeArray(struct tm **values_pp, const size_t num_values)
CompareDates
int CompareDates(const struct tm *time_0_p, const struct tm *time_1_p, const bool dates_only_flag)
Compare two dates chronologically.
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47
MayStringIncludeTime
bool MayStringIncludeTime(const char *const time_s)