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 //extern _CACDayOfMonthLimitType _CACDayOfMonthLimit[];
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     /*static CPKIFTime now();
00066     static CPKIFTime today();*/
00067 
00068     CPKIFTime();
00069     CPKIFTime(const CPKIFTime& time_);
00070     //CPKIFTime(const CACX509V3Time time);
00071     CPKIFTime(const char *time, TimeType type);
00072     CPKIFTime(const char* time);
00073     ~CPKIFTime();
00074 
00075     //------------------------------------------------------------------
00076     // Properties
00077     //------------------------------------------------------------------
00078 
00079     int  year() const;
00080     int month() const;
00081     int dayOfMonth() const;
00082     //int julianDay() const;
00083     //CACDayOfWeek::Type dayOfWeek() const;
00084     int hours() const;
00085     int minutes() const;
00086     int seconds() const;
00087 
00088     /*CPKIFTime startOfDay() const;
00089     CPKIFTime startOfWeek() const;
00090     CPKIFTime startOfMonth() const;
00091     CPKIFTime startOfYear() const;*/
00092 
00093     //------------------------------------------------------------------
00094     // Operations
00095     //------------------------------------------------------------------
00096 
00097     // Print and parse
00098     const char* GetTime() const;
00099 
00100     // Modification
00101     void set(
00102         int  year_, 
00103         int month_, 
00104         int dom_, 
00105         int hours_, 
00106         int minutes_, 
00107         int seconds_ );
00108     //void setJulian(
00109     //  int  year_, 
00110     //  int julianDay_,
00111     //  int hours_, 
00112     //  int minutes_, 
00113     //  int seconds_ );
00114     //void addDays( int days_ );
00115     //void addYears( int years_ );
00116 
00117     //------------------------------------------------------------------
00118     // Operators
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 // The following routines convert a gregorian calendar date to a Julian Day, and vice
00142 // versa.  Julian Day is defined as the day index starting on 1 January 4713 B.C. 
00143 // (1 January -4712 in astronomical years).
00144 //
00145 // These conversions are explained in the following book:
00146 // Standard C Date/Time Library
00147 // Programming the World's Calendars and Clocks
00148 // Lance Latham (Author)
00149 // Published by: R&D Books, 1601 West 23rd Street, Suite 200, Lawrence, KS 66046, USA
00150 // Distributed by: Publishers Group West, PO Box 8843, Emeryville, CA 94662, USA
00151 // ISBN: 0-87930-496-0
00152 // 1998
00153 //
00154 // The author claims to have adapted the routines from FORTRAN subroutine by Henry F. Fliegel
00155 // and Thomas C. Van Flandern, CACM, v 11, n 10, OCT 1968, page 657.
00156 // 
00157 //----------------------------------------------------------------------------------------------------
00158 // Adapted from grep2jd0.c (see ISBN 0-87930-496-0)
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 // Adapted from jd02greg.c (see ISBN 0-87930-496-0)
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 // Adapted from dowindxj.c (see ISBN 0-87930-496-0)
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 

Generated on Mon Nov 15 11:15:55 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6