Mercurial > code
comparison C++/modules/Date/Date.cpp @ 334:0b576ee64d45
* Create brand new hierarchy
* Rename DynLib to Dynlib
* Remove some warnings
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 08 Mar 2015 14:26:33 +0100 |
parents | C++/Date.cpp@2bfe43b85d7f |
children | 412c3e26bb40 |
comparison
equal
deleted
inserted
replaced
333:412ca7a5e1ea | 334:0b576ee64d45 |
---|---|
1 /* | |
2 * Date.cpp -- date and time manipulation | |
3 * | |
4 * Copyright (c) 2011, 2012, 2013 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 #include "Date.h" | |
20 | |
21 Date::Date() | |
22 { | |
23 m_timestamp = time(NULL); | |
24 } | |
25 | |
26 Date::Date(time_t timestamp) | |
27 { | |
28 m_timestamp = timestamp; | |
29 } | |
30 | |
31 Date::~Date() | |
32 { | |
33 } | |
34 | |
35 time_t Date::getTimestamp() const | |
36 { | |
37 return m_timestamp; | |
38 } | |
39 | |
40 std::string Date::format(const std::string &format) | |
41 { | |
42 char buffer[512]; | |
43 struct tm *tm; | |
44 | |
45 tm = localtime(&m_timestamp); | |
46 strftime(buffer, sizeof (buffer), format.c_str(), tm); | |
47 | |
48 return std::string(buffer); | |
49 } | |
50 | |
51 bool operator==(const Date &d1, const Date &d2) | |
52 { | |
53 return d1.getTimestamp() == d2.getTimestamp(); | |
54 } | |
55 | |
56 bool operator<=(const Date &d1, const Date &d2) | |
57 { | |
58 return d1.getTimestamp() <= d2.getTimestamp(); | |
59 } |