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
00033 #define MAX_TIMESTR_SIZE 64
00034
00035 #define LOG_TTMERR(stat) (mStatus = stat, stat)
00036
00037
00039
00040
00041
00042
00043
00044
00045
00046
00064 class EXTRTCLASS ASN1TTime {
00065 public:
00066 short mYear;
00067 short mMonth;
00068 short mDay;
00069 short mHour;
00070 short mMinute;
00071 short mSecond;
00072 short mDiffHour;
00073 short mDiffMin;
00074 int mSecFraction;
00075 int mSecFracLen;
00076 int mStatus;
00077 OSBOOL mbUtcFlag;
00078 OSBOOL mbDerRules;
00079
00080 enum {
00081 January = 1, Jan = 1,
00082 February = 2, Feb = 2,
00083 March = 3, Mar = 3,
00084 April = 4, Apr = 4,
00085 May = 5,
00086 June = 6, Jun = 6,
00087 July = 7, Jul = 7,
00088 August = 8, Aug = 8,
00089 September = 9, Sep = 9,
00090 October = 10, Oct = 10,
00091 November = 11, Nov = 11,
00092 December = 12, Dec = 12
00093 };
00094
00095 EXTRTMETHOD ASN1TTime ();
00096
00103 EXTRTMETHOD ASN1TTime (OSBOOL useDerRules);
00104
00105
00111 EXTRTMETHOD ASN1TTime (const ASN1TTime& original);
00112
00116 virtual EXTRTMETHOD ~ASN1TTime();
00117
00128 virtual EXTRTMETHOD int getYear() const;
00129
00143 virtual EXTRTMETHOD int getMonth() const;
00144
00156 virtual EXTRTMETHOD int getDay() const;
00157
00169 virtual EXTRTMETHOD int getHour() const;
00170
00181 virtual EXTRTMETHOD int getMinute() const;
00182
00193 virtual EXTRTMETHOD int getSecond() const;
00194
00204 virtual EXTRTMETHOD int getFraction() const;
00205
00217 virtual EXTRTMETHOD double getFractionAsDouble() const;
00218
00228 virtual EXTRTMETHOD int getFractionStr(char* const pBuf, size_t bufSize) const;
00229
00238 virtual EXTRTMETHOD int getFractionLen() const;
00239
00254 virtual EXTRTMETHOD int getDiffHour() const;
00255
00270 virtual EXTRTMETHOD int getDiffMinute() const;
00271
00286 virtual EXTRTMETHOD int getDiff() const;
00287
00296 virtual EXTRTMETHOD OSBOOL getUTC() const;
00297
00313 virtual EXTRTMETHOD time_t getTime() const;
00314
00319 void setDER (OSBOOL bvalue) { mbDerRules = bvalue; }
00320
00332 virtual EXTRTMETHOD int setUTC(OSBOOL utc);
00333
00345 virtual EXTRTMETHOD int setYear(short year_);
00346
00361 virtual EXTRTMETHOD int setMonth(short month_);
00362
00375 virtual EXTRTMETHOD int setDay(short day_);
00376
00389 virtual EXTRTMETHOD int setHour(short hour_);
00390
00402 virtual EXTRTMETHOD int setMinute(short minute_);
00403
00415 virtual EXTRTMETHOD int setSecond(short second_);
00416
00432 virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
00433
00445 virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
00446
00456 virtual EXTRTMETHOD int setFraction (char const* frac);
00457
00474 virtual int setTime(time_t time, OSBOOL diffTime) = 0;
00475
00493 virtual EXTRTMETHOD int setDiffHour(short dhour);
00494
00513 virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
00514
00531 virtual EXTRTMETHOD int setDiff(short inMinutes);
00532
00545 virtual int parseString (const char* string) = 0;
00546
00553 virtual EXTRTMETHOD void clear();
00554
00565 virtual int compileString (char* pbuf, size_t bufsize) const = 0;
00566
00571 virtual EXTRTMETHOD int equals (const ASN1TTime&) const;
00572
00580 EXTRTMETHOD const char* toString (char* pbuf, size_t bufsize) const;
00581
00588 EXTRTMETHOD const char* toString (OSCTXT* pctxt) const;
00589
00597 EXTRTMETHOD const char* toString () const;
00598
00599 EXTRTMETHOD const ASN1TTime& operator = (const ASN1TTime& );
00600 virtual EXTRTMETHOD OSBOOL operator == (const ASN1TTime&) const;
00601 virtual EXTRTMETHOD OSBOOL operator != (const ASN1TTime&) const;
00602 virtual EXTRTMETHOD OSBOOL operator > (const ASN1TTime&) const;
00603 virtual EXTRTMETHOD OSBOOL operator < (const ASN1TTime&) const;
00604 virtual EXTRTMETHOD OSBOOL operator >= (const ASN1TTime&) const;
00605 virtual EXTRTMETHOD OSBOOL operator <= (const ASN1TTime&) const;
00606
00607 protected:
00608 EXTRTMETHOD static int checkDate (int day, int month, int year);
00609 EXTRTMETHOD void privateInit ();
00610
00611 EXTRTMETHOD static void addMilliseconds (int deltaMs,
00612 short& year, short& month, short& day,
00613 short& hour, short& minute,
00614 short& second, int& secFraction,
00615 int secFracLen);
00616 EXTRTMETHOD static void addDays (int deltaDays, short& year, short& month, short& day);
00617
00618 EXTRTMETHOD int getDaysNum () const;
00619 EXTRTMETHOD long getMillisNum () const;
00620
00621 EXTRTMETHOD static short daysInMonth(int i);
00622 EXTRTMETHOD static int daysAfterMonth(int i);
00623
00624 } ;
00625
00630 class EXTRTCLASS ASN1TGeneralizedTime : public ASN1TTime {
00631 public:
00632
00636 inline ASN1TGeneralizedTime () {}
00637
00644 EXTRTMETHOD ASN1TGeneralizedTime(const char* buf, OSBOOL useDerRules = FALSE);
00645
00651 inline ASN1TGeneralizedTime(OSBOOL useDerRules) :
00652 ASN1TTime (useDerRules) {}
00653
00657 inline ASN1TGeneralizedTime (const ASN1TGeneralizedTime& original) :
00658 ASN1TTime (original) {}
00659
00669 EXTRTMETHOD int getCentury() const;
00670
00680 EXTRTMETHOD int setCentury(short century);
00681
00696 EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
00697
00705 EXTRTMETHOD int parseString (const char* string);
00706
00707 inline const ASN1TGeneralizedTime& operator =
00708 (const ASN1TGeneralizedTime& tm)
00709 {
00710 return (const ASN1TGeneralizedTime&) ASN1TTime::operator = (tm);
00711 }
00712
00723 EXTRTMETHOD int compileString (char* pbuf, size_t bufsize) const;
00724 } ;
00725
00730 class EXTRTCLASS ASN1TUTCTime : public ASN1TTime {
00731 public:
00732
00736 EXTRTMETHOD ASN1TUTCTime ();
00737
00744 EXTRTMETHOD ASN1TUTCTime(const char* timeStr, OSBOOL useDerRules = FALSE);
00745
00751 EXTRTMETHOD ASN1TUTCTime(OSBOOL useDerRules);
00752
00756 ASN1TUTCTime (const ASN1TUTCTime& original) :
00757 ASN1TTime (original) {}
00758
00773 EXTRTMETHOD int setYear(short year_);
00774
00786 EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
00787
00799 EXTRTMETHOD int setUTC (OSBOOL utc);
00800
00804 EXTRTMETHOD void clear();
00805
00816 EXTRTMETHOD int compileString (char* pbuf, size_t bufsize) const;
00817
00827 EXTRTMETHOD int parseString(const char* string);
00828
00829 const ASN1TUTCTime& operator = (const ASN1TUTCTime& tm) {
00830 return (ASN1TUTCTime&) ASN1TTime::operator = (tm);
00831 }
00832
00833 protected:
00834
00835
00836
00837
00838 EXTRTMETHOD int getFraction() const;
00839
00840
00841
00842
00843
00844 EXTRTMETHOD int setFraction (int fraction, int fracLen = -1);
00845
00846 } ;
00847 #endif //__ASN1TTIME_H__
00848