libcommonc++  0.7
Date.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_Date_hxx
24 #define __ccxx_Date_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 namespace ccxx {
29 
36 {
37  public:
38 
40  static const uint_t JAN;
42  static const uint_t FEB;
44  static const uint_t MAR;
46  static const uint_t APR;
48  static const uint_t MAY;
50  static const uint_t JUN;
52  static const uint_t JUL;
54  static const uint_t AUG;
56  static const uint_t SEP;
58  static const uint_t OCT;
60  static const uint_t NOV;
62  static const uint_t DEC;
63 
64  enum Weekday { Invalid = 0, Monday, Tuesday, Wednesday, Thursday, Friday,
65  Saturday, Sunday };
66 
68  Date();
69 
71  Date(uint_t day, uint_t month, uint_t year);
72 
74  Date(const Date& other);
75 
77  virtual ~Date();
78 
80  void setMonth(uint_t month);
81 
83  void setDay(uint_t day);
84 
86  void setYear(uint_t year);
87 
89  void setDate(uint_t day, uint_t month, uint_t year);
90 
92  inline uint_t getMonth() const
93  { return(_month); }
94 
96  inline uint_t getDay() const
97  { return(_day); }
98 
100  inline uint_t getYear() const
101  { return(_year); }
102 
104  Weekday getWeekday() const;
105 
107  uint_t getDayOfYear() const;
108 
110  static bool isLeapYear(uint_t year);
111 
116  uint_t getWeekOfYear() const;
117 
119  bool isValid() const;
120 
121  bool operator==(const Date& other) const;
122  bool operator<(const Date& other) const;
123  bool operator<=(const Date& other) const;
124 
125  inline bool operator!=(const Date& other) const
126  { return(! operator==(other)); }
127 
128  inline bool operator>(const Date& other) const
129  { return(! operator<=(other)); }
130 
131  inline bool operator>=(const Date& other) const
132  { return(! operator<(other)); }
133 
134  Date& operator=(const Date& other);
135 
136  protected:
137 
139  uint_t _year;
140  uint_t _month;
141  uint_t _day;
142  mutable Weekday _wday;
143  mutable uint_t _yday;
144  mutable int _wnum;
147  private:
148 
149  void _recalculate() const;
150 };
151 
152 } // namespace ccxx
153 
154 #endif // __ccxx_Date_hxx
bool operator!=(const Date &other) const
Definition: Date.h++:125
static const uint_t MAY
The month of May.
Definition: Date.h++:48
static const uint_t APR
The month of April.
Definition: Date.h++:46
A representation of a calendar date.
Definition: Date.h++:35
bool operator>=(const Date &other) const
Definition: Date.h++:131
uint_t getMonth() const
Get the month component of the date.
Definition: Date.h++:92
static const uint_t NOV
The month of November.
Definition: Date.h++:60
bool operator<=(const Blob &b1, const Blob &b2)
Definition: Blob.h++:356
bool operator>(const Date &other) const
Definition: Date.h++:128
bool operator==(const Blob &b1, const Blob &b2)
Definition: Blob.h++:344
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
Weekday
Definition: Date.h++:64
static const uint_t JUL
The month of July.
Definition: Date.h++:52
static const uint_t SEP
The month of September.
Definition: Date.h++:56
static const uint_t AUG
The month of August.
Definition: Date.h++:54
static const uint_t OCT
The month of October.
Definition: Date.h++:58
uint_t getDay() const
Get the day-of-month component of the date.
Definition: Date.h++:96
uint_t getYear() const
Get the year component of the date.
Definition: Date.h++:100
#define COMMONCPP_API
Definition: Common.h++:126
static const uint_t FEB
The month of February.
Definition: Date.h++:42
static const uint_t MAR
The month of March.
Definition: Date.h++:44
bool operator<(const Blob &b1, const Blob &b2)
Definition: Blob.h++:350
static const uint_t JUN
The month of June.
Definition: Date.h++:50
Definition: AllocationMap.c++:25
static const uint_t JAN
The month of January.
Definition: Date.h++:40
static const uint_t DEC
The month of December.
Definition: Date.h++:62