ASN1C C/C++ Common Runtime  ASN1C v7.6.x
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members

#include <ASN1TTime.h>

Inheritance diagram for ASN1TTime:
ASN1TGeneralizedTime ASN1TUTCTime

Public Types

enum  {
  January = 1, Jan = 1, February = 2, Feb = 2,
  March = 3, Mar = 3, April = 4, Apr = 4,
  May = 5, June = 6, Jun = 6, July = 7,
  Jul = 7, August = 8, Aug = 8, September = 9,
  Sep = 9, October = 10, Oct = 10, November = 11,
  Nov = 11, December = 12, Dec = 12
}
 

Public Member Functions

EXTRTMETHOD ASN1TTime ()
 
EXTRTMETHOD ASN1TTime (OSBOOL useDerRules)
 
EXTRTMETHOD ASN1TTime (const ASN1TTime &original)
 
virtual EXTRTMETHOD ~ASN1TTime ()
 
virtual EXTRTMETHOD int getYear () const
 
virtual EXTRTMETHOD int getMonth () const
 
virtual EXTRTMETHOD int getDay () const
 
virtual EXTRTMETHOD int getHour () const
 
virtual EXTRTMETHOD int getMinute () const
 
virtual EXTRTMETHOD int getSecond () const
 
virtual EXTRTMETHOD int getFraction () const
 
virtual EXTRTMETHOD double getFractionAsDouble () const
 
virtual EXTRTMETHOD int getFractionStr (char *const pBuf, OSSIZE bufSize) const
 
virtual EXTRTMETHOD int getFractionLen () const
 
virtual EXTRTMETHOD int getDiffHour () const
 
virtual EXTRTMETHOD int getDiffMinute () const
 
virtual EXTRTMETHOD int getDiff () const
 
virtual EXTRTMETHOD OSBOOL getUTC () const
 
virtual EXTRTMETHOD time_t getTime () const
 
void setDER (OSBOOL bvalue)
 
virtual EXTRTMETHOD int setUTC (OSBOOL utc)
 
virtual EXTRTMETHOD int setYear (short year_)
 
virtual EXTRTMETHOD int setMonth (short month_)
 
virtual EXTRTMETHOD int setDay (short day_)
 
virtual EXTRTMETHOD int setHour (short hour_)
 
virtual EXTRTMETHOD int setMinute (short minute_)
 
virtual EXTRTMETHOD int setSecond (short second_)
 
virtual EXTRTMETHOD int setFraction (int fraction, int fracLen=-1)
 
virtual EXTRTMETHOD int setFraction (double frac, int fracLen)
 
virtual EXTRTMETHOD int setFraction (char const *frac)
 
virtual int setTime (time_t time, OSBOOL diffTime)=0
 
virtual EXTRTMETHOD int setDiffHour (short dhour)
 
virtual EXTRTMETHOD int setDiff (short dhour, short dminute)
 
virtual EXTRTMETHOD int setDiff (short inMinutes)
 
virtual int parseString (const char *string)=0
 
virtual EXTRTMETHOD void clear ()
 
virtual int compileString (char *pbuf, OSSIZE bufsize) const =0
 
virtual EXTRTMETHOD int equals (const ASN1TTime &) const
 
EXTRTMETHOD const char * toString (char *pbuf, OSSIZE bufsize) const
 
EXTRTMETHOD char * toString (OSCTXT *pctxt) const
 
EXTRTMETHOD char * toString () const
 
EXTRTMETHOD const ASN1TTimeoperator= (const ASN1TTime &)
 
virtual EXTRTMETHOD OSBOOL operator== (const ASN1TTime &) const
 
virtual EXTRTMETHOD OSBOOL operator!= (const ASN1TTime &) const
 
virtual EXTRTMETHOD OSBOOL operator> (const ASN1TTime &) const
 
virtual EXTRTMETHOD OSBOOL operator< (const ASN1TTime &) const
 
virtual EXTRTMETHOD OSBOOL operator>= (const ASN1TTime &) const
 
virtual EXTRTMETHOD OSBOOL operator<= (const ASN1TTime &) const
 

Public Attributes

short mYear
 
short mMonth
 
short mDay
 
short mHour
 
short mMinute
 
short mSecond
 
short mDiffHour
 
short mDiffMin
 
int mSecFraction
 
int mSecFracLen
 
int mStatus
 
OSBOOL mbUtcFlag
 
