Added a few unittests + bugfix in Year
[libdatetime.git] / src / Timestamp.cxx
blob6d05acea30abfadd6700984f981833f738f8f2ae
1 /*{{{ LICENCE
3 * libdatetime
4 * Copyright (C) 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.
18 *}}}*/
20 #include <ctime>
21 #include <libdatetime/Timestamp.hxx>
23 namespace libdatetime
25 Timestamp::Timestamp()/*{{{*/
26 : _raw(0)
28 // TODO: Check return value, must not be -1.
29 time_t tmp;
30 time(&tmp);
31 // _raw = static_cast<int>(tmp);
32 _raw = tmp;
35 /*}}}*/
36 Timestamp::Timestamp(int time)/*{{{*/
37 : _raw(time)
41 /*}}}*/
42 Timestamp::~Timestamp()/*{{{*/
46 /*}}}*/
47 Timestamp::operator int() const/*{{{*/
49 return _raw;
52 /*}}}*/
53 Timestamp& Timestamp::operator++()/*{{{*/
55 ++_raw;
56 return *this;
59 /*}}}*/
60 Timestamp Timestamp::operator++(int noop)/*{{{*/
62 Timestamp pre(_raw);
63 ++_raw;
64 return pre;
67 /*}}}*/
68 Timestamp& Timestamp::operator--()/*{{{*/
70 --_raw;
71 return *this;
74 /*}}}*/
75 Timestamp Timestamp::operator--(int noop)/*{{{*/
77 Timestamp pre(_raw);
78 --_raw;
79 return pre;
82 /*}}}*/
83 Timestamp& Timestamp::operator=(int rhs)/*{{{*/
85 _raw = rhs;
86 return *this;
89 /*}}}*/
90 Timestamp& Timestamp::operator+=(int rhs)/*{{{*/
92 _raw += rhs;
93 return *this;
96 /*}}}*/
97 Timestamp& Timestamp::operator-=(int rhs)/*{{{*/
99 _raw -= rhs;
100 return *this;
103 /*}}}*/
106 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
107 // vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker