ASN1C C/C++ Common Runtime  ASN1C v7.3.x
ASN1TTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2019 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, OSSIZE 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, OSSIZE bufsize) const = 0;
628 
633  virtual EXTRTMETHOD int equals (const ASN1TTime&) const;
634 
642  EXTRTMETHOD const char* toString (char* pbuf, OSSIZE bufsize) const;
643 
653  EXTRTMETHOD char* toString (OSCTXT* pctxt) const;
654 
662  EXTRTMETHOD char* toString () const;
663 
664  EXTRTMETHOD const ASN1TTime& operator = (const ASN1TTime& );
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  virtual EXTRTMETHOD OSBOOL operator < (const ASN1TTime&) const;
669  virtual EXTRTMETHOD OSBOOL operator >= (const ASN1TTime&) const;
670  virtual EXTRTMETHOD OSBOOL operator <= (const ASN1TTime&) const;
671 
672  protected:
673  EXTRTMETHOD static int checkDate (int day, int month, int year);
674  EXTRTMETHOD void privateInit ();
675 
676  EXTRTMETHOD static void addMilliseconds (int deltaMs,
677  short& year, short& month, short& day,
678  short& hour, short& minute,
679  short& second, int& secFraction,
680  int secFracLen);
681  EXTRTMETHOD static void addDays (int deltaDays, short& year, short& month, short& day);
682 
683  EXTRTMETHOD int getDaysNum () const;
684  EXTRTMETHOD long getMillisNum () const;
685 
686  EXTRTMETHOD static short daysInMonth(int i);
687  EXTRTMETHOD static int daysAfterMonth(int i);
688  int ncharsToInt (const char* str, OSSIZE nchars, int& value);
689 } ;
690 
695 class EXTRTCLASS ASN1TGeneralizedTime : public ASN1TTime {
696  public:
697 
701  inline ASN1TGeneralizedTime () {}
702 
709  EXTRTMETHOD ASN1TGeneralizedTime(const char* buf, OSBOOL useDerRules = FALSE);
710 
716  inline ASN1TGeneralizedTime(OSBOOL useDerRules) :
717  ASN1TTime (useDerRules) {}
718 
722  inline ASN1TGeneralizedTime (const ASN1TGeneralizedTime& original) :
723  ASN1TTime (original) {}
724 
734  EXTRTMETHOD int getCentury() const;
735 
745  EXTRTMETHOD int setCentury(short century);
746 
761  EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
762 
770  EXTRTMETHOD int parseString (const char* string);
771 
772  inline const ASN1TGeneralizedTime& operator =
773  (const ASN1TGeneralizedTime& tm)
774  {
775  return (const ASN1TGeneralizedTime&) ASN1TTime::operator = (tm);
776  }
777 
788  EXTRTMETHOD int compileString (char* pbuf, OSSIZE bufsize) const;
789 } ;
790 
795 class EXTRTCLASS ASN1TUTCTime : public ASN1TTime {
796  public:
797 
801  EXTRTMETHOD ASN1TUTCTime ();
802 
809  EXTRTMETHOD ASN1TUTCTime(const char* timeStr, OSBOOL useDerRules = FALSE);
810 
816  EXTRTMETHOD ASN1TUTCTime(OSBOOL useDerRules);
817 
821  ASN1TUTCTime (const ASN1TUTCTime& original) :
822  ASN1TTime (original) {}
823 
838  EXTRTMETHOD int setYear(short year_);
839 
851  EXTRTMETHOD int setTime(time_t time, OSBOOL diffTime);
852 
864  EXTRTMETHOD int setUTC (OSBOOL utc);
865 
869  EXTRTMETHOD void clear();
870 
881  EXTRTMETHOD int compileString (char* pbuf, OSSIZE bufsize) const;
882 
892  EXTRTMETHOD int parseString(const char* string);
893 
894  const ASN1TUTCTime& operator = (const ASN1TUTCTime& tm) {
895  return (ASN1TUTCTime&) ASN1TTime::operator = (tm);
896  }
897 
898  protected:
899  /*
900  * Gets fraction of second, 0..9.
901  * Returns: Zero.
902  */
903  EXTRTMETHOD int getFraction() const;
904 
905  /*
906  * This method is not applicable for ASN1TUTCTime.
907  * Returns RTERR_NOTSUPP.
908  */
909  EXTRTMETHOD int setFraction (int fraction, int fracLen = -1);
910 
911 } ;
912 #endif //__ASN1TTIME_H__
913 
ASN1TGeneralizedTime()
Definition: ASN1TTime.h:701
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:795
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:716
int operator==(const ASN1OBJID &lhs, const ASN1OBJID &rhs)
int mStatus
Definition: ASN1TTime.h:126
OSBOOL mbUtcFlag
Definition: ASN1TTime.h:131
Definition: ASN1TTime.h:695
short mYear
Definition: ASN1TTime.h:76
ASN1TUTCTime(const ASN1TUTCTime &original)
Definition: ASN1TTime.h:821
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)
virtual int compileString(char *pbuf, OSSIZE bufsize) const =0
short mMinute
Definition: ASN1TTime.h:96
int mSecFracLen
Definition: ASN1TTime.h:121
short mDiffMin
Definition: ASN1TTime.h:111
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:722