- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
48 { sunday, monday, tuesday, wednesday, thursday, friday, saturday } ;
49
50 enum Month
51 { january = 1 , february , march , april , may , june , july ,
52 august , september , october , november , december } ;
53
54 enum Format
55 { yyyy_mm_dd_slash , yyyy_mm_dd , mm_dd } ;
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
G::Date::thursday
Definition: gdate.h:48
G::Date::january
Definition: gdate.h:51
G::Date::month
Month month() const
Returns the month.
Definition: gdate.cpp:165
G::Date::sunday
Definition: gdate.h:48
G::Date::monday
Definition: gdate.h:48
G::DateTime::EpochTime
std::time_t EpochTime
Definition: gdatetime.h:41
G::Date
A date (dd/mm/yyyy) class.
Definition: gdate.h:40
G::Date::wednesday
Definition: gdate.h:48
G::Date::monthName
std::string monthName(bool brief=false) const
Returns the month as a string (in english).
Definition: gdate.cpp:170
G::Date::november
Definition: gdate.h:52
G::Date::yearLowerLimit
static int yearLowerLimit()
Returns the smallest supported year value.
Definition: gdate.cpp:33
G::Date::march
Definition: gdate.h:51
G::Date::operator!=
bool operator!=(const Date &rhs) const
Comparison operator.
Definition: gdate.cpp:285
G::Date::monthday
int monthday() const
Returns the day of the month.
Definition: gdate.cpp:111
G::Date::friday
Definition: gdate.h:48
G::Date::year
int year() const
Returns the year.
Definition: gdate.cpp:187
G::Date::operator==
bool operator==(const Date &rhs) const
Comparison operator.
Definition: gdate.cpp:277
G::Date::december
Definition: gdate.h:52
G::Date::Format
Format
Definition: gdate.h:54
G::Date::july
Definition: gdate.h:51
G::Date::saturday
Definition: gdate.h:48
G::Date::LocalTime
An overload discriminator class for Date constructors.
Definition: gdate.h:44
G::Date::string
std::string string(Format format=yyyy_mm_dd_slash) const
Returns a string representation of the date.
Definition: gdate.cpp:89
G::Date::dd
std::string dd() const
Returns the day of the month as a two-digit decimal string.
Definition: gdate.cpp:116
G::Date::september
Definition: gdate.h:52
G::Date::mm_dd
Definition: gdate.h:55
G::Date::tuesday
Definition: gdate.h:48
G
Low-level classes.
G::Date::Month
Month
Definition: gdate.h:50
G::Date::Date
Date()
Default constructor for the current date in the UTC timezone.
Definition: gdate.cpp:38
G::Date::february
Definition: gdate.h:51
G::Date::yyyy
std::string yyyy() const
Returns the year as a four-digit decimal string.
Definition: gdate.cpp:192
G::Date::yyyy_mm_dd_slash
Definition: gdate.h:55
G::Date::april
Definition: gdate.h:51
G::Date::weekdayName
std::string weekdayName(bool brief=false) const
Returns an english string representation of the day of the week.
Definition: gdate.cpp:153
G::Date::operator--
Date & operator--()
Decrements the date by one day.
Definition: gdate.cpp:222
G::Date::operator++
Date & operator++()
Increments the date by one day.
Definition: gdate.cpp:199
gdatetime.h
G::Date::yyyy_mm_dd
Definition: gdate.h:55
G::Date::weekday
Weekday weekday() const
Returns the day of the week.
Definition: gdate.cpp:130
G::Date::yearUpperLimit
static int yearUpperLimit()
Returns the largest supported year value.
Definition: gdate.cpp:28
G::DateTime::BrokenDownTime
struct std::tm BrokenDownTime
Definition: gdatetime.h:43
G::Date::august
Definition: gdate.h:52
G::Date::may
Definition: gdate.h:51
G::Date::october
Definition: gdate.h:52
G::Date::mm
std::string mm() const
Returns the month as a two-digit decimal string.
Definition: gdate.cpp:123
G::Date::Weekday
Weekday
Definition: gdate.h:47
gdebug.h
G::Date::june
Definition: gdate.h:51