libDwm-0.6.0
DwmDateTime.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmDateTime.hh 8651 $
3 // @(#) $Id: DwmDateTime.hh 8651 2016-06-12 04:21:49Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2005, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
33 // PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMDATETIME_HH_
43 #define _DWMDATETIME_HH_
44 
45 extern "C" {
46 #include <inttypes.h>
47 #include <time.h>
48 }
49 
50 #include <string>
51 
52 #include "DwmTimeValue.hh"
53 #include "DwmTimeValue64.hh"
54 
55 namespace Dwm {
56 
57  //--------------------------------------------------------------------------
62  //--------------------------------------------------------------------------
63  class DateTime
64  {
65  public:
66  //------------------------------------------------------------------------
69  //------------------------------------------------------------------------
70  DateTime(bool now = false);
71 
72  //------------------------------------------------------------------------
74  //------------------------------------------------------------------------
75  DateTime(const TimeValue & tv);
76 
77  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  DateTime(const Dwm::TimeValue64 & tv);
81 
82  //------------------------------------------------------------------------
84  //------------------------------------------------------------------------
85  TimeValue GetTimeValue() const;
86 
87  //------------------------------------------------------------------------
89  //------------------------------------------------------------------------
91 
92  //------------------------------------------------------------------------
94  //------------------------------------------------------------------------
95  bool IsDaylightSavings() const;
96 
97  //------------------------------------------------------------------------
99  //------------------------------------------------------------------------
100  uint8_t Sec() const;
101 
102  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  uint8_t Min() const;
106 
107  //------------------------------------------------------------------------
109  //------------------------------------------------------------------------
110  uint8_t Hour() const;
111 
112  //------------------------------------------------------------------------
114  //------------------------------------------------------------------------
115  uint8_t DayOfMonth() const;
116 
117  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  uint8_t Month() const;
121 
122  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  uint16_t Year() const;
126 
127  //------------------------------------------------------------------------
129  //------------------------------------------------------------------------
130  uint8_t DayOfWeek() const;
131 
132  //------------------------------------------------------------------------
134  //------------------------------------------------------------------------
135  uint16_t DayOfYear() const;
136 
137  //------------------------------------------------------------------------
139  //------------------------------------------------------------------------
140  std::string TimeZone() const;
141 
142  //------------------------------------------------------------------------
145  //------------------------------------------------------------------------
146  std::string Formatted(const std::string & format) const;
147 
148  //------------------------------------------------------------------------
153  //------------------------------------------------------------------------
154  bool Parse(const std::string & s, const std::string & format);
155 
156  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  bool operator == (const DateTime & dt) const;
160 
161  //------------------------------------------------------------------------
163  //------------------------------------------------------------------------
164  bool operator < (const DateTime & dt) const;
165 
166  private:
167  struct tm _tm;
168  };
169 
170 } // namespace Dwm
171 
172 #endif // _DWMDATETIME_HH_
173 
174 //---------------------------- emacs settings -----------------------------
175 // Local Variables:
176 // mode: C++/la
177 // tab-width: 2
178 // indent-tabs-mode: nil
179 // c-basic-offset: 2
180 // End:
181 //-------------------------------------------------------------------------
TimeValue64 GetTimeValue64() const
Return the equivalent TimeValue64, using the current timezone setting.
uint8_t DayOfMonth() const
Returns the day of the month (1 - 31).
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue.hh:72
TimeValue GetTimeValue() const
Return the equivalent TimeValue, using the current timezone setting.
DateTime(bool now=false)
Constructor.
bool operator==(const DateTime &dt) const
operator ==
uint8_t Sec() const
Returns the seconds (0 - 59).
Dwm::TimeValue class definition.
uint8_t Min() const
Returns the minutes (0 - 59).
Definition: DwmBZ2IO.hh:67
bool Parse(const std::string &s, const std::string &format)
Parses time string s according to the given format.
std::string TimeZone() const
Returns the time zone.
std::string Formatted(const std::string &format) const
Returns a string formatted according to format.
uint16_t Year() const
Returns the year.
uint8_t Month() const
Returns the month of the year (1 - 12).
bool operator<(const DateTime &dt) const
operator <
Dwm::TimeValue64 class definition.
This class just encapsulates a struct tm and some of the typical functionality for dealing with date ...
Definition: DwmDateTime.hh:63
uint16_t DayOfYear() const
Returns the day of the year (0 - 365).
bool IsDaylightSavings() const
Returns true if daylight savings is in effect.
uint8_t Hour() const
Returns the hour (0 - 23).
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue64.hh:72
uint8_t DayOfWeek() const
Returns the day of the week (Sunday == 0)