PKIFTime.h
Go to the documentation of this file.00001
00009 #ifndef __CPKIFTIME_H__
00010 #define __CPKIFTIME_H__
00011
00012 #include "PKIFdll.h"
00013
00014
00015
00016 #include <time.h>
00017
00018
00019
00020 typedef struct
00021 {
00022 int limit;
00023 bool adjustLeap;
00024 } _CACDayOfMonthLimitType;
00025
00031 struct CACDayOfWeek
00032 {
00033 enum Type
00034 {
00035 SUNDAY = 0,
00036 MONDAY = 1,
00037 TUESDAY = 2,
00038 WEDNESDAY = 3,
00039 THURSDAY = 4,
00040 FRIDAY = 5,
00041 SATURDAY = 6
00042 };
00043 };
00044
00045 class CAC_API CPKIFDuration;
00046 class CAC_API CPKIFTime;
00047 DECLARE_SMART_POINTERS(CPKIFTime);
00048 struct CPKIFTimeImpl;
00049
00050 enum TimeType
00051 {
00052 UTCTIME = 1,
00053 GENERALIZEDTIME = 2
00054 };
00060 class CAC_API CPKIFTime
00061 {
00062 public:
00063 static CPKIFTimePtr CurrentTime();
00064
00065
00066
00067
00068 CPKIFTime();
00069 CPKIFTime(const CPKIFTime& time_);
00070
00071 CPKIFTime(const char *time, TimeType type);
00072 CPKIFTime(const char* time);
00073 ~CPKIFTime();
00074
00075
00076
00077
00078
00079 int year() const;
00080 int month() const;
00081 int dayOfMonth() const;
00082
00083
00084 int hours() const;
00085 int minutes() const;
00086 int seconds() const;
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 const char* GetTime() const;
00099
00100
00101 void set(
00102 int year_,
00103 int month_,
00104 int dom_,
00105 int hours_,
00106 int minutes_,
00107 int seconds_ );
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 CPKIFTime& operator=(const CPKIFTime& time_);
00122 CPKIFTime& operator+=(const CPKIFDuration& duration_);
00123 CPKIFTime& operator-=(const CPKIFDuration& duration_);
00124 CPKIFTime operator+(const CPKIFDuration& duration_) const;
00125 CPKIFTime operator-(const CPKIFDuration& duration_) const;
00126 CPKIFDuration operator-(const CPKIFTime& time_) const;
00127 bool operator==(const CPKIFTime& time_) const;
00128 bool operator!=(const CPKIFTime& time_) const;
00129 bool operator<(const CPKIFTime& time_) const;
00130 bool operator<=(const CPKIFTime& time_) const;
00131 bool operator>(const CPKIFTime& time_) const;
00132 bool operator>=(const CPKIFTime& time_) const;
00133
00134 private:
00135 struct CPKIFTimeImpl * m_impl;
00136 CPKIFStringPtr m_timeStr;
00137 };
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00166 inline void gregorian_to_JD0(
00168 const int& year_,
00170 const int& month_,
00172 const int& dom_,
00174 int& jd0_ )
00175 {
00176 int yp = (year_+4800);
00177 int mi = ((int)month_ - 14)/12;
00178 jd0_ = (int)dom_ - 32075;
00179 jd0_ += 1461 * (yp+mi) / 4;
00180 jd0_ += 367 * ((int)month_ - 2 -(mi*12)) / 12;
00181 jd0_ -= 3 * ((yp+100+mi)/100)/4;
00182 }
00183
00191 inline void JD0_to_gregorian(
00193 const int& jd0_,
00195 int& year_,
00197 int& month_,
00199 int& dom_ )
00200 {
00201 int x = jd0_ + 68569;
00202 int n = 4 * x / 146097;
00203 x = x - ((146097*n+3)/4);
00204 int it = 4000 * (x+1) / 1461001;
00205 x = x - (1461*it/4) + 31;
00206 int m = 80 * x / 2447;
00207 int d = x - (2447*m/80);
00208 x = m/11;
00209 m = m+2-12*x;
00210 int y = 100 * (n-49) + it + x;
00211
00212 year_ = y;
00213 month_ = (int)m;
00214 dom_ = (int)d;
00215 }
00216
00224 inline int JD0_to_DOW_index(
00226 const double& jd0_)
00227 {
00228 int j = (int) jd0_ + 1;
00229 return (j % 7);
00230 }
00231
00232 #endif
00233