OpendTect-6_4  6.4
dateinfo.h
Go to the documentation of this file.
1 #ifndef dateinfo_h
2 #define dateinfo_h
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Bril
8  Date: 12-3-1996
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "basicmod.h"
15 #include "enums.h"
16 #include "undefval.h"
17 
32 {
33 public:
34  enum DayOfWeek { Su=0, Mo, Tu, We, Th, Fr, Sa };
36  enum Month { Jan=0, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep,
37  Oct, Nov, Dec };
39  static const char** sFullMonths();
40  static const char** sAllDaysInMonth();
41 
42  DateInfo();
43  DateInfo(int usryr,int usrmnth,int usrdy);
44  DateInfo(int usryr,Month,int usrdy);
45  DateInfo(int usryr,const char* mnth,int usrdy);
46  DateInfo(const char*);
47 
48  bool isUdf() const { return mIsUdf(days1900_); }
49  void setUdf(bool yn=true);
50 
51  int day() const { return days_ + 1; }
52  Month month() const { return (Month)months_; }
53  int year() const { return 1900 + years_; }
54  int usrMonth() const { return (int)months_ + 1; }
55  void setDay(int);
56  void setMonth(int);
57  void setMonth(Month);
58  void setYear(int);
59 
60  bool operator ==(const DateInfo&) const;
61  bool operator !=(const DateInfo&) const;
62  bool operator <(const DateInfo&) const;
63  bool operator <=(const DateInfo&) const;
64  bool operator >(const DateInfo&) const;
65  bool operator >=(const DateInfo&) const;
66  DateInfo& operator +=(int);
67  DateInfo& operator -=( int dys ) { *this += -dys; return *this; }
68  friend int operator -(const DateInfo&,const DateInfo&);
69  void addMonths(int);
70 
71  int weekDay() const;
72  const char* weekDayName() const;
73  const char* monthName() const {return getMonthString(month());}
74  const char* whenRelative(const DateInfo* di=0) const;
75  static const char* fullMonthName(int);
76  static const char* fullMonthName(Month);
77  const char* fullMonthName() const { return fullMonthName(month());}
78 
79  void toString(BufferString&) const;
80  bool fromString(const char*);
81  bool fromStdDateString(const char*);
82  bool fromNumString(const char*,bool yearfirst);
83  void getUsrDisp(BufferString&,bool withcurtime) const;
84 
85  static int daysInMonth(int yr,Month);
86  static int daysInYear( int yr ) { return yr%4 ? 365 : 366; }
87  static Month usrMonth2Month(int);
88 
89 private:
90 
91  int days1900_;
92  int years_;
93  int months_;
94  int days_;
95 
96  void getDaysMonths(int,int,int&,int&);
97  void calcDMY();
98  void calcDays1900();
99  void getRel(const DateInfo&,BufferString&) const;
100  void getRelToday(BufferString&) const;
101  void addDay(BufferString&) const;
102 
103 public:
104 
105  int key() const { return days1900_; }
106  DateInfo(int the_key);
107 
108 };
109 
110 
111 inline bool DateInfo::operator ==( const DateInfo& di ) const
112 { return days1900_ == di.days1900_; }
113 
114 inline bool DateInfo::operator !=( const DateInfo& di ) const
115 { return days1900_ != di.days1900_; }
116 
117 inline bool DateInfo::operator <( const DateInfo& di ) const
118 { return days1900_ < di.days1900_; }
119 
120 inline bool DateInfo::operator <=( const DateInfo& di ) const
121 { return days1900_ <= di.days1900_; }
122 
123 inline bool DateInfo::operator >( const DateInfo& di ) const
124 { return days1900_ > di.days1900_; }
125 
126 inline bool DateInfo::operator >=( const DateInfo& di ) const
127 { return days1900_ >= di.days1900_; }
128 
129 inline int operator -( const DateInfo& di1, const DateInfo& di2 )
130 { return di1.days1900_ - di2.days1900_; }
131 
132 
133 #endif
#define mExpClass(module)
Definition: commondefs.h:160
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
static int daysInYear(int yr)
Definition: dateinfo.h:86
friend int operator-(const DateInfo &, const DateInfo &)
Definition: dateinfo.h:129
int operator-(const DateInfo &di1, const DateInfo &di2)
Definition: dateinfo.h:129
int year() const
Definition: dateinfo.h:53
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
int key() const
Definition: dateinfo.h:105
int usrMonth() const
Definition: dateinfo.h:54
Definition: dateinfo.h:34
A date info class.
Definition: dateinfo.h:31
bool operator>(const DateInfo &) const
Definition: dateinfo.h:123
int months_
Definition: dateinfo.h:93
#define mDeclareEnumUtils(enm)
Some utilities surrounding the often needed enum <-> string table.
Definition: enums.h:258
int days_
Definition: dateinfo.h:94
bool operator<=(const DateInfo &) const
Definition: dateinfo.h:120
bool operator<(const DateInfo &) const
Definition: dateinfo.h:117
bool operator==(const DateInfo &) const
Definition: dateinfo.h:111
Month month() const
Definition: dateinfo.h:52
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
const char * monthName() const
Definition: dateinfo.h:73
int years_
Definition: dateinfo.h:92
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Definition: dateinfo.h:37
Month
Definition: dateinfo.h:36
T & setUdf(T &u)
Definition: undefval.h:262
DayOfWeek
Definition: dateinfo.h:34
bool isUdf(const T &t)
Definition: undefval.h:243
const char * fullMonthName() const
Definition: dateinfo.h:77
Export_Basic const char * toString(ViewStyle)
Definition: dateinfo.h:36
bool operator!=(const DateInfo &) const
Definition: dateinfo.h:114
int day() const
Definition: dateinfo.h:51
bool operator>=(const DateInfo &) const
Definition: dateinfo.h:126
int days1900_
Definition: dateinfo.h:91

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019