Debian Codegraph @

src/libs/datetime/datetime_utils.hpp

raw
1 /*
2 * This File is part of Davix, The IO library for HTTP based protocols
3 * Copyright (C) 2013 Adrien Devresse <[email protected]>, CERN
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #ifndef DATETIME_UTILS_HPP
22 #define DATETIME_UTILS_HPP
23
24 #include <string.h>
25 #include <time.h>
26 #include <string>
27
28 #define DATETIME_UTILS_PARSE_ERROR 1
29 #define DATETIME_UTILS_CONV_ERROR 2
30
31
32 /**
33 parse an http standard date to a posix time
34 @param http_date http string of the date
35 @return posix time or -1 if error occures
36 */
37 time_t parse_http_date(const char* http_date);
38
39 /**
40 parse a iso 8601 date to a posix time
41 @param iso8601_date http string of the date
42 @param err : Gerror error report system
43 @return posix time or -1 if error occures and err is set
44 */
45 time_t parse_iso8601date(const char* http_date);
46
47 /**
48 parse both of iso 8601 and http standard date to a posix time
49 @param http or iso8601 date
50 @return posix time or -1 if error occures
51 */
52 time_t parse_standard_date(const char* http_date);
53
54 namespace Davix {
55
56 /**
57 give current time as string
58 @param the format string to pass to strftime
59 @return the current time using the requested formatting
60 */
61 std::string current_time(const std::string format);
62
63 /**
64 format time_t to string
65 @param the time
66 @param the format string to pass to strftime
67 @return a string using the requested formatting
68 */
69 std::string time_as_string(const time_t t, const std::string format);
70
71 }
72
73 #endif // DATETIME_UTILS_HPP