Home > Support > Documentation

ASN1TTime.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997-2007 Objective Systems, Inc.
00003  *
00004  * This software is furnished under a license and may be used and copied
00005  * only in accordance with the terms of such license and with the
00006  * inclusion of the above copyright notice. This software or any other
00007  * copies thereof may not be provided or otherwise made available to any
00008  * other person. No title to and ownership of the software is hereby
00009  * transferred.
00010  *
00011  * The information in this software is subject to change without notice
00012  * and should not be construed as a commitment by Objective Systems, Inc.
00013  *
00014  * PROPRIETARY NOTICE
00015  *
00016  * This software is an unpublished work subject to a confidentiality agreement
00017  * and is protected by copyright and trade secret law.  Unauthorized copying,
00018  * redistribution or other use of this work is prohibited.
00019  *
00020  * The above notice of copyright on this source code product does not indicate
00021  * any actual or intended publication of such source code.
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 // ASN1TTime
00041 // 
00042 // ISO 8601 time and date for ITU-T X.680. 
00043 //
00044 // Author Artem Bolgar.
00045 //
00046 
00064 class EXTERNRT 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    static short mDaysInMonth[];
00080 
00081    enum {
00082       January = 1,   Jan = 1,
00083       February = 2,  Feb = 2,
00084       March = 3,     Mar = 3,
00085       April = 4,     Apr = 4,
00086       May = 5,
00087       June = 6,      Jun = 6,
00088       July = 7,      Jul = 7,
00089       August = 8,    Aug = 8,
00090       September = 9, Sep = 9,
00091       October = 10,  Oct = 10,
00092       November = 11, Nov = 11,
00093       December = 12, Dec = 12
00094    }; 
00095 
00096    ASN1TTime (); 
00097 
00104    ASN1TTime (OSBOOL useDerRules); 
00105    
00106    
00112    ASN1TTime (const ASN1TTime& original); 
00113 
00117    virtual ~ASN1TTime();
00118 
00129    virtual int getYear() const;
00130 
00144    virtual int getMonth() const;
00145 
00157    virtual int getDay() const;
00158 
00170    virtual int getHour() const;
00171 
00182    virtual int getMinute() const;
00183 
00194    virtual int getSecond() const;
00195 
00205    virtual int getFraction() const;
00206 
00218    virtual double getFractionAsDouble() const;
00219 
00229    virtual int getFractionStr(char* const pBuf, size_t bufSize) const;
00230 
00239    virtual int getFractionLen() const;
00240 
00255    virtual int getDiffHour() const;
00256 
00271    virtual int getDiffMinute() const;
00272 
00287    virtual int getDiff() const;
00288 
00297    virtual OSBOOL getUTC() const;
00298 
00314    virtual time_t getTime() const;
00315 
00320    void setDER (OSBOOL bvalue) { mbDerRules = bvalue; }
00321 
00333    virtual int setUTC(OSBOOL utc);
00334 
00346    virtual int setYear(int year_);
00347 
00362    virtual int setMonth(int month_);
00363 
00376    virtual int setDay(int day_);
00377 
00390    virtual int setHour(int hour_);
00391 
00403    virtual int setMinute(int minute_);
00404 
00416    virtual int setSecond(int second_);
00417 
00433    virtual int setFraction(int fraction, int fracLen = -1);
00434 
00446    virtual int setFraction (double frac, int fracLen);
00447 
00457    virtual int setFraction (char const* frac);
00458 
00475    virtual int setTime(time_t time, OSBOOL diffTime) = 0;
00476 
00494    virtual int setDiffHour(int dhour);
00495 
00514    virtual int setDiff(int dhour, int dminute);
00515 
00532    virtual int setDiff(int inMinutes);
00533 
00546    virtual int parseString (const char* string) = 0;
00547 
00554    virtual void clear();
00555 
00566    virtual int compileString (char* pbuf, size_t bufsize) const = 0;
00567 
00572    virtual int equals (const ASN1TTime&) const;
00573 
00581    const char* toString (char* pbuf, size_t bufsize) const;
00582 
00589    const char* toString (OSCTXT* pctxt) const;
00590 
00598    const char* toString () const;
00599 
00600    const ASN1TTime& operator = (const ASN1TTime& );
00601    virtual OSBOOL operator == (const ASN1TTime&) const;
00602    virtual OSBOOL operator != (const ASN1TTime&) const;
00603    virtual OSBOOL operator > (const ASN1TTime&) const;
00604    virtual OSBOOL operator < (const ASN1TTime&) const;
00605    virtual OSBOOL operator >= (const ASN1TTime&) const;
00606    virtual OSBOOL operator <= (const ASN1TTime&) const;
00607 
00608  protected:
00609    static int checkDate (int day, int month, int year);
00610    void privateInit ();
00611 
00612    static void addMilliseconds (int deltaMs, 
00613                                 short& year, short& month, short& day,
00614                                 short& hour, short& minute, 
00615                                 short& second, int& secFraction,
00616                                 int secFracLen);
00617    static void addDays (int deltaDays, short& year, short& month, short& day);
00618 
00619    int getDaysNum () const;
00620    long getMillisNum () const;
00621 } ;
00622 
00627 class EXTERNRT ASN1TGeneralizedTime : public ASN1TTime {
00628  public:
00629 
00633    inline ASN1TGeneralizedTime () {}
00634     
00641    ASN1TGeneralizedTime(const char* buf, OSBOOL useDerRules = FALSE); 
00642 
00648    inline ASN1TGeneralizedTime(OSBOOL useDerRules) : 
00649       ASN1TTime (useDerRules) {}
00650 
00654    inline ASN1TGeneralizedTime (const ASN1TGeneralizedTime& original) :
00655       ASN1TTime (original) {}
00656 
00666    int getCentury() const;
00667 
00677    int setCentury(int century);
00678 
00693    int setTime(time_t time, OSBOOL diffTime);
00694 
00702    int parseString (const char* string);
00703 
00704    inline const ASN1TGeneralizedTime& operator = 
00705       (const ASN1TGeneralizedTime& tm) 
00706    {
00707       return (const ASN1TGeneralizedTime&) ASN1TTime::operator = (tm);
00708    }
00709 
00720    int compileString (char* pbuf, size_t bufsize) const;
00721 } ;
00722 
00727 class EXTERNRT ASN1TUTCTime : public ASN1TTime {
00728  public:
00729 
00733    ASN1TUTCTime ();
00734 
00741    ASN1TUTCTime(const char* timeStr, OSBOOL useDerRules = FALSE); 
00742 
00748    ASN1TUTCTime(OSBOOL useDerRules); 
00749 
00753    ASN1TUTCTime (const ASN1TUTCTime& original) :
00754       ASN1TTime (original) {}
00755 
00770    int setYear(int year_);
00771 
00783    int setTime(time_t time, OSBOOL diffTime);
00784 
00796    int setUTC (OSBOOL utc);
00797 
00801    void clear();
00802 
00813    int compileString (char* pbuf, size_t bufsize) const;
00814 
00824    int parseString(const char* string);
00825 
00826    const ASN1TUTCTime& operator = (const ASN1TUTCTime& tm) {
00827       return (ASN1TUTCTime&) ASN1TTime::operator = (tm);
00828    }
00829 
00830  protected:
00831    /* 
00832    * Gets fraction of second, 0..9. 
00833    * Returns: Zero.
00834    */
00835    int getFraction() const;
00836    
00837    /*
00838    * This method is not applicable for ASN1TUTCTime.
00839    * Returns RTERR_NOTSUPP.
00840    */
00841    int setFraction (int fraction, int fracLen = -1);
00842 
00843 } ;
00844 #endif //__ASN1TTIME_H__
00845