00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __ASN1TTIME_H__
00026 #define __ASN1TTIME_H__
00027
00028 #ifndef _WIN32_WCE
00029 #include <time.h>
00030 #endif
00031 #include "rtsrc/asn1CppTypes.h"
00032
00034 #define MAX_TIMESTR_SIZE 64
00035
00042 #define LOG_TTMERR(stat) (mStatus = stat, stat)
00043
00044
00046
00047
00048
00049
00050
00051
00052
00053
00071 class EXTRTCLASS ASN1TTime {
00072 public:
00076 short mYear;
00077
00081 short mMonth;
00082
00086 short mDay;
00087
00091 short mHour;
00092
00096 short mMinute;
00097
00101 short mSecond;
00102
00106 short mDiffHour;
00107
00111 short mDiffMin;
00112
00116 int mSecFraction;
00117
00121 int mSecFracLen;
00122
00126 int mStatus;
00127
00131 OSBOOL mbUtcFlag;
00132
00137 OSBOOL mbDerRules;
00138
00139 enum {
00140 January = 1, Jan = 1,
00141 February = 2, Feb = 2,
00142 March = 3, Mar = 3,
00143 April = 4, Apr = 4,
00144 May = 5,
00145 June = 6, Jun = 6,
00146 July = 7, Jul = 7,
00147 August = 8, Aug = 8,
00148 September = 9, Sep = 9,
00149 October = 10, Oct = 10,
00150 November = 11, Nov = 11,
00151 December = 12, Dec = 12
00152 };
00153
00157 EXTRTMETHOD ASN1TTime ();
00158
00165 EXTRTMETHOD ASN1TTime (OSBOOL useDerRules);
00166
00167
00173 EXTRTMETHOD ASN1TTime (const ASN1TTime& original);
00174
00178 virtual EXTRTMETHOD ~ASN1TTime();
00179
00190 virtual EXTRTMETHOD int getYear() const;
00191
00205 virtual EXTRTMETHOD int getMonth() const;
00206
00218 virtual EXTRTMETHOD int getDay() const;
00219
00231 virtual EXTRTMETHOD int getHour() const;
00232
00243 virtual EXTRTMETHOD int getMinute() const;
00244
00255 virtual EXTRTMETHOD int getSecond() const;
00256
00266 virtual EXTRTMETHOD int getFraction() const;
00267
00279 virtual EXTRTMETHOD double getFractionAsDouble() const;
00280
00290 virtual EXTRTMETHOD int getFractionStr(char* const pBuf, size_t bufSize) const;
00291
00300 virtual EXTRTMETHOD int getFractionLen() const;
00301
00316 virtual EXTRTMETHOD int getDiffHour() const;
00317
00332 virtual EXTRTMETHOD int getDiffMinute() const;
00333
00348 virtual EXTRTMETHOD int getDiff() const;
00349
00358 virtual EXTRTMETHOD OSBOOL getUTC() const;
00359
00375 virtual EXTRTMETHOD time_t getTime() const;
00376
00381 void setDER (OSBOOL bvalue) { mbDerRules = bvalue; }
00382
00394 virtual EXTRTMETHOD int setUTC(OSBOOL utc);
00395
00407 virtual EXTRTMETHOD int setYear(short year_);
00408
00423 virtual EXTRTMETHOD int setMonth(short month_);
00424
00437 virtual EXTRTMETHOD int setDay(short day_);
00438
00451 virtual EXTRTMETHOD int setHour(short hour_);
00452
00464 virtual EXTRTMETHOD int setMinute(short minute_);
00465
00477 virtual EXTRTMETHOD int setSecond(short second_);
00478
00494 virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
00495
00507 virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
00508
00518 virtual EXTRTMETHOD int setFraction (char const* frac);
00519
00536 virtual int setTime(time_t time, OSBOOL diffTime) = 0;
00537
00555 virtual EXTRTMETHOD int setDiffHour(short dhour);
00556
00575 virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
00576
00593 virtual EXTRTMETHOD int setDiff(short inMinutes);
00594
00607 virtual int parseString (const char* string) = 0;
00608
00615 virtual EXTRTMETHOD void clear();
00616
00627 virtual int compileString (char* pbuf, size_t bufsize) const = 0;
00628
00633 virtual EXTRTMETHOD int equals (const ASN1TTime&) const;
00634
00642 EXTRTMETHOD const char* toString (char* pbuf, size_t bufsize) const;
00643
00650 EXTRTMETHOD const char* toString (OSCTXT* pctxt) const;
00651
00659 EXTRTMETHOD const char* toString () const;
00660
00661 EXTRTMETHOD const ASN1TTime& operator = (const ASN1TTime& );
00662 virtual EXTRTMETHOD OSBOOL operator == (const ASN1TTime&) const;
00663 virtual EXTRTMETHOD OSBOOL operator != (const ASN1TTime&) const;
00664 virtual EXTRTMETHOD OSBOOL operator > (const ASN1TTime&) const;
00665 virtual EXTRTMETHOD OSBOOL operator < (const ASN1TTime&) const;
00666 virtual EXTRTMETHOD OSBOOL operator >= (const ASN1TTime&) const;
00667 virtual EXTRTMETHOD OSBOOL operator <= (const ASN1TTime&) const;
00668
00669 protected:
00670 EXTRTMETHOD static int checkDate (int day, int month, int year);
00671 EXTRTMETHOD void privateInit ();
00672
00673 EXTRTMETHOD static void addMilliseconds (int deltaMs,
00674 short& year, short& month, short& day,
00675 short& hour, short& minute,
00676 short& second, int& secFraction,
00677 int secFracLen);
00678 EXTRTMETHOD static void addDays (int deltaDays, short& year, short& month, short& day);
00679
00680 EXTRTMETHOD int getDaysNum () const;
00681 EXTRTMETHOD long getMillisNum () const;
00682
00683 EXTRTMETHOD static short daysInMonth(int i);
00684 EXTRTMETHOD static int daysAfterMonth(int i);
00685
00686 } ;
00687
00692 class EXTRTCLASS ASN1TGeneralizedTime : public ASN1TTime {
00693 public:
00694
00698 inline ASN1TGeneralizedTime () {}
00699
00706 EXTRTMETHOD ASN1TGeneralizedTime(const char* buf, OSBOOL useDerRules = FALSE);
00707
00713 inline ASN1TGeneralizedTime(OSBOOL useDerRules) :
00714 ASN1TTime (useDerRules) {}
00715
00719 inline ASN1TGeneralizedTime (const ASN1TGeneralizedTime& original) :
00720 ASN1TTime (original) {}
00721
00731 EXTRTMETHOD int getCentury() const;
00732
00742 EXTRTMETHOD int setCentury(short century);
00743
00758 EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
00759
00767 EXTRTMETHOD int parseString (const char* string);
00768
00769 inline const ASN1TGeneralizedTime& operator =
00770 (const ASN1TGeneralizedTime& tm)
00771 {
00772 return (const ASN1TGeneralizedTime&) ASN1TTime::operator = (tm);
00773 }
00774
00785 EXTRTMETHOD int compileString (char* pbuf, size_t bufsize) const;
00786 } ;
00787
00792 class EXTRTCLASS ASN1TUTCTime : public ASN1TTime {
00793 public:
00794
00798 EXTRTMETHOD ASN1TUTCTime ();
00799
00806 EXTRTMETHOD ASN1TUTCTime(const char* timeStr, OSBOOL useDerRules = FALSE);
00807
00813 EXTRTMETHOD ASN1TUTCTime(OSBOOL useDerRules);
00814
00818 ASN1TUTCTime (const ASN1TUTCTime& original) :
00819 ASN1TTime (original) {}
00820
00835 EXTRTMETHOD int setYear(short year_);
00836
00848 EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
00849
00861 EXTRTMETHOD int setUTC (OSBOOL utc);
00862
00866 EXTRTMETHOD void clear();
00867
00878 EXTRTMETHOD int compileString (char* pbuf, size_t bufsize) const;
00879
00889 EXTRTMETHOD int parseString(const char* string);
00890
00891 const ASN1TUTCTime& operator = (const ASN1TUTCTime& tm) {
00892 return (ASN1TUTCTime&) ASN1TTime::operator = (tm);
00893 }
00894
00895 protected:
00896
00897
00898
00899
00900 EXTRTMETHOD int getFraction() const;
00901
00902
00903
00904
00905
00906 EXTRTMETHOD int setFraction (int fraction, int fracLen = -1);
00907
00908 } ;
00909 #endif //__ASN1TTIME_H__
00910