gdate.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20 
21 #ifndef G_DATE_H
22 #define G_DATE_H
23 
24 #include "gdef.h"
25 #include "gdatetime.h"
26 #include "gdebug.h"
27 #include <ctime>
28 #include <string>
29 
31 namespace G
32 {
33  class Date ;
34 }
35 
40 class G::Date
41 {
42 public:
44  class LocalTime
45  {} ;
46 
47  enum Weekday
49 
50  enum Month
51  { january = 1 , february , march , april , may , june , july ,
53 
54  enum Format
56 
57  static int yearUpperLimit() ;
59 
60  static int yearLowerLimit() ;
62 
63  Date() ;
66 
67  explicit Date( const LocalTime & ) ;
70 
71  Date( const G::DateTime::BrokenDownTime & tm ) ;
73 
74  explicit Date( G::DateTime::EpochTime t ) ;
77 
78  Date( G::DateTime::EpochTime t , const LocalTime & ) ;
81 
82  Date( int year , Month month , int day_of_month ) ;
84 
85  std::string string( Format format = yyyy_mm_dd_slash ) const ;
87 
88  Weekday weekday() const ;
90 
91  std::string weekdayName( bool brief = false ) const ;
95 
96  int monthday() const ;
98 
99  std::string dd() const ;
102 
103  Month month() const ;
105 
106  std::string monthName( bool brief = false ) const ;
108 
109  std::string mm() const ;
111 
112  int year() const ;
114 
115  std::string yyyy() const ;
118 
119  Date & operator++() ;
121 
122  Date & operator--() ;
124 
125  bool operator==( const Date & rhs ) const ;
127 
128  bool operator!=( const Date & rhs ) const ;
130 
131 private:
132  void init( const G::DateTime::BrokenDownTime & ) ;
133  static int lastDay( int month , int year ) ;
134  static bool isLeapYear( int y ) ;
135 
136 private:
137  int m_day ;
138  int m_month ;
139  int m_year ;
140  bool m_weekday_set ;
141  Weekday m_weekday ;
142 } ;
143 
144 #endif
Month month() const
Returns the month.
Definition: gdate.cpp:165
std::time_t EpochTime
Definition: gdatetime.h:41
A date (dd/mm/yyyy) class.
Definition: gdate.h:40
std::string monthName(bool brief=false) const
Returns the month as a string (in english).
Definition: gdate.cpp:170
static int yearLowerLimit()
Returns the smallest supported year value.
Definition: gdate.cpp:33
bool operator!=(const Date &rhs) const
Comparison operator.
Definition: gdate.cpp:285
int monthday() const
Returns the day of the month.
Definition: gdate.cpp:111
int year() const
Returns the year.
Definition: gdate.cpp:187
bool operator==(const Date &rhs) const
Comparison operator.
Definition: gdate.cpp:277
Format
Definition: gdate.h:54
An overload discriminator class for Date constructors.
Definition: gdate.h:44
std::string string(Format format=yyyy_mm_dd_slash) const
Returns a string representation of the date.
Definition: gdate.cpp:89
std::string dd() const
Returns the day of the month as a two-digit decimal string.
Definition: gdate.cpp:116
Low-level classes.
Month
Definition: gdate.h:50
Date()
Default constructor for the current date in the UTC timezone.
Definition: gdate.cpp:38
std::string yyyy() const
Returns the year as a four-digit decimal string.
Definition: gdate.cpp:192
std::string weekdayName(bool brief=false) const
Returns an english string representation of the day of the week.
Definition: gdate.cpp:153
Date & operator--()
Decrements the date by one day.
Definition: gdate.cpp:222
Date & operator++()
Increments the date by one day.
Definition: gdate.cpp:199
Weekday weekday() const
Returns the day of the week.
Definition: gdate.cpp:130
static int yearUpperLimit()
Returns the largest supported year value.
Definition: gdate.cpp:28
struct std::tm BrokenDownTime
Definition: gdatetime.h:43
std::string mm() const
Returns the month as a two-digit decimal string.
Definition: gdate.cpp:123
Weekday
Definition: gdate.h:47