OSBOOL mbDerRules
 

Protected Member Functions

EXTRTMETHOD void privateInit ()
 
EXTRTMETHOD int getDaysNum () const
 
EXTRTMETHOD long getMillisNum () const
 
int ncharsToInt (const char *str, OSSIZE nchars, int &value)
 

Static Protected Member Functions

static EXTRTMETHOD int checkDate (int day, int month, int year)
 
static EXTRTMETHOD void addMilliseconds (int deltaMs, short &year, short &month, short &day, short &hour, short &minute, short &second, int &secFraction, int secFracLen)
 
static EXTRTMETHOD void addDays (int deltaDays, short &year, short &month, short &day)
 
static EXTRTMETHOD short daysInMonth (int i)
 
static EXTRTMETHOD int daysAfterMonth (int i)
 

Detailed Description

ASN.1 Time utility base class.

Constructor & Destructor Documentation

◆ ASN1TTime() [1/3]

EXTRTMETHOD ASN1TTime::ASN1TTime ( )

This constructpor creates an empty time class.

◆ ASN1TTime() [2/3]

EXTRTMETHOD ASN1TTime::ASN1TTime ( OSBOOL  useDerRules)

This constructor creates an empty time class.

Parameters
useDerRulesUse the Distinguished Encoding Rules (DER) to operate on this time value.

◆ ASN1TTime() [3/3]

EXTRTMETHOD ASN1TTime::ASN1TTime ( const ASN1TTime original)

The copy constructor.

Parameters
originalThe original time string object value.

◆ ~ASN1TTime()

virtual EXTRTMETHOD ASN1TTime::~ASN1TTime ( )
virtual

The destructor.

Member Function Documentation

◆ clear()

virtual EXTRTMETHOD void ASN1TTime::clear ( )
virtual

This method clears the time object.

Note the action of this method may differ for different inherited ASN1TTime classes.

Reimplemented in ASN1TUTCTime.

Referenced by ASN1TUTCTime::ASN1TUTCTime().

◆ compileString()

virtual int ASN1TTime::compileString ( char *  pbuf,
OSSIZE  bufsize 
) const
pure virtual

Compiles new time string accoring X.680 and ISO 8601. Returns 0, if succeed, or error code, if error.

Parameters
pbufA pointer to destination buffer.
bufsizeA size of destination buffer.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

Implemented in ASN1TUTCTime, and ASN1TGeneralizedTime.

Referenced by ASN1TGeneralizedTime::ASN1TGeneralizedTime(), and ASN1TUTCTime::ASN1TUTCTime().

◆ equals()

virtual EXTRTMETHOD int ASN1TTime::equals ( const ASN1TTime ) const
virtual

This method compares times.

◆ getDay()

virtual EXTRTMETHOD int ASN1TTime::getDay ( ) const
virtual

This method returns the day of month number component of the time value.

The number of the first day in the month is 1; the number of the last day may be in the interval from 28 to 31. Note that the return value may be differ for different inherited ASN1TTime classes.

Returns
Day of month component (1 - 31) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getDiff()

virtual EXTRTMETHOD int ASN1TTime::getDiff ( ) const
virtual

This method returns the difference between the time zone of the object and the Coordinated Universal Time (UTC).

The UTC time is the sum of the local time and a positive of negative time difference. Note that the return value may differ for different inherited ASN1TTime classes.

Returns
The negative or positive minute component of the difference between the time zone of the object and the UTC time (-12*60 - +12*60) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getDiffHour()

virtual EXTRTMETHOD int ASN1TTime::getDiffHour ( ) const
virtual

This method returns the hour component of the difference between the time zone of the object and the Coordinated Universal Time (UTC).

The UTC time is the sum of the local time and a positive of negative time difference. Note that the return value may differ for different inherited ASN1TTime classes.

Returns
The negative or positive hour component of the difference between the time zone of the object and the UTC time (-12 - +12) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getDiffMinute()

virtual EXTRTMETHOD int ASN1TTime::getDiffMinute ( ) const
virtual

This method returns the minute component of the difference between the time zone of the object and the Coordinated Universal Time (UTC).

The UTC time is the sum of the local time and a positive of negative time difference. Note that the return value may differ for different inherited ASN1TTime classes.

Returns
The negative or positive minute component of the difference between the time zone of the object and the UTC time (-59 - +59) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getFraction()

virtual EXTRTMETHOD int ASN1TTime::getFraction ( ) const
virtual

This method returns the second's decimal component of the time value.

Second's decimal fraction is represented by one or more digits from 0 to 9.

Returns
Second's decimal fraction component is returned if operation is successful. If the operation fails, a negative value is returned.

Reimplemented in ASN1TUTCTime.

Referenced by ASN1TUTCTime::ASN1TUTCTime().

◆ getFractionAsDouble()

virtual EXTRTMETHOD double ASN1TTime::getFractionAsDouble ( ) const
virtual

This method returns the second's decimal component of the time value. Second's fraction will be represented as double value more than 0 and less than 1.

Second's decimal fraction is represented by one or more digits from 0 to 9.

Returns
Second's decimal fraction component is returned if operation is successful. If the operation fails, a negative value is returned.

◆ getFractionLen()

virtual EXTRTMETHOD int ASN1TTime::getFractionLen ( ) const
virtual

This method returns the number of digits in second's decimal component of the time value.

Returns
Second's decimal fraction's length is returned if operation is successful. If the operation fails, a negative value is returned.

◆ getFractionStr()

virtual EXTRTMETHOD int ASN1TTime::getFractionStr ( char *const  pBuf,
OSSIZE  bufSize 
) const
virtual

This method returns the second's decimal component of the time value. Second's fraction will be represented as string w/o integer part and decimal point.

Returns
Length of the fraction string returned in pBuf, if operation is successful. If the operation fails, a negative value is returned.

◆ getHour()

virtual EXTRTMETHOD int ASN1TTime::getHour ( ) const
virtual

This method returns the hour component of the time value.

As the ISO 8601 is based on the 24-hour timekeeping system, hours are represented by two-digit values from 00 to 23. Note that the return value may differ from different inherited ASN1TTime classes.

Returns
Hour component (0 - 23) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getMinute()

virtual EXTRTMETHOD int ASN1TTime::getMinute ( ) const
virtual

This method returns the minute component of the time value.

Minutes are represented by the two digits from 00 to 59. Note that the return value may differ from different inherited ASN1TTime classes.

Returns
Minute component (0 - 59) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getMonth()

virtual EXTRTMETHOD int ASN1TTime::getMonth ( ) const
virtual

This method returns the month number component of the time value.

The number of January is 1, February 2, ... up to December 12. You may also use enumerated valued for decoded months: ASN1TTime::January, ASN1TTime::February, etc. Also short aliases for months can be used: ASN1TTime::Jan, ASN1TTime::Feb, etc. Note that the return value may differ for different inherited ASN1TTime classes.

Returns
Month component (1 - 12) is returned if operation is successful. If the operation fails, a negative value is returned.

◆ getSecond()

virtual EXTRTMETHOD int ASN1TTime::getSecond ( ) const
virtual

This method returns the second component of the time value.

Seconds are represented by two digits from 00 to 59. Note that the return value may differ from different inherited ASN1TTime classes.

Returns
Second component (0 - 59) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ getTime()

virtual EXTRTMETHOD time_t ASN1TTime::getTime ( ) const
virtual

This method converts the time string to a value of the built-in C type time_t.

The value is the number of seconds from January 1, 1970. If the time is represned as UTC time plus or minus a time difference, then the resulting value will be recalculated as local time. For example, if the time string is "19991208120000+0930", then this string will be converted to "19991208213000" and then converted to a time_t value. Note that the return value may differ for different inherited ASN1TTime classes.

Returns
The time value, expressed as a number of seconds from January 1, 1970. If the operation fails, a negative value is returned.

◆ getUTC()

virtual EXTRTMETHOD OSBOOL ASN1TTime::getUTC ( ) const
virtual

This method returns the UTC flag state.

If the UTC flag is TRUE, then the time is a UTC time and symbol Z is added at the end of the time string. Otherwise, it is local time.

Returns
UTC flag state is returned.

◆ getYear()

virtual EXTRTMETHOD int ASN1TTime::getYear ( ) const
virtual

This method returns the year component of the time value.

Note that the return value may differ for different inherited ASN1TTime classes.

Returns
Year component (full 4 digits) is returned if the operation is successful. If the operation fails, a negative value is returned.

◆ parseString()

virtual int ASN1TTime::parseString ( const char *  string)
pure virtual

This method parses the given time string.

The string is expected to be in the ASN.1 value notation format for the given ASN.1 time string type. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
stringThe time string value to be parsed.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

Implemented in ASN1TUTCTime, and ASN1TGeneralizedTime.

Referenced by ASN1TGeneralizedTime::ASN1TGeneralizedTime(), and ASN1TUTCTime::ASN1TUTCTime().

◆ setDay()

virtual EXTRTMETHOD int ASN1TTime::setDay ( short  day_)
virtual

This method sets the day of month number component of the time value.

The number of the first day in the month is 1; the number of the last day in the month may be in the interval from 28 to 31. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
day_Day of month component (1 - 31).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setDER()

void ASN1TTime::setDER ( OSBOOL  bvalue)
inline

This method sets the 'use DER' flag which enforces the DER rules when time strings are constructed or parsed.

References operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

◆ setDiff() [1/2]

virtual EXTRTMETHOD int ASN1TTime::setDiff ( short  dhour,
short  dminute 
)
virtual

This method sets the hours and the minute components of the difference between the time zone of the object and Coordinated Universal Time (UTC).

The UTC time is the sum of the local time and a positive or negative time difference. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
dhourThe negative or positive hour component of the difference between the time zone of the object and the UTC time (-12 - +12).
dminuteThe negative or positive minute component of the difference between the time zone of the object and the UTC time (-59 - +59).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setDiff() [2/2]

virtual EXTRTMETHOD int ASN1TTime::setDiff ( short  inMinutes)
virtual

This method sets the difference between the time zone of the object and Coordinated Universal Time (UTC), in minutes.

The UTC time is the sum of the local time and a positive or negative time difference. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
inMinutesThe negative or positive difference, in minutes, between the time zone of the object and the UTC time (-12*60 - +12*60) is returned if the operation is successful.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setDiffHour()

virtual EXTRTMETHOD int ASN1TTime::setDiffHour ( short  dhour)
virtual

This method sets teh hour component of the difference between the time zone of the object and the Coordinated Universal Time (UTC).

The UTC time is the sum of the local time and a positive or negative time difference. Note that the action of this method may differ from different inherited ASN1TTime classes.

Parameters
dhourThe negative or positive hour component of the difference between the time zone of the object and the UTC time (-12 - +12) is returned if the operation is successful. If the operation fails, a negative value is returned.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setFraction() [1/3]

virtual EXTRTMETHOD int ASN1TTime::setFraction ( int  fraction,
int  fracLen = -1 
)
virtual

This method sets the second's decimal fraction component of the time value.

Second's decimal fraction is represented by one or more digits from 0 to 9. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
fractionSecond's decimal fraction component (0 - 9).
fracLenOptional parameter specifies number of digits in second's fraction.
Returns
Completion status of operation:
  • 0 (ASN_OK) = success,
  • negative return value is error.

Reimplemented in ASN1TUTCTime.

Referenced by ASN1TUTCTime::ASN1TUTCTime().

◆ setFraction() [2/3]

virtual EXTRTMETHOD int ASN1TTime::setFraction ( double  frac,
int  fracLen 
)
virtual

This method sets the second's decimal fraction component of the time value. Double value must be greater or equal 0 and less than 1.

Parameters
fracSecond's decimal fraction component.
fracLenSpecifies number of digits in second's fraction.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setFraction() [3/3]

virtual EXTRTMETHOD int ASN1TTime::setFraction ( char const *  frac)
virtual

This method sets the second's decimal fraction component of the time value. Double value must be greater or equal 0 and less than 1.

Parameters
fracSecond's decimal fraction component.
Returns
Completion status of operation:
  • 0 (ASN_OK) = success,
  • negative return value is error.

◆ setHour()

virtual EXTRTMETHOD int ASN1TTime::setHour ( short  hour_)
virtual

This method sets the hour component of the time value.

As the ISO 8601 is based on the 24-hour timekeeping system, hours are represented by two digits from 00 to 23. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
hour_Hour component (0 - 23).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setMinute()

virtual EXTRTMETHOD int ASN1TTime::setMinute ( short  minute_)
virtual

This method sets the minute component of the time value.

Minutes are represented by two digits from 00 to 59. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
minute_Minute component (0 - 59).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setMonth()

virtual EXTRTMETHOD int ASN1TTime::setMonth ( short  month_)
virtual

This method sets the month number component of the time value.

The number of January is 1, February 2, ..., through December 12. You may use enumerated values for months encoding: ASN1TTime::January, ASN1TTime::February, etc. Also you can use short aliases for months: ASN1TTime::Jan, ASN1TTime::Feb, etc. Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
month_Month component (1 - 12).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setSecond()

virtual EXTRTMETHOD int ASN1TTime::setSecond ( short  second_)
virtual

This method sets the second component of the time value.

Seconds are represented by two digits from 00 to 59. Note that the action of this method may differ form different inherited ASN1TTime classes.

Parameters
second_Second component (0 - 59).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

◆ setTime()

virtual int ASN1TTime::setTime ( time_t  time,
OSBOOL  diffTime 
)
pure virtual

This converts the value of the C built-in type time_t to a time string.

The value is the number of seconds from January 1, 1970. Note that the action of this method may differ for different inherited ASN1TTime Classes.

Parameters
timeThe time value, expressed as a number of seconds from January 1, 1970.
diffTimeTRUE means the difference between local time and UTC time will be calculated; in other case, only local time will be stored.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

Implemented in ASN1TUTCTime, and ASN1TGeneralizedTime.

Referenced by ASN1TGeneralizedTime::ASN1TGeneralizedTime(), and ASN1TUTCTime::ASN1TUTCTime().

◆ setUTC()

virtual EXTRTMETHOD int ASN1TTime::setUTC ( OSBOOL  utc)
virtual

This method sets teh UTC flag state.

If the UTC flag is TRUE, then the time is a UTC time and symbol 'Z' is added to the end of the string. Otherwise, it is a local time.

Parameters
utcUTC flag state.
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

Reimplemented in ASN1TUTCTime.

Referenced by ASN1TUTCTime::ASN1TUTCTime().

◆ setYear()

virtual EXTRTMETHOD int ASN1TTime::setYear ( short  year_)
virtual

This method sets the year component of the time value.

Note that the action of this method may differ for different inherited ASN1TTime classes.

Parameters
year_Year component (full 4 digits).
Returns
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

Reimplemented in ASN1TUTCTime.

Referenced by ASN1TUTCTime::ASN1TUTCTime().

◆ toString() [1/3]

EXTRTMETHOD const char* ASN1TTime::toString ( char *  pbuf,
OSSIZE  bufsize 
) const

Get a printable ASCII string of the time value into the specified buffer.

Parameters
pbufPointer to a destination buffer.
bufsizeSize of destination buffer.
Returns
Compiled time string. NULL, if error occurs.

◆ toString() [2/3]

EXTRTMETHOD char* ASN1TTime::toString ( OSCTXT pctxt) const

Get a printable ASCII string of the time value. Memory for the returned string is allocated using the rtxMemAlloc function and is freed either when context memory is freed or explicitly via a call to rtxMemFreePtr.

Parameters
pctxtPointer to a context structure.
Returns
Compiled time string. NULL, if error occurs.

◆ toString() [3/3]

EXTRTMETHOD char* ASN1TTime::toString ( ) const

Get a printable ASCII string of the time value. Memory will be allocated using new[] operator. User is responsible to free it using delete[].

Returns
Compiled time string. NULL, if error occurs.

Member Data Documentation

◆ mbDerRules

OSBOOL ASN1TTime::mbDerRules

This member variable tells whether we will encode this time according to the Distinguished Encoding Rules (DER) or not.

◆ mbUtcFlag

OSBOOL ASN1TTime::mbUtcFlag

This member variable tells whether this time is UTC time or not.

◆ mDay

short ASN1TTime::mDay

This member variable holds this time's day.

◆ mDiffHour

short ASN1TTime::mDiffHour

This member variable holds this time's hour differential.

◆ mDiffMin

short ASN1TTime::mDiffMin

This member variable holds this time's minute differential.

◆ mHour

short ASN1TTime::mHour

This member variable holds this time's hour.

◆ mMinute

short ASN1TTime::mMinute

This member variable holds this time's minute.

◆ mMonth

short ASN1TTime::mMonth

This member variable holds this time's month.

◆ mSecFracLen

int ASN1TTime::mSecFracLen

This member variable holds this time's fractional seconds length.

◆ mSecFraction

int ASN1TTime::mSecFraction

This member variable holds this time's fractional seconds.

◆ mSecond

short ASN1TTime::mSecond

This member variable holds this time's second.

◆ mStatus

int ASN1TTime::mStatus

This member variable holds this time's status.

◆ mYear

short ASN1TTime::mYear

This member variable holds this time's year.


The documentation for this class was generated from the following file: