Databaseconnectionclasses  0.5.3
hk_datetime.h
1 // ****************************************************************************
2 // copyright (c) 2000-2005 Horst Knorr <hk_classes@knoda.org>
3 // This file is part of the hk_classes library.
4 // This file may be distributed and/or modified under the terms of the
5 // GNU Library Public License version 2 as published by the Free Software
6 // Foundation and appearing in the file COPYING included in the
7 // packaging of this file.
8 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10 // ****************************************************************************
11 #ifndef HK_DATETIME
12 #define HK_DATETIME
13 #include "hk_class.h"
14 using namespace std;
15 
25 class hk_datetime: public hk_class
26 {
27  public:
28  hk_datetime(void);
29  hk_datetime(const hk_datetime&);
30  virtual ~hk_datetime(void){}
34  bool set_date( int day, int month, int year);
38  bool set_time( int hour, int minute, int second);
42  bool set_datetime( int day, int month, int year, int hour, int minute, int second);
47  bool set_date_asstring(const hk_string& s);
51  bool set_time_asstring(const hk_string& s);
55  bool set_datetime_asstring(const hk_string& s);
59  hk_string date_asstring(void) const;
63  hk_string time_asstring(void)const;
67  hk_string datetime_asstring(void) const;
75  void set_dateformat(const hk_string& f);
83  void set_timeformat(const hk_string& f);
94  void set_datetimeformat(const hk_string& f);
95 
96  int day() const {return p_day;}
97  int month()const{return p_month;}
98  int year()const{return p_year;}
99  int hour()const{return p_hour;}
100  int minute()const{return p_minute;}
101  int second()const {return p_second;}
105  void set_now(void);
106 
107  bool operator=(const hk_datetime&);
108  bool operator==(const hk_datetime&);
109  bool operator!=(const hk_datetime&);
110  bool operator>(const hk_datetime&);
111  bool operator>=(const hk_datetime&);
112  bool operator<(const hk_datetime&);
113  bool operator<=(const hk_datetime&);
114 
118  double difference(const hk_datetime& d);
119  protected:
120 
121  bool is_ok_date( int day, int month, int year);
122  bool is_ok_time( int hour, int minute, int second);
123 
124  private:
125  void p_dateasstring(void)const ;
126  void p_timeasstring(void) const;
127  int p_setvalue(int &l,const hk_string& s,bool is_date=false);
128  int p_year,p_month,p_day;
129  int p_second,p_minute,p_hour;
130  hk_string p_dateformat;
131  hk_string p_timeformat;
132  hk_string p_datetimeformat;
133  mutable hk_string buffer;
134  void set_hk_datetime(const hk_datetime&);
135  bool is_equal(const hk_datetime&);
136 };
137 
138 //void set_format(hk_datetime &dt,int t);
143 hk_string transfer_date(const hk_string& date,const hk_string& originalformat, const hk_string& targetformat);
148 hk_string transfer_time(const hk_string& time,const hk_string& originalformat, const hk_string& targetformat);
153 hk_string transfer_datetime(const hk_string& datetime,const hk_string& originalformat, const hk_string& targetformat);
154 
155 ostream& operator<<(ostream&,const hk_datetime&);
156 ostream& operator<<(ostream&, hk_datetime&);
157 #endif
basic class for all other defined classes.
Definition: hk_class.h:52
translates date and/or time values in different formats
Definition: hk_datetime.h:25