Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXDate.h
1 /********************************************************************************
2 * *
3 * D a t e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2005,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXDATE_H
22 #define FXDATE_H
23 
24 
25 namespace FX {
26 
27 
31 class FXAPI FXDate {
32 private:
33  FXuint julian;
34 private:
35  static const FXchar shortMonthName[12][4];
36  static const FXchar longMonthName[12][10];
37  static const FXchar shortWeekDay[7][4];
38  static const FXchar longWeekDay[7][10];
39 public:
40 
42  enum {
43  Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
44  };
45 
47  enum {
48  Sun=0,Mon,Tue,Wed,Thu,Fri,Sat
49  };
50 
51 public:
52 
54  FXDate(){}
55 
57  FXDate(const FXDate& date):julian(date.julian){}
58 
60  FXDate(FXuint jd):julian(jd){}
61 
63  FXDate(FXint yr,FXint dy);
64 
66  FXDate(FXint yr,FXint mo,FXint dy);
67 
69  void setJulian(FXuint jd){ julian=jd; }
70 
72  FXuint getJulian() const { return julian; }
73 
75  void setDate(FXint yr,FXint dy);
76 
78  void getDate(FXint& yr,FXint& dy) const;
79 
81  void setDate(FXint yr,FXint mo,FXint dy);
82 
84  void getDate(FXint& yr,FXint& mo,FXint& dy) const;
85 
87  void setTime(FXTime ns);
88 
90  FXTime getTime() const;
91 
93  FXint day() const;
94 
96  FXint month() const;
97 
99  FXint year() const;
100 
102  FXint dayOfWeek() const;
103 
105  FXint dayOfYear() const;
106 
108  FXint weekOfYear() const;
109 
111  FXbool leapYear() const;
112 
114  FXint daysInYear() const;
115 
117  FXint daysInMonth() const;
118 
120  FXDate& addDays(FXint d);
121 
123  FXDate& addMonths(FXint m);
124 
126  FXDate& addYears(FXint y);
127 
129  static FXbool leapYear(FXint yr);
130 
132  static FXint daysInYear(FXint yr);
133 
135  static FXint daysInMonth(FXint yr,FXint mo);
136 
138  static const FXchar *monthName(FXint mo){ return longMonthName[mo-1]; }
139 
141  static const FXchar *monthNameShort(FXint mo){ return shortMonthName[mo-1]; }
142 
144  static const FXchar *dayName(FXint dy){ return longWeekDay[dy]; }
145 
147  static const FXchar *dayNameShort(FXint dy){ return shortWeekDay[dy]; }
148 
150  static FXDate localDate();
151 
153  static FXDate universalDate();
154 
156  FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
157 
159  FXDate& operator+=(FXint x){ julian+=x; return *this; }
160  FXDate& operator-=(FXint x){ julian-=x; return *this; }
161 
163  FXDate& operator++(){ ++julian; return *this; }
164  FXDate& operator--(){ --julian; return *this; }
165 
167  FXDate operator++(int){ FXDate t(julian++); return t; }
168  FXDate operator--(int){ FXDate t(julian--); return t; }
169 
171  FXbool operator==(const FXDate& date) const { return julian==date.julian;}
172  FXbool operator!=(const FXDate& date) const { return julian!=date.julian;}
173 
175  FXbool operator<(const FXDate& date) const { return julian<date.julian;}
176  FXbool operator<=(const FXDate& date) const { return julian<=date.julian;}
177  FXbool operator>(const FXDate& date) const { return julian>date.julian;}
178  FXbool operator>=(const FXDate& date) const { return julian>=date.julian;}
179 
181  friend inline FXDate operator+(const FXDate& d,FXint x);
182  friend inline FXDate operator+(FXint x,const FXDate& d);
183 
185  friend inline FXint operator-(const FXDate& a,const FXDate& b);
186 
188  friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
189 
191  friend FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
192 
195  };
196 
197 
198 inline FXDate operator+(const FXDate& d,FXint x){ return FXDate(d.julian+x); }
199 inline FXDate operator+(FXint x,const FXDate& d){ return FXDate(x+d.julian); }
200 inline FXint operator-(const FXDate& a,const FXDate& b){return a.julian-b.julian; }
201 
202 extern FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
203 extern FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
204 
205 }
206 
207 #endif
void setJulian(FXuint jd)
Set julian day number.
Definition: FXDate.h:69
FXuint getJulian() const
Get julian day number.
Definition: FXDate.h:72
static const FXchar * monthNameShort(FXint mo)
Get the abbreviated name of the month.
Definition: FXDate.h:141
Gregorian date class, which is useful for calendrical calculations.
Definition: FXDate.h:31
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
FXDate operator++(int)
Post-Increment and decrement.
Definition: FXDate.h:167
static const FXchar * monthName(FXint mo)
Get the name of the month.
Definition: FXDate.h:138
FXDate & operator=(const FXDate &date)
Assignment.
Definition: FXDate.h:156
Definition: FX4Splitter.h:28
~FXDate()
Destructor.
Definition: FXDate.h:194
FXDate & operator++()
Pre-Increment and decrement.
Definition: FXDate.h:163
FXDate(const FXDate &date)
Copy constructor.
Definition: FXDate.h:57
FXbool operator<(const FXDate &date) const
Inequality tests.
Definition: FXDate.h:175
static const FXchar * dayName(FXint dy)
Get the name of the day.
Definition: FXDate.h:144
static const FXchar * dayNameShort(FXint dy)
Get the abbreviated name of the day.
Definition: FXDate.h:147
FXDate(FXuint jd)
Initialize with julian day number.
Definition: FXDate.h:60
FXDate & operator+=(FXint x)
Assignment operators.
Definition: FXDate.h:159
FXDate()
Default constructor.
Definition: FXDate.h:54
FXbool operator==(const FXDate &date) const
Equality tests.
Definition: FXDate.h:171

Copyright © 1997-2022 Jeroen van der Zijp