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,2025 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);
76 
78  void getDate(FXint& yr) const;
79 
81  void setDate(FXint yr,FXint dy);
82 
84  void getDate(FXint& yr,FXint& dy) const;
85 
87  void setDate(FXint yr,FXint mo,FXint dy);
88 
90  void getDate(FXint& yr,FXint& mo,FXint& dy) const;
91 
93  void setTime(FXTime ns);
94 
96  FXTime getTime() const;
97 
99  FXint day() const;
100 
102  FXint month() const;
103 
105  FXint year() const;
106 
108  FXint dayOfWeek() const;
109 
111  FXint dayOfYear() const;
112 
114  FXint weekOfYear() const;
115 
117  FXbool leapYear() const;
118 
120  FXint daysInYear() const;
121 
123  FXint daysInMonth() const;
124 
126  FXDate& addDays(FXint d);
127 
129  FXDate& addMonths(FXint m);
130 
132  FXDate& addYears(FXint y);
133 
135  static FXbool leapYear(FXint yr);
136 
138  static FXint daysInYear(FXint yr);
139 
141  static FXint daysInMonth(FXint yr,FXint mo);
142 
144  static const FXchar *monthName(FXint mo){ return longMonthName[mo-1]; }
145 
147  static const FXchar *monthNameShort(FXint mo){ return shortMonthName[mo-1]; }
148 
150  static const FXchar *dayName(FXint dy){ return longWeekDay[dy]; }
151 
153  static const FXchar *dayNameShort(FXint dy){ return shortWeekDay[dy]; }
154 
156  static FXDate localDate();
157 
159  static FXDate universalDate();
160 
162  FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
163 
165  FXDate& operator+=(FXint x){ julian+=x; return *this; }
166  FXDate& operator-=(FXint x){ julian-=x; return *this; }
167 
169  FXDate& operator++(){ ++julian; return *this; }
170  FXDate& operator--(){ --julian; return *this; }
171 
173  FXDate operator++(int){ FXDate t(julian++); return t; }
174  FXDate operator--(int){ FXDate t(julian--); return t; }
175 
177  FXbool operator==(const FXDate& date) const { return julian==date.julian;}
178  FXbool operator!=(const FXDate& date) const { return julian!=date.julian;}
179 
181  FXbool operator<(const FXDate& date) const { return julian<date.julian;}
182  FXbool operator<=(const FXDate& date) const { return julian<=date.julian;}
183  FXbool operator>(const FXDate& date) const { return julian>date.julian;}
184  FXbool operator>=(const FXDate& date) const { return julian>=date.julian;}
185 
187  friend inline FXDate operator+(const FXDate& d,FXint x);
188  friend inline FXDate operator+(FXint x,const FXDate& d);
189 
191  friend inline FXint operator-(const FXDate& a,const FXDate& b);
192 
194  friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
195 
197  friend FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
198 
201  };
202 
203 
204 inline FXDate operator+(const FXDate& d,FXint x){ return FXDate(d.julian+x); }
205 inline FXDate operator+(FXint x,const FXDate& d){ return FXDate(x+d.julian); }
206 inline FXint operator-(const FXDate& a,const FXDate& b){return a.julian-b.julian; }
207 
208 extern FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
209 extern FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
210 
211 }
212 
213 #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:147
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:173
static const FXchar * monthName(FXint mo)
Get the name of the month.
Definition: FXDate.h:144
FXDate & operator=(const FXDate &date)
Assignment.
Definition: FXDate.h:162
Definition: FX4Splitter.h:28
~FXDate()
Destructor.
Definition: FXDate.h:200
FXDate & operator++()
Pre-Increment and decrement.
Definition: FXDate.h:169
FXDate(const FXDate &date)
Copy constructor.
Definition: FXDate.h:57
FXbool operator<(const FXDate &date) const
Inequality tests.
Definition: FXDate.h:181
static const FXchar * dayName(FXint dy)
Get the name of the day.
Definition: FXDate.h:150
static const FXchar * dayNameShort(FXint dy)
Get the abbreviated name of the day.
Definition: FXDate.h:153
FXDate(FXuint jd)
Initialize with julian day number.
Definition: FXDate.h:60
FXDate & operator+=(FXint x)
Assignment operators.
Definition: FXDate.h:165
FXDate()
Default constructor.
Definition: FXDate.h:54
FXbool operator==(const FXDate &date) const
Equality tests.
Definition: FXDate.h:177

Copyright © 1997-2022 Jeroen van der Zijp