ASN1C C/C++ Common Runtime  ASN1C v7.2.x
ASN1TTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2018 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
24 
25 #ifndef __ASN1TTIME_H__
26 #define __ASN1TTIME_H__
27 
28 #ifndef _WIN32_WCE
29 #include <time.h>
30 #endif
31 #include "rtsrc/asn1CppTypes.h"
32 
34 #define MAX_TIMESTR_SIZE 64
35 
42 #define LOG_TTMERR(stat) (mStatus = stat, stat)
43 
44 
46 //
47 // ASN1TTime
48 //
49 // ISO 8601 time and date for ITU-T X.680.
50 //
51 // Author Artem Bolgar.
52 //
53 
71 class EXTRTCLASS ASN1TTime {
72  public:
76  short mYear;
77 
81  short mMonth;
82 
86  short mDay;
87 
91  short mHour;
92 
96  short mMinute;
97 
101  short mSecond;
102 
106  short mDiffHour;
107 
111  short mDiffMin;
112 
117 
122 
126  int mStatus;
127 
131  OSBOOL mbUtcFlag;
132 
137  OSBOOL mbDerRules;
138 
139  enum {
140  January = 1, Jan = 1,
141  February = 2, Feb = 2,
142  March = 3, Mar = 3,
143  April = 4, Apr = 4,
144  May = 5,
145  June = 6, Jun = 6,
146  July = 7, Jul = 7,
147  August = 8, Aug = 8,
148  September = 9, Sep = 9,
149  October = 10, Oct = 10,
150  November = 11, Nov = 11,
151  December = 12, Dec = 12
152  };
153 
157  EXTRTMETHOD ASN1TTime ();
158 
165  EXTRTMETHOD ASN1TTime (OSBOOL useDerRules);
166 
167 
173  EXTRTMETHOD ASN1TTime (const ASN1TTime& original);
174 
178  virtual EXTRTMETHOD ~ASN1TTime();
179 
190  virtual EXTRTMETHOD int getYear() const;
191 
205  virtual EXTRTMETHOD int getMonth() const;
206 
218  virtual EXTRTMETHOD int getDay() const;
219 
231  virtual EXTRTMETHOD int getHour() const;
232 
243  virtual EXTRTMETHOD int getMinute() const;
244 
255  virtual EXTRTMETHOD int getSecond() const;
256 
266  virtual EXTRTMETHOD int getFraction() const;
267 
279  virtual EXTRTMETHOD double getFractionAsDouble() const;
280 
290  virtual EXTRTMETHOD int getFractionStr(char* const pBuf, size_t bufSize) const;
291 
300  virtual EXTRTMETHOD int getFractionLen() const;
301 
316  virtual EXTRTMETHOD int getDiffHour() const;
317 
332  virtual EXTRTMETHOD int getDiffMinute() const;
333 
348  virtual EXTRTMETHOD int getDiff() const;
349 
358  virtual EXTRTMETHOD OSBOOL getUTC() const;
359 
375  virtual EXTRTMETHOD time_t getTime() const;
376 
381  void setDER (OSBOOL bvalue) { mbDerRules = bvalue; }
382 
394  virtual EXTRTMETHOD int setUTC(OSBOOL utc);
395 
407  virtual EXTRTMETHOD int setYear(short year_);
408 
423  virtual EXTRTMETHOD int setMonth(short month_);
424 
437  virtual EXTRTMETHOD int setDay(short day_);
438 
451  virtual EXTRTMETHOD int setHour(short hour_);
452 
464  virtual EXTRTMETHOD int setMinute(short minute_);
465 
477  virtual EXTRTMETHOD int setSecond(short second_);
478 
494  virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
495 
507  virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
508 
518  virtual EXTRTMETHOD int setFraction (char const* frac);
519 
536  virtual int setTime(time_t time, OSBOOL diffTime) = 0;
537 
555  virtual EXTRTMETHOD int setDiffHour(short dhour);
556 
575  virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
576 
593  virtual EXTRTMETHOD int setDiff(short inMinutes);
594 
607  virtual int parseString (const char* string) = 0;
608 
615  virtual EXTRTMETHOD void clear();
616 
627  virtual int compileString (char* pbuf, size_t bufsize) const = 0;
628 
633  virtual EXTRTMETHOD int equals (const ASN1TTime&) const;
634 
642  EXTRTMETHOD const char* toString (char* pbuf, size_t bufsize) const;
643 
650  EXTRTMETHOD const char* toString (OSCTXT* pctxt) const;
651 
659  EXTRTMETHOD const char* toString () const;
660 
661  EXTRTMETHOD const ASN1TTime& operator = (const ASN1TTime& );
662  virtual EXTRTMETHOD OSBOOL operator == (const ASN1TTime&) const;
663  virtual EXTRTMETHOD OSBOOL operator != (const ASN1TTime&) const;
664  virtual EXTRTMETHOD OSBOOL operator > (const ASN1TTime&) const;
665  virtual EXTRTMETHOD OSBOOL operator < (const ASN1TTime&) const;
666  virtual EXTRTMETHOD OSBOOL operator >= (const ASN1TTime&) const;
667  virtual EXTRTMETHOD OSBOOL operator <= (const ASN1TTime&) const;
668 
669  protected:
670  EXTRTMETHOD static int checkDate (int day, int month, int year);
671  EXTRTMETHOD void privateInit ();
672 
673  EXTRTMETHOD static void addMilliseconds (int deltaMs,
674  short& year, short& month, short& day,
675  short& hour, short& minute,
676  short& second, int& secFraction,
677  int secFracLen);
678  EXTRTMETHOD static void addDays (int deltaDays, short& year, short& month, short& day);
679 
680  EXTRTMETHOD int getDaysNum () const;
681  EXTRTMETHOD long getMillisNum () const;
682 
683  EXTRTMETHOD static short daysInMonth(int i);
684  EXTRTMETHOD static int daysAfterMonth(int i);
685  int ncharsToInt (const char* str, OSSIZE nchars, int& value);
686 } ;
687 
692 class EXTRTCLASS ASN1TGeneralizedTime : public ASN1TTime {
693  public:
694 
698  inline ASN1TGeneralizedTime () {}
699 
706  EXTRTMETHOD ASN1TGeneralizedTime(const char* buf, OSBOOL useDerRules = FALSE);
707 
713  inline ASN1TGeneralizedTime(OSBOOL useDerRules) :
714  ASN1TTime (useDerRules) {}
715 
719  inline ASN1TGeneralizedTime (const ASN1TGeneralizedTime& original) :
720  ASN1TTime (original) {}
721 
731  EXTRTMETHOD int getCentury() const;
732 
742  EXTRTMETHOD int setCentury(short century);
743 
758  EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
759 
767  EXTRTMETHOD int parseString (const char* string);
768 
769  inline const ASN1TGeneralizedTime& operator =
770  (const ASN1TGeneralizedTime& tm)
771  {
772  return (const ASN1TGeneralizedTime&) ASN1TTime::operator = (tm);
773  }
774 
785  EXTRTMETHOD int compileString (char* pbuf, size_t bufsize) const;
786 } ;
787 
792 class EXTRTCLASS ASN1TUTCTime : public ASN1TTime {
793  public:
794 
798  EXTRTMETHOD ASN1TUTCTime ();
799 
806  EXTRTMETHOD ASN1TUTCTime(const char* timeStr, OSBOOL useDerRules = FALSE);
807 
813  EXTRTMETHOD ASN1TUTCTime(OSBOOL useDerRules);
814 
818  ASN1TUTCTime (const ASN1TUTCTime& original) :
819  ASN1TTime (original) {}
820 
835  EXTRTMETHOD int setYear(short year_);
836 
848  EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
849 
861  EXTRTMETHOD int setUTC (OSBOOL utc);
862 
866  EXTRTMETHOD void clear();
867 
878  EXTRTMETHOD int compileString (char* pbuf, size_t bufsize) const;
879 
889  EXTRTMETHOD int parseString(const char* string);
890 
891  const ASN1TUTCTime& operator = (const ASN1TUTCTime& tm) {
892  return (ASN1TUTCTime&) ASN1TTime::operator = (tm);
893  }
894 
895  protected:
896  /*
897  * Gets fraction of second, 0..9.
898  * Returns: Zero.
899  */
900  EXTRTMETHOD int getFraction() const;
901 
902  /*
903  * This method is not applicable for ASN1TUTCTime.
904  * Returns RTERR_NOTSUPP.
905  */
906  EXTRTMETHOD int setFraction (int fraction, int fracLen = -1);
907 
908 } ;
909 #endif //__ASN1TTIME_H__
910 
ASN1TGeneralizedTime()
Definition: ASN1TTime.h:698
short mSecond
Definition: ASN1TTime.h:101
int operator>=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:71
short mDiffHour
Definition: ASN1TTime.h:106
short mMonth
Definition: ASN1TTime.h:81
int operator<=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:792
virtual int setTime(time_t time, OSBOOL diffTime)=0
int operator<(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
virtual EXTRTMETHOD int getFraction() const
ASN1TGeneralizedTime(OSBOOL useDerRules)
Definition: ASN1TTime.h:713
int operator==(const ASN1OBJID &lhs, const ASN1OBJID &rhs)
int mStatus
Definition: ASN1TTime.h:126
OSBOOL mbUtcFlag
Definition: ASN1TTime.h:131
Definition: ASN1TTime.h:692
short mYear
Definition: ASN1TTime.h:76
ASN1TUTCTime(const ASN1TUTCTime &original)
Definition: ASN1TTime.h:818
virtual EXTRTMETHOD void clear()
virtual EXTRTMETHOD int setFraction(int fraction, int fracLen=-1)
virtual EXTRTMETHOD int setYear(short year_)
OSBOOL mbDerRules
Definition: ASN1TTime.h:137
virtual EXTRTMETHOD int setUTC(OSBOOL utc)
short mMinute
Definition: ASN1TTime.h:96
int mSecFracLen
Definition: ASN1TTime.h:121
short mDiffMin
Definition: ASN1TTime.h:111
virtual int compileString(char *pbuf, size_t bufsize) const =0
short mDay
Definition: ASN1TTime.h:86
Definition: rtxContext.h:185
void setDER(OSBOOL bvalue)
Definition: ASN1TTime.h:381
virtual int parseString(const char *string)=0
int mSecFraction
Definition: ASN1TTime.h:116
short mHour
Definition: ASN1TTime.h:91
int operator!=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
int operator>(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
ASN1TGeneralizedTime(const ASN1TGeneralizedTime &original)
Definition: ASN1TTime.h:719