libcommonc++  0.7
Time.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Time_hxx
24 #define __ccxx_Time_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 #include <ctime>
29 
30 namespace ccxx {
31 
38 {
39  public:
40 
42  Time();
43 
45  Time(uint_t hour, uint_t minute, uint_t second = 0, uint_t msec = 0);
46 
48  Time(const Time& other);
49 
51  virtual ~Time();
52 
54  void setHour(uint_t hour);
55 
57  void setHour12(uint_t hour, bool pm = false);
58 
60  void setMinute(uint_t minute);
61 
63  void setSecond(uint_t second);
64 
66  void setMillisecond(uint_t msec);
67 
69  void setTime(uint_t hour, uint_t minute, uint_t second = 0, uint_t msec = 0);
70 
72  inline uint_t getHour() const
73  { return(_hour); }
74 
76  inline uint_t getHour12() const
77  { return(_hour == 0 ? 12 : _hour % 12); }
78 
80  inline bool isPM() const
81  { return(_hour >= 12); }
82 
84  inline bool isAM() const
85  { return(_hour < 12); }
86 
88  inline uint_t getMinute() const
89  { return(_minute); }
90 
92  inline uint_t getSecond() const
93  { return(_second); }
94 
96  inline uint_t getMillisecond() const
97  { return(_msec); }
98 
99  bool operator==(const Time& other) const;
100  bool operator<(const Time& other) const;
101  bool operator<=(const Time& other) const;
102 
103  inline bool operator!=(const Time& other) const
104  { return(! operator==(other)); }
105 
106  inline bool operator>(const Time& other) const
107  { return(! operator<=(other)); }
108 
109  inline bool operator>=(const Time& other) const
110  { return(! operator<(other)); }
111 
112  Time& operator=(const Time& other);
113 
114  protected:
115 
117  uint_t _hour;
118  uint_t _minute;
119  uint_t _second;
120  uint_t _msec;
122 };
123 
124 } // namespace ccxx
125 
126 #endif // __ccxx_Time_hxx
bool isPM() const
Test if the hour is post meridiem.
Definition: Time.h++:80
bool operator<=(const Blob &b1, const Blob &b2)
Definition: Blob.h++:356
bool operator==(const Blob &b1, const Blob &b2)
Definition: Blob.h++:344
bool operator!=(const Time &other) const
Definition: Time.h++:103
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
uint_t getMillisecond() const
Get the millisecond component of the time.
Definition: Time.h++:96
bool operator>=(const Time &other) const
Definition: Time.h++:109
bool isAM() const
Test if the hour is ante meridiem.
Definition: Time.h++:84
A representation of a clock time.
Definition: Time.h++:37
#define COMMONCPP_API
Definition: Common.h++:126
uint_t getHour() const
Get the hour component of the time.
Definition: Time.h++:72
uint_t getHour12() const
Get the hour component of the time (12-hour clock).
Definition: Time.h++:76
uint_t getMinute() const
Get the minute component of the time.
Definition: Time.h++:88
bool operator<(const Blob &b1, const Blob &b2)
Definition: Blob.h++:350
bool operator>(const Time &other) const
Definition: Time.h++:106
uint_t getSecond() const
Get the second component of the time.
Definition: Time.h++:92
Definition: AllocationMap.c++:25