E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gdate.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // ===
17 ///
18 /// \file gdate.h
19 ///
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
30 namespace G
31 {
32 class Date ;
33 }
34
35 /// \class G::Date
36 /// A date (dd/mm/yyyy) class.
37 /// \see G::Time, G::DateTime
38 ///
39 class G::Date
40 {
41 public:
42 class LocalTime /// An overload discriminator class for Date constructors.
43 {} ;
44
45 enum Weekday
46 { sunday, monday, tuesday, wednesday, thursday, friday, saturday } ;
47
48 enum Month
49 { january = 1 , february , march , april , may , june , july ,
50 august , september , october , november , december } ;
51
52 enum Format
53 { yyyy_mm_dd_slash , yyyy_mm_dd , mm_dd } ;
54
55 static int yearUpperLimit() ;
56 ///< Returns the largest supported year value.
57
58 static int yearLowerLimit() ;
59 ///< Returns the smallest supported year value.
60
61 Date() ;
62 ///< Default constructor for the current date
63 ///< in the UTC timezone.
64
65 explicit Date( const LocalTime & ) ;
66 ///< Constructor for the current date
67 ///< in the local timezone.
68
69 Date( const G::DateTime::BrokenDownTime & tm ) ;
70 ///< Constructor for the specified date.
71
72 explicit Date( G::EpochTime t ) ;
73 ///< Constructor for the date in the UTC
74 ///< timezone as at the given epoch time.
75
76 Date( G::EpochTime t , const LocalTime & ) ;
77 ///< Constructor for the date in the local
78 ///< timezone as at the given epoch time.
79
80 Date( int year , Month month , int day_of_month ) ;
81 ///< Constructor for the specified date.
82
83 std::string string( Format format = yyyy_mm_dd_slash ) const ;
84 ///< Returns a string representation of the date.
85
86 Weekday weekday() const ;
87 ///< Returns the day of the week.
88
89 std::string weekdayName( bool brief = false ) const ;
90 ///< Returns an english string representation of
91 ///< the day of the week.
92
93 int monthday() const ;
94 ///< Returns the day of the month.
95
96 std::string dd() const ;
97 ///< Returns the day of the month as a two-digit decimal string.
98
99 Month month() const ;
100 ///< Returns the month.
101
102 std::string monthName( bool brief = false ) const ;
103 ///< Returns the month as a string (in english).
104
105 std::string mm() const ;
106 ///< Returns the month as a two-digit decimal string.
107
108 int year() const ;
109 ///< Returns the year.
110
111 std::string yyyy() const ;
112 ///< Returns the year as a four-digit decimal string.
113
114 Date & operator++() ;
115 ///< Increments the date by one day.
116
117 Date & operator--() ;
118 ///< Decrements the date by one day.
119
120 bool operator==( const Date & rhs ) const ;
121 ///< Comparison operator.
122
123 bool operator!=( const Date & rhs ) const ;
124 ///< Comparison operator.
125
126 private:
127 void init( const G::DateTime::BrokenDownTime & ) ;
128 static int lastDay( int month , int year ) ;
129 static bool isLeapYear( int y ) ;
130
131 private:
132 int m_day ;
133 int m_month ;
134 int m_year ;
135 bool m_weekday_set ;
136 Weekday m_weekday ;
137 } ;
138
139 #endif
G::EpochTime
A subsecond-resolution timestamp based on a time_t.
Definition: gdatetime.h:39
G::Date::month
Month month() const
Returns the month.
Definition: gdate.cpp:165
G::Date
A date (dd/mm/yyyy) class.
Definition: gdate.h:39
G::Date::monthName
std::string monthName(bool brief=false) const
Returns the month as a string (in english).
Definition: gdate.cpp:170
G::Date::yearLowerLimit
static int yearLowerLimit()
Returns the smallest supported year value.
Definition: gdate.cpp:33
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::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::LocalTime
An overload discriminator class for Date constructors.
Definition: gdate.h:42
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
Low-level classes.
Definition: garg.h:29
G::Date::Date
Date()
Default constructor for the current date in the UTC timezone.
Definition: gdate.cpp:38
G::Date::yyyy
std::string yyyy() const
Returns the year as a four-digit decimal string.
Definition: gdate.cpp:192
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::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::Date::mm
std::string mm() const
Returns the month as a two-digit decimal string.
Definition: gdate.cpp:123
gdebug.h