Added a few unittests + bugfix in Year
[libdatetime.git] / src / Time.cxx
blob6135c1b54dddcc01f3caf1698cc76c448cde3259
1 /*{{{ LICENCE
3 * libdatetime
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.
18 *}}}*/
20 #include <libdatetime/Time.hxx>
22 namespace libdatetime
24 Time::Time(unsigned int seconds)/*{{{*/
25 : _totalSeconds(seconds)
26 , _hours(0)
27 , _minutes(0)
28 , _seconds(seconds)
30 _hours = _seconds / (60 * 60);
31 _seconds -= _hours * 60 * 60;
33 _minutes = _seconds / 60;
34 _seconds -= _minutes * 60;
37 /*}}}*/
38 unsigned int Time::hours() const/*{{{*/
40 return _hours;
43 /*}}}*/
44 unsigned int Time::minutes() const/*{{{*/
46 return _minutes;
49 /*}}}*/
50 unsigned int Time::seconds() const/*{{{*/
52 return _seconds;
55 /*}}}*/
56 Time::operator int() const/*{{{*/
58 return _totalSeconds;
61 /*}}}*/
62 Time& Time::operator++()/*{{{*/
64 if (59 == _seconds) {
65 if (59 == _minutes) {
66 ++_hours;
67 _minutes = 0;
68 } else {
69 ++_minutes;
71 _seconds = 0;
72 } else {
73 ++_seconds;
76 return *this;
79 /*}}}*/
80 Time Time::operator++(int noop)/*{{{*/
82 Time pre(*this);
83 ++(*this);
85 return pre;
88 /*}}}*/
89 Time& Time::operator--()/*{{{*/
91 if (0 == _seconds) {
92 if (0 == _minutes) {
93 --_hours;
94 _minutes = 59;
95 } else {
96 --_minutes;
98 _seconds = 59;
99 } else {
100 --_seconds;
103 return *this;
106 /*}}}*/
107 Time Time::operator--(int noop)/*{{{*/
109 Time pre(*this);
110 --(*this);
112 return pre;
115 /*}}}*/
118 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
119 // vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker