VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gdate.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
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  ///< (Was weekdayString().)
93 
94  int monthday() const ;
95  ///< Returns the day of the month.
96 
97  std::string dd() const ;
98  ///< Returns the day of the month as a two-digit decimal string.
99  ///< (Was monthdayString().)
100 
101  Month month() const ;
102  ///< Returns the month.
103 
104  std::string monthName( bool brief = false ) const ;
105  ///< Returns the month as a string (in english).
106 
107  std::string mm() const ;
108  ///< Returns the month as a two-digit decimal string.
109 
110  int year() const ;
111  ///< Returns the year.
112 
113  std::string yyyy() const ;
114  ///< Returns the year as a four-digit decimal string.
115  ///< (Was yearString().)
116 
117  Date & operator++() ;
118  ///< Increments the date by one day.
119 
120  Date & operator--() ;
121  ///< Decrements the date by one day.
122 
123  bool operator==( const Date & rhs ) const ;
124  ///< Comparison operator.
125 
126  bool operator!=( const Date & rhs ) const ;
127  ///< Comparison operator.
128 
129 private:
130  void init( const G::DateTime::BrokenDownTime & ) ;
131  static int lastDay( int month , int year ) ;
132  static bool isLeapYear( int y ) ;
133 
134 private:
135  int m_day ;
136  int m_month ;
137  int m_year ;
138  bool m_weekday_set ;
139  Weekday m_weekday ;
140 } ;
141 
142 #endif
A subsecond-resolution timestamp based on a time_t.
Definition: gdatetime.h:39
Month month() const
Returns the month.
Definition: gdate.cpp:165
A date (dd/mm/yyyy) class.
Definition: gdate.h:39
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
An overload discriminator class for Date constructors.
Definition: gdate.h:42
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
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
std::string mm() const
Returns the month as a two-digit decimal string.
Definition: gdate.cpp:123