4 * Copyright (C) 2009 Andreas Waidler <arandes@programmers.at>
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.
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.
20 #include <libdatetime/DateTime.hxx>
22 #include <libdatetime/Date.hxx>
23 #include <libdatetime/Time.hxx>
30 DateTime::DateTime(const Timestamp
& timestamp
)/*{{{*/
32 , _ownsTimestamp(false)
42 DateTime::DateTime(Timestamp
* timestamp
)/*{{{*/
44 , _ownsTimestamp(false)
54 DateTime::DateTime(const Date
& date
, const Time
& time
)/*{{{*/
56 , _ownsTimestamp(false)
66 DateTime::DateTime(Date
* date
, Time
* time
)/*{{{*/
68 , _ownsTimestamp(false)
78 DateTime::~DateTime()/*{{{*/
84 const Timestamp
& DateTime::timestamp() const/*{{{*/
90 const Date
& DateTime::date() const/*{{{*/
96 const Time
& DateTime::time() const/*{{{*/
104 DateTime::DateTime()/*{{{*/
106 , _ownsTimestamp(false)
115 void DateTime::set(const Timestamp
& timestamp
)/*{{{*/
119 _timestamp
= ×tamp
;
120 _ownsTimestamp
= false;
126 void DateTime::set(Timestamp
* timestamp
)/*{{{*/
130 _timestamp
= timestamp
;
131 _ownsTimestamp
= true;
137 void DateTime::set(const Date
& date
, const Time
& time
)/*{{{*/
146 _allocateTimestamp();
150 void DateTime::set(Date
* date
, Time
* time
)/*{{{*/
159 _allocateTimestamp();
163 void DateTime::dispose()/*{{{*/
165 if (_ownsTimestamp
) {
182 void DateTime::_allocateTimestamp()/*{{{*/
184 _timestamp
= new Timestamp(abs(*_date
+ *_time
));
185 _ownsTimestamp
= true;
189 void DateTime::_allocateDateTime()/*{{{*/
191 _date
= new Date(*_timestamp
);
193 _time
= new Time(*_date
- *_timestamp
);
200 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
201 // vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker