ASN1C C/C++ Common Runtime  ASN1C v7.7.x
ASN1TTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2023 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 
66 class EXTRTCLASS ASN1TTime {
67  public:
71  short mYear;
72 
76  short mMonth;
77 
81  short mDay;
82 
86  short mHour;
87 
91  short mMinute;
92 
96  short mSecond;
97 
101  short mDiffHour;
102 
106  short mDiffMin;
107 
112 
117 
121  int mStatus;
122 
126  OSBOOL mbUtcFlag;
127 
132  OSBOOL mbDerRules;
133 
134  enum {
135  January = 1, Jan = 1,
136  February = 2, Feb = 2,
137  March = 3, Mar = 3,
138  April = 4, Apr = 4,
139  May = 5,
140  June = 6, Jun = 6,
141  July = 7, Jul = 7,
142  August = 8, Aug = 8,
143  September = 9, Sep = 9,
144  October = 10, Oct = 10,
145  November = 11, Nov = 11,
146  December = 12, Dec = 12
147  };
148 
152  EXTRTMETHOD ASN1TTime ();
153 
160  EXTRTMETHOD ASN1TTime (OSBOOL useDerRules);
161 
162 
168  EXTRTMETHOD ASN1TTime (const ASN1TTime& original);
169 
173  virtual EXTRTMETHOD ~ASN1TTime();
174 
185  virtual EXTRTMETHOD int getYear() const;
186 
200  virtual EXTRTMETHOD int getMonth() const;
201 
213  virtual EXTRTMETHOD int getDay() const;
214 
226  virtual EXTRTMETHOD int getHour() const;
227 
238  virtual EXTRTMETHOD int getMinute() const;
239 
250  virtual EXTRTMETHOD int getSecond() const;
251 
261  virtual EXTRTMETHOD int getFraction() const;
262 
274  virtual EXTRTMETHOD double getFractionAsDouble() const;
275 
285  virtual EXTRTMETHOD int getFractionStr(char* const pBuf, OSSIZE bufSize) const;
286 
295  virtual EXTRTMETHOD int getFractionLen() const;
296 
311  virtual EXTRTMETHOD int getDiffHour() const;
312 
327  virtual EXTRTMETHOD int getDiffMinute() const;
328 
343  virtual EXTRTMETHOD int getDiff() const;
344 
353  virtual EXTRTMETHOD OSBOOL getUTC() const;
354 
370  virtual EXTRTMETHOD time_t getTime() const;
371 
376  void setDER (OSBOOL bvalue) { mbDerRules = bvalue; }
377 
389  virtual EXTRTMETHOD int setUTC(OSBOOL utc);
390 
402  virtual EXTRTMETHOD int setYear(short year_);
403 
418  virtual EXTRTMETHOD int setMonth(short month_);
419 
432  virtual EXTRTMETHOD int setDay(short day_);
433 
446  virtual EXTRTMETHOD int setHour(short hour_);
447 
459  virtual EXTRTMETHOD int setMinute(short minute_);
460 
472  virtual EXTRTMETHOD int setSecond(short second_);
473 
489  virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
490 
502  virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
503 
513  virtual EXTRTMETHOD int setFraction (char const* frac);
514 
531  virtual int setTime(time_t time, OSBOOL diffTime) = 0;
532 
550  virtual EXTRTMETHOD int setDiffHour(short dhour);
551 
570  virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
571 
588  virtual EXTRTMETHOD int setDiff(short inMinutes);
589 
602  virtual int parseString (const char* string) = 0;
603 
610  virtual EXTRTMETHOD void clear();
611 
622  virtual int compileString (char* pbuf, OSSIZE bufsize) const = 0;
623 
628  virtual EXTRTMETHOD int equals (const ASN1TTime&) const;
629 
637  EXTRTMETHOD const char* toString (char* pbuf, OSSIZE bufsize) const;
638 
648  EXTRTMETHOD char* toString (OSCTXT* pctxt) const;
649 
657  EXTRTMETHOD char* toString () const;
658 
659  EXTRTMETHOD const ASN1TTime& operator = (const ASN1TTime& );
660  virtual EXTRTMETHOD OSBOOL operator == (const ASN1TTime&) const;
661  virtual EXTRTMETHOD OSBOOL operator != (const ASN1TTime&) const;
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 
667  protected:
668  EXTRTMETHOD static int checkDate (int day, int month, int year);
669  EXTRTMETHOD void privateInit ();
670 
671  EXTRTMETHOD static void addMilliseconds (int deltaMs,
672  short& year, short& month, short& day,
673  short& hour, short& minute,
674  short& second, int& secFraction,
675  int secFracLen);
676  EXTRTMETHOD static void addDays (int deltaDays, short& year, short& month, short& day);
677 
678  EXTRTMETHOD int getDaysNum () const;
679  EXTRTMETHOD long getMillisNum () const;
680 
681  EXTRTMETHOD static short daysInMonth(int i);
682  EXTRTMETHOD static int daysAfterMonth(int i);
683  int ncharsToInt (const char* str, OSSIZE nchars, int& value);
684 } ;
685 
690 class EXTRTCLASS ASN1TGeneralizedTime : public ASN1TTime {
691  public:
692 
696  inline ASN1TGeneralizedTime () {}
697 
704  EXTRTMETHOD ASN1TGeneralizedTime(const char* buf, OSBOOL useDerRules = FALSE);
705 
711  inline ASN1TGeneralizedTime(OSBOOL useDerRules) :
712  ASN1TTime (useDerRules) {}
713 
717  inline ASN1TGeneralizedTime (const ASN1TGeneralizedTime& original) :
718  ASN1TTime (original) {}
719 
729  EXTRTMETHOD int getCentury() const;
730 
740  EXTRTMETHOD int setCentury(short century);
741 
756  EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
757 
765  EXTRTMETHOD int parseString (const char* string);
766 
767  inline const ASN1TGeneralizedTime& operator =
768  (const ASN1TGeneralizedTime& tm)
769  {
770  return (const ASN1TGeneralizedTime&) ASN1TTime::operator = (tm);
771  }
772 
783  EXTRTMETHOD int compileString (char* pbuf, OSSIZE bufsize) const;
784 } ;
785 
790 class EXTRTCLASS ASN1TUTCTime : public ASN1TTime {
791  public:
792 
796  EXTRTMETHOD ASN1TUTCTime ();
797 
804  EXTRTMETHOD ASN1TUTCTime(const char* timeStr, OSBOOL useDerRules = FALSE);
805 
811  EXTRTMETHOD ASN1TUTCTime(OSBOOL useDerRules);
812 
816  ASN1TUTCTime (const ASN1TUTCTime& original) :
817  ASN1TTime (original) {}
818 
833  EXTRTMETHOD int setYear(short year_);
834 
846  EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
847 
859  EXTRTMETHOD int setUTC (OSBOOL utc);
860 
864  EXTRTMETHOD void clear();
865 
876  EXTRTMETHOD int compileString (char* pbuf, OSSIZE bufsize) const;
877 
887  EXTRTMETHOD int parseString(const char* string);
888 
889  const ASN1TUTCTime& operator = (const ASN1TUTCTime& tm) {
890  return (ASN1TUTCTime&) ASN1TTime::operator = (tm);
891  }
892 
893  protected:
894  /*
895  * Gets fraction of second, 0..9.
896  * Returns: Zero.
897  */
898  EXTRTMETHOD int getFraction() const;
899 
900  /*
901  * This method is not applicable for ASN1TUTCTime.
902  * Returns RTERR_NOTSUPP.
903  */
904  EXTRTMETHOD int setFraction (int fraction, int fracLen = -1);
905 
906 } ;
907 #endif //__ASN1TTIME_H__
908 
909  // end ingroup cppruntime asn1data asn1ctime
ASN1TGeneralizedTime()
Definition: ASN1TTime.h:696
short mSecond
Definition: ASN1TTime.h:96
int operator>=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:66
short mDiffHour
Definition: ASN1TTime.h:101
short mMonth
Definition: ASN1TTime.h:76
int operator<=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:790
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:711
int operator==(const ASN1OBJID &lhs, const ASN1OBJID &rhs)
int mStatus
Definition: ASN1TTime.h:121
OSBOOL mbUtcFlag
Definition: ASN1TTime.h:126
Definition: ASN1TTime.h:690
short mYear
Definition: ASN1TTime.h:71
ASN1TUTCTime(const ASN1TUTCTime &original)
Definition: ASN1TTime.h:816
virtual EXTRTMETHOD void clear()
virtual EXTRTMETHOD int setFraction(int fraction, int fracLen=-1)
virtual EXTRTMETHOD int setYear(short year_)
OSBOOL mbDerRules
Definition: ASN1TTime.h:132
virtual EXTRTMETHOD int setUTC(OSBOOL utc)
virtual int compileString(char *pbuf, OSSIZE bufsize) const =0
short mMinute
Definition: ASN1TTime.h:91
int mSecFracLen
Definition: ASN1TTime.h:116
short mDiffMin
Definition: ASN1TTime.h:106
short mDay
Definition: ASN1TTime.h:81
Definition: rtxContext.h:198
void setDER(OSBOOL bvalue)
Definition: ASN1TTime.h:376
virtual int parseString(const char *string)=0
int mSecFraction
Definition: ASN1TTime.h:111
short mHour
Definition: ASN1TTime.h:86
int operator!=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
int operator>(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
ASN1TGeneralizedTime(const ASN1TGeneralizedTime &original)
Definition: ASN1TTime.h:717