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