Skip to Content.
Sympa Menu

freetds - Re: Bizarre date wraparound bug

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT speakeasy.org>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: Bizarre date wraparound bug
  • Date: Wed, 24 Oct 2001 00:55:03 -0400


Brian Bruns wrote:
>
> from src/tds/convert.c:
>
> TDS_INT tds_convert_datetime(int srctype,unsigned char *src,int
> desttype,unsigned char *dest,TDS_INT destlen)
> {
> TDS_INT dtdays, dttime;
> time_t tmp_secs_from_epoch;
>
> switch(desttype) {
> case SYBCHAR:
> case SYBVARCHAR:
> /* FIX ME -- This fails for dates before 1902 or after 2038 */
> Anybody wanna take a crack at fixing it?

Brian,

I am working on 5 functions. If 1 Jan 1900 + 65536 days is 6/7/2079 (I
haven't checked yet), the first one works:

bool datetime_to_tm( const TDS_DATETIME* pTdsDate, struct tm *pTm );
bool smalldatetime_to_tm( const TDS_DATETIME4* pTdsDate, struct tm *pTm
);

bool tm_to_datetime( const struct tm *pTm, TDS_DATETIME* pTdsDate );
bool tm_to_smalldatetime( const struct tm *pTm, TDS_DATETIME4* pTdsDate
);

char * tm_to_char( const struct tm *pTm, char pBuffer[] );

I don't need:
bool char_to_tm( const char pBuffer[], struct tm *pTm );
because _string_to_tm() will do that job.

The idea is to use the tm structure as neutral ground. Even if the C
library wouldn't know what to do with a tm_year < 2, the structure
itself will hold any date we need. From what I can see, we don't have
to do date arithmetic, just convert to/from string.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page