July 24, 2004
Passing a "MM/DD/YYYY" or "YYYY/MM/DD" formated string into std.date.parse() function which has a year equal-to or less-than 1970, causes the other std.date functions to use 1970 internal as the year... messing up the end results. Needless to say this is throwing my wip dateutils.d module functions off! :(

Everything above 1970 seems to work just fine, is it me or is this a bug I should report? Thxs as always, in advance. :))

# import std.stdio;
# import std.date;
#
# int main()
# {
#    char[] sDate = "07/04/1776";
#    int    iYear = 1776;
#
#    writefln( "parse( sDate ) is creating a wrong d_time");
#    writefln( "parse( \"%s\" )=0x%-X  )", sDate, parse( sDate )  );
#
#    writefln( "YearFromTime( parse( \"%s\" )=%-d",
#               sDate, YearFromTime( parse( sDate ) ));
#
#    writefln( "\n" );
#
#    writefln( "TimeFromYear( %d )=0x%-X is fine with an integer",
#               iYear, TimeFromYear( iYear ) );
#    writefln( "YearFromTime( TimeFromYear( %d ) )=%-d",
#               iYear, YearFromTime( TimeFromYear( iYear ) ) );
#
#    return 0;
#
# } // end int main()

<output>
parse( sDate ) is creating a wrong d_time
parse( "07/04/1776" )=0x112A880  )
YearFromTime( parse( "07/04/1776" )=1970

TimeFromYear( 1776 )=0xFFFFFA6E99B1C400 is fine with an integer
YearFromTime( TimeFromYear( 1776 ) )=1776
</output>

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
July 24, 2004
David L. Davis wrote:
> Passing a "MM/DD/YYYY" or "YYYY/MM/DD" formated string into std.date.parse()
> function which has a year equal-to or less-than 1970, causes the other std.date
> functions to use 1970 internal as the year... messing up the end results.
> Needless to say this is throwing my wip dateutils.d module functions off! :( 
> 
> Everything above 1970 seems to work just fine, is it me or is this a bug I
> should report? Thxs as always, in advance. :))

Yeah, I'd call it a bug.

From http://www.digitalmars.com/d/phobos.html:
"typedef d_time: Is a signed arithmetic type giving the time elapsed since January 1, 1970. Negative values are for dates preceding 1970. The time unit used is Ticks. Ticks are milliseconds or smaller intervals."

Without studying the code in std\dateparse.d, I'd guess that the negative case of a d_time isn't handled correctly.

> 
> # import std.stdio;
> # import std.date;
> #
> # int main()   # {
> #    char[] sDate = "07/04/1776";
> #    int    iYear = 1776;
> #    #    writefln( "parse( sDate ) is creating a wrong d_time");
> #    writefln( "parse( \"%s\" )=0x%-X  )", sDate, parse( sDate )  );
> #    #    writefln( "YearFromTime( parse( \"%s\" )=%-d", #               sDate, YearFromTime( parse( sDate ) ));
> #               #    writefln( "\n" ); #    #    writefln( "TimeFromYear( %d )=0x%-X is fine with an integer",
> #               iYear, TimeFromYear( iYear ) );         #    writefln( "YearFromTime( TimeFromYear( %d ) )=%-d", #               iYear, YearFromTime( TimeFromYear( iYear ) ) );         #
> #    return 0;
> #    # } // end int main()
> 
> <output>
> parse( sDate ) is creating a wrong d_time
> parse( "07/04/1776" )=0x112A880  )
> YearFromTime( parse( "07/04/1776" )=1970
> 
> TimeFromYear( 1776 )=0xFFFFFA6E99B1C400 is fine with an integer
> YearFromTime( TimeFromYear( 1776 ) )=1776
> </output>
> 
> -------------------------------------------------------------------
> "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/