comparison modules/date/date.h @ 486:7ee8da32da98

Unify all in modules/
author David Demelier <markand@malikania.fr>
date Fri, 13 Nov 2015 09:26:46 +0100
parents
children f48bb09bccc7
comparison
equal deleted inserted replaced
485:898d8b29a4f1 486:7ee8da32da98
1 /*
2 * date.h -- date and time manipulation
3 *
4 * Copyright (c) 2011-2015 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef _DATE_H_
20 #define _DATE_H_
21
22 /**
23 * @file date.h
24 * @brief Basic date management.
25 */
26
27 #include <cstdint>
28 #include <ctime>
29 #include <string>
30
31 /**
32 * @class Date
33 * @brief Basic date class and format.
34 */
35 class Date {
36 private:
37 time_t m_timestamp;
38
39 public:
40 /**
41 * Default constructor to the current date.
42 */
43 Date();
44
45 /**
46 * Date with specific timestamp.
47 *
48 * @param timestamp the timestamp
49 */
50 Date(time_t timestamp);
51
52 /**
53 * Get the timestamp.
54 *
55 * @return the timestamp
56 */
57 inline time_t timestamp() const noexcept
58 {
59 return m_timestamp;
60 }
61
62 /**
63 * Format the current that in the specified format,
64 * see strftime(3) for patterns.
65 *
66 * @param format the format
67 * @return the date formated
68 */
69 std::string format(const std::string &format);
70 };
71
72 /**
73 * Check is two dates are identical.
74 *
75 * @param d1 the first date
76 * @param d2 the second date
77 * @return true if same
78 */
79 bool operator==(const Date &d1, const Date &d2);
80
81 /**
82 * Check is a date is less or equal the second date.
83 *
84 * @param d1 the first date
85 * @param d2 the second date
86 * @return true if d1 <= d2
87 */
88 bool operator<=(const Date &d1, const Date &d2);
89
90 #endif // !_DATE_H_