COleDateTime.Format can't deal with year before 1900

I

Ian Harding

This is a problem present using Visual Studio 2005, but not in Visual
Studio 2003 or Visual C++ 6.

COleDateTime modernDate( 1900, 1, 1, 0, 1, 0 );
COleDateTime problemDate( 1753, 1, 1, 0, 1, 0 );

CString isoDate = modernDate.Format(_T("%Y-%m-%dT%H:%M:%S"));
isoDate = problemDate.Format(_T("%Y-%m-%dT%H:%M:%S")); // problem!

problemDate.Format triggers an assertion failure on line 783 of strftime.c:

_VALIDATE_RETURN( ( timeptr->tm_year >=0 ), EINVAL, FALSE)

So any date where the year is earlier than 1900 will result in
timeptr->tm_year containing a negative value and fail the assertion on
line 783 of strftime.c if %Y is requested in the format string.

Is this a bug, or am I missing something?

Thanks,
Ian
 
J

Jochen Kalmbach [MVP]

Hi Ian!
COleDateTime problemDate( 1753, 1, 1, 0, 1, 0 );

I think this is not allowed:
<quote>
The DATE type is implemented as a floating-point value, measuring days
from midnight, 30 December 1899. So, midnight, 31 December 1899 is
represented by 1.0. Similarly, 6 AM, 1 January 1900 is represented by
2.25, and midnight, 29 December 1899 is – 1.0. However, 6 AM, 29
December 1899 is – 1.25.
</quote>



--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
J

Jochen Kalmbach [MVP]

Sorry... I forgot about the negativ numbers ;-(

<quote>
The COleDateTime class handles dates from 1 January 100 – 31 December 9999.
</quote>

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
J

Jochen Kalmbach [MVP]

Hi Ian!
This is a problem present using Visual Studio 2005, but not in Visual
Studio 2003 or Visual C++ 6.

COleDateTime problemDate( 1753, 1, 1, 0, 1, 0 );
isoDate = problemDate.Format(_T("%Y-%m-%dT%H:%M:%S")); // problem!

The simplest repro-code is:

COleDateTime dt( 1753, 1, 1, 0, 1, 0 );
CString year = dt.Format(_T("%Y"));

It seems that this is a bug... of course there are a entry in ladybug:

COleDateTime::Format("%Y") with m_dt set to 0.0 fails with
invalid_parameter
http://lab.msdn.microsoft.com/produ...edbackid=f001951c-aa17-4eba-bbed-e15981250119

It seems that the bug is fixed but not yet available to public...
If you need a hotfix you might ask Product support to get one.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
I

Ian Harding

Jochen said:
Hi Ian!



The simplest repro-code is:

COleDateTime dt( 1753, 1, 1, 0, 1, 0 );
CString year = dt.Format(_T("%Y"));

It seems that this is a bug... of course there are a entry in ladybug:

COleDateTime::Format("%Y") with m_dt set to 0.0 fails with
invalid_parameter
http://lab.msdn.microsoft.com/produ...edbackid=f001951c-aa17-4eba-bbed-e15981250119


It seems that the bug is fixed but not yet available to public...
If you need a hotfix you might ask Product support to get one.

Thank you. At least it is confirmed as a bug. I didn't know MS bugs
were accessible online, that's useful to know.

Ian
 
G

Guest

Does anyone know what the hotfix number is for this issue? I contacted
Microsoft Professional Support here in Sweden but they could not find it and
the bug id (FDBK26782) didn't seem to help them.

Thanks!

/Henrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top