Wednesday, September 15, 2010

Rounding

http://codingforums.com/showthread.php?t=10827

SYSTEMTIME Structure

 http://msdn.microsoft.com/en-us/library/ms724950(VS.85).aspx
 typedef struct _SYSTEMTIME {   WORD wYear;   WORD wMonth;   WORD wDayOfWeek;   WORD wDay;   WORD wHour;   WORD wMinute;   WORD wSecond;   WORD wMilliseconds; } SYSTEMTIME, *PSYSTEMTIME;
 

Constants


http://www.cplusplus.com/doc/tutorial/constants/

Literals

75         // decimal 0113       // octal 0x4b       // hexadecimal 


75 // int 75u // unsigned int 75l // long 75ul // unsigned long

3.14159 // 3.14159 // default double 6.02e23 // 6.02 x 10^23 1.6e-19 // 1.6 x 10^-19 3.0 // 3.0

 3.14159L   // long double 6.02e23f   // float 
 
 
 'z' 'p' "Hello world" "How do you do?" 
 
\n newline
\r carriage return
\t tab
\v vertical tab
\b backspace
\f form feed (page feed)
\a alert (beep)
\' single quote (')
\" double quote (")
\? question mark (?)
\\ backslash (\)


For example: 

1
2
3
4
'\n' '\t' "Left \t Right" "one\ntwo\nthree" 

More at link.

fmod

http://www.cplusplus.com/reference/clibrary/cmath/fmod/

     double fmod (      double numerator,      double denominator );       float fmod (       float numerator,       float denominator ); long double fmod ( long double numerator, long double denominator );
 

COleDatTime::COleDateTime

For older unmanaged code this handles the DATE type.



 COleDateTime( ) throw( );  COleDateTime(    const VARIANT& varSrc  ) throw( ); COleDateTime(    DATE dtSrc  ) throw( ); COleDateTime(    time_t timeSrc  ) throw( ); COleDateTime(    __time64_t timeSrc  ) throw( ); COleDateTime(    const SYSTEMTIME& systimeSrc  ) throw( ); COleDateTime(    const FILETIME& filetimeSrc  ) throw( ); COleDateTime(    int nYear,    int nMonth,    int nDay,    int nHour,    int nMin,    int nSec  ) throw( ); COleDateTime(    WORD wDosDate,    WORD wDosTime  ) throw( ); COleDateTime(       const DBTIMESTAMP& dbts ) throw();
 

Re: Time DBTIMESTAMP

 http://msdn.microsoft.com/en-us/library/c3zzz087(v=VS.80).aspx
 Function for getting the DBTIMESTAMP.
 bool GetAsDBTIMESTAMP(       DBTIMESTAMP& dbts ) const throw();

On Wed, Sep 15, 2010 at 9:41 AM, Stan Hughes <hughes.stan@gmail.com> wrote:

The fraction time is from 0 to 999,999,999.

Not really sure what good this does since you can only get it for the current time and any translation of time rounds to the nearest second.

DBTIMESTAMP

The DBTIMESTAMP structure typedef is defined as follows:

 typedef struct tagDBTIMESTAMP {     SHORT  year;     USHORT month;     USHORT day;     USHORT hour;     USHORT minute;     USHORT second;     ULONG  fraction } DBTIMESTAMP; 

Members

year
The year (0 to 9999) is measured from 0 A.D.
month
The month ranges from 1 to 12 representing January through December.
day
The day ranges from 1 to a maximum of 31, depending on the number of days in the month.
hour
The hour ranges from 0 to 23.
minute
The minute ranges from 0 to 59.
second
The second ranges from 0 to 59.
fraction
The fraction represents billionths of a second ranging from 0 to 999,999,999.

Time DBTIMESTAMP


The fraction time is from 0 to 999,999,999.

Not really sure what good this does since you can only get it for the current time and any translation of time rounds to the nearest second.

DBTIMESTAMP

The DBTIMESTAMP structure typedef is defined as follows:

 typedef struct tagDBTIMESTAMP {     SHORT  year;     USHORT month;     USHORT day;     USHORT hour;     USHORT minute;     USHORT second;     ULONG  fraction } DBTIMESTAMP; 

Members

year
The year (0 to 9999) is measured from 0 A.D.
month
The month ranges from 1 to 12 representing January through December.
day
The day ranges from 1 to a maximum of 31, depending on the number of days in the month.
hour
The hour ranges from 0 to 23.
minute
The minute ranges from 0 to 59.
second
The second ranges from 0 to 59.
fraction
The fraction represents billionths of a second ranging from 0 to 999,999,999.

Tuesday, September 07, 2010

DATE Delta

#include <FLOAT.H> // for the FLT_EPSILON unmanaged code

DATE date1;
DATE date2;

DATE dEpsilon = date1 - date2;

if (dEpsilon > FLT_EPSILON)
{
   COleDateTime clTempEpsilon (depsilon);
   CString strEpsilon = clTempEpsilon.Format("%H:%M:%S %m/%d%Y");
   TRACE (strEpsilon);
}

OLE Date/Time

http://www.newobjects.com/pages/ndl/SQLite2\SQL-OleDate.htm

Related to SQL.

Starts from 30 December 1899 00:00:00


It would seem that the newer, OLD DB Date/Time, SQL Server 2008 R2, support milliseconds.

'yyyy-mm-dd hh:mm:ss[.999]

The time structure is has greater resolution:

'hh:mm:ss[.9999999]


Time Management, Conversion of system time to CTime


CTime Class

8 bytes, with an upper limit of January 18, 2038.


Time Management

#define _BASE_YEAR 70L /* 1970 is the base year */
#define _MAX_YEAR 138: /* 2038 is the max year */

Note that the _make__time64_t() function insist that the year is between 1969 and 2038.  If it is not a error value of 22 is set and a value of -1 is returned.

This is slight inconsistent with the behavior of CTime which set the time to 1970 is the time is earlier than 1900 and than creates the CTime from system time with no error.

This is a know bug.

atltime.inl

if (sysTime.wYear < 1900)
{
   __time64_t time0 = 0L;
   CTime timeT(time0);
   ...
}
else
{
   CTime timeT(
      (int) sysTime.wYear, (int)sysTime,wMonth, (int) sysTime.wDay,
      (int) sysTime.wHour, (int)sysTime.wMinute, (int) sysTime,wSecond,
      nDST);
   ...
}

The SYSTEMTIME structure does have milliseconds, but it is not used by CTime.

::VariantTimeToSystemTime() also seem to be dropping the milliseconds.

Friday, September 03, 2010

Static Variables

http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr038.htm

 class C {       static int i;       static int j;       static int k;       static int l;       static int m;       static int n;       static int p;       static int q;       static int r;       static int s;       static int f() { return 0; }       int a; public:       C() { a = 0; }       };

 C c; int C::i = C::f();    // initialize with static member function int C::j = C::i;      // initialize with another static data member int C::k = c.f();     // initialize with member function from an object int C::l = c.j;       // initialize with data member from an object int C::s = c.a;       // initialize with nonstatic data member int C::r = 1;         // initialize with a constant value

 class Y : private C {} y;  int C::m = Y::f(); int C::n = Y::r; int C::p = y.r;       // error int C::q = y.f();     // error

Asserts, Exceptions

This is rather random, but I need to save the search results.


This is a discussion of when to use asserts and when to use exceptions.

Asserts only exist in debug.

Asserts terminate normal program execution.

Rule of thumb: 

Can the error be managed?
Yes - throw exception and handle it.
No - use assert.

Can you write a unit test that is able to throw the exception?
Yes - exception
No - assert

Are you protecting against a coding error?
Yes - assert
No - exception

Are you protecting against 'normal program' (i.e. file not writable etc.):
Yes - exception
No - assert

Exception example:


http://msdn.microsoft.com/en-us/library/ac9f67ah.aspx

 try {    throw CSomeOtherException(); } catch(...) {  // Handle all exceptions    // Respond (perhaps only partially) to exception    throw;       // Pass exception to some other handler }