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

FXDate.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * D a t e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2005,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (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 GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXDate.h,v 1.10.2.1 2006/07/17 17:57:30 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXDATE_H
25 #define FXDATE_H
26 
27 namespace FX {
28 
29 
30 
31 /**
32 * Gregorian date object.
33 */
34 class FXAPI FXDate {
35 private:
36  FXuint julian;
37 private:
38  static const FXchar shortMonthName[12][4];
39  static const FXchar longMonthName[12][10];
40  static const FXchar shortWeekDay[7][4];
41  static const FXchar longWeekDay[7][10];
42 protected:
43  static void greg2jul(FXuint& jd,FXint y,FXint m,FXint d);
44  static void jul2greg(FXuint jd,FXint& y,FXint& m,FXint& d);
45 public:
46 
47  /// Names for the months
48  enum {
49  Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
50  };
51 
52  /// Names for the weekdays
53  enum {
54  Sun=0,Mon,Tue,Wed,Thu,Fri,Sat
55  };
56 
57 public:
58 
59  /// Default constructor
60  FXDate(){}
61 
62  /// Copy constructor
63  FXDate(const FXDate& date):julian(date.julian){}
64 
65  /// Initialize with year, month, and day
66  FXDate(FXint y,FXint m,FXint d);
67 
68  /// Initialize with julian day number
69  FXDate(FXuint j):julian(j){}
70 
71  /// Set julian day number
72  void setJulian(FXuint d){ julian=d; }
73 
74  /// Get julian day number
75  FXuint getJulian() const { return julian; }
76 
77  /// Set to year, month, and day
78  void setDate(FXint y,FXint m,FXint d);
79 
80  /// Get year, month, and day
81  void getDate(FXint& y,FXint& m,FXint& d) const;
82 
83  /// Return day of the month
84  FXint day() const;
85 
86  /// Return month
87  FXint month() const;
88 
89  /// Return year
90  FXint year() const;
91 
92  /// Return day of the week
93  FXint dayOfWeek() const;
94 
95  /// Return day of year
96  FXint dayOfYear() const;
97 
98  /// Return days in this month
99  FXint daysInMonth() const;
100 
101  /// Return true if leap year
102  bool leapYear() const;
103 
104  /// Is the value a leap year
105  static bool leapYear(FXint y);
106 
107  /// Get the name of the month
108  static const FXchar *monthName(FXint m){ return longMonthName[m-1]; }
109 
110  /// Get the abbreviated name of the month
111  static const FXchar *monthNameShort(FXint m){ return shortMonthName[m-1]; }
112 
113  /// Get the name of the day
114  static const FXchar *dayName(FXint d){ return longWeekDay[d]; }
115 
116  /// Get the abbreviated name of the day
117  static const FXchar *dayNameShort(FXint d){ return shortWeekDay[d]; }
118 
119  /// Return current local date
120  static FXDate localDate();
122  /// Return current UTC (Zulu) date
123  static FXDate zuluDate();
125  /// Assignment
126  FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
127 
128  /// Assignment operators
129  FXDate& operator+=(FXint x){ julian+=x; return *this; }
130  FXDate& operator-=(FXint x){ julian-=x; return *this; }
132  /// Increment and decrement
133  FXDate& operator++(){ julian++; return *this; }
134  FXDate& operator--(){ julian--; return *this; }
135 
136  /// Equality tests
137  bool operator==(const FXDate& date) const { return julian==date.julian;}
138  bool operator!=(const FXDate& date) const { return julian!=date.julian;}
139 
140  /// Inequality tests
141  bool operator<(const FXDate& date) const { return julian<date.julian;}
142  bool operator<=(const FXDate& date) const { return julian<=date.julian;}
143  bool operator>(const FXDate& date) const { return julian>date.julian;}
144  bool operator>=(const FXDate& date) const { return julian>=date.julian;}
145 
146  /// Add days to date yielding another date
147  friend inline FXDate operator+(const FXDate& d,FXint x);
148  friend inline FXDate operator+(FXint x,const FXDate& d);
150  /// Substract dates yielding days
151  friend inline FXint operator-(const FXDate& a,const FXDate& b);
152 
153  /// save to stream
154  friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
155 
156  /// load from stream
157  friend FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
158  };
159 
160 
161 inline FXDate operator+(const FXDate& d,FXint x){ return FXDate(d.julian+x); }
162 inline FXDate operator+(FXint x,const FXDate& d){ return FXDate(x+d.julian); }
163 inline FXint operator-(const FXDate& a,const FXDate& b){return a.julian-b.julian; }
164 
165 extern FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
166 extern FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
167 
168 }
169 
170 #endif
FXStream & operator>>(FXStream &store, FXDate &d)
char FXchar
Definition: fxdefs.h:387
unsigned int FXuint
Definition: fxdefs.h:396
#define FXAPI
Definition: fxdefs.h:122
Gregorian date object.
Definition: FXDate.h:34
bool operator<=(const FXString &s1, const FXString &s2)
bool operator>=(const FXString &s1, const FXString &s2)
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
int FXint
Definition: fxdefs.h:397
FXDate operator+(const FXDate &d, FXint x)
Definition: FXDate.h:148
bool operator<(const FXString &s1, const FXString &s2)
FXint operator-(const FXDate &a, const FXDate &b)
Definition: FXDate.h:150
bool operator>(const FXString &s1, const FXString &s2)
FXStream & operator<<(FXStream &store, const FXDate &d)
bool operator!=(const FXString &s1, const FXString &s2)
bool operator==(const FXString &s1, const FXString &s2)

Copyright © 1997-2005 Jeroen van der Zijp