Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread StrToTime oddity
Wed, Mar 5 2014 9:00 AMPermanent Link

Matthew Jones

Here's an interesting one. If you do:

var
 tmTime : DateTime;
begin
 tmTime := StrToTime('12:48:27');
 Report('Time ' + DateToStr(tmBuild) + ' ' + TimeToStr(tmBuild));
 Report('Time int=' + IntToStr(Integer(tmBuild)));
end;
 
You will find that the outputs are:
Time 1899-12-31 12:48:27  
Time int=-2209029093000

Now, the time in the display is correct, but the year is not. The help says a
DateTime is "A date/time value containing the number of milliseconds since midnight
on January 1, 1970." which implies positive to me, and 1899 does look before 1970,
so it makes sense.

However, if you take Date + tmTime, then you end up with a date in 1944, which
isn't right. Now, StrToTime calls EncodeTime, which is "internal" and creates a Day
object with 0 values. Then it uses setHours to modify it.

Now, in the browser, the $5 object is showing as "invalid date" and the
http://stackoverflow.com/questions/7766122/date-utc-for-years-between-0-100 answer
says that dates do not support years before 1900.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Dat
e/UTC
 
My reading of it is that the internal function should call "Date" with a single
zero parameter, which sets it to the number of milliseconds past 1970. Okay, just
done a quick hack, and that too shows as "invalid date" in the browser, so that
issue may not be relevant, but when run it gives:

Time 1970-01-01 12:48:27  
Time int=46107000

This is the same time output, but the value is now suitable for adding to a Date
value which is key.

If you now add a time and date together then you get a valid timestamp, which is
what I was really wanting. Temporarily, I can fix this with an adjustment to the
time value of 2209075200000 if it is less than zero. I think though long term the
internal encodetime should be using var $5 = new Date(0); instead of var $5 = new
Date(0, 0, 0, 0, 0, 0); Probably the others that do this too.

/Matthew Jones/
Thu, Mar 6 2014 6:11 PMPermanent Link

Ronald

I take off my hat for you.

"Matthew Jones"  schreef in bericht
news:memo.20140305140015.6848X@nothanks.nothanks.co.uk...

Here's an interesting one. If you do:

var
 tmTime : DateTime;
begin
 tmTime := StrToTime('12:48:27');
 Report('Time ' + DateToStr(tmBuild) + ' ' + TimeToStr(tmBuild));
 Report('Time int=' + IntToStr(Integer(tmBuild)));
end;

You will find that the outputs are:
Time 1899-12-31 12:48:27
Time int=-2209029093000

Now, the time in the display is correct, but the year is not. The help says
a
DateTime is "A date/time value containing the number of milliseconds since
midnight
on January 1, 1970." which implies positive to me, and 1899 does look before
1970,
so it makes sense.

However, if you take Date + tmTime, then you end up with a date in 1944,
which
isn't right. Now, StrToTime calls EncodeTime, which is "internal" and
creates a Day
object with 0 values. Then it uses setHours to modify it.

Now, in the browser, the $5 object is showing as "invalid date" and the
http://stackoverflow.com/questions/7766122/date-utc-for-years-between-0-100
answer
says that dates do not support years before 1900.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Dat
e/UTC

My reading of it is that the internal function should call "Date" with a
single
zero parameter, which sets it to the number of milliseconds past 1970. Okay,
just
done a quick hack, and that too shows as "invalid date" in the browser, so
that
issue may not be relevant, but when run it gives:

Time 1970-01-01 12:48:27
Time int=46107000

This is the same time output, but the value is now suitable for adding to a
Date
value which is key.

If you now add a time and date together then you get a valid timestamp,
which is
what I was really wanting. Temporarily, I can fix this with an adjustment to
the
time value of 2209075200000 if it is less than zero. I think though long
term the
internal encodetime should be using var $5 = new Date(0); instead of var $5
= new
Date(0, 0, 0, 0, 0, 0); Probably the others that do this too.

/Matthew Jones/
Tue, Mar 11 2014 9:14 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< says that dates do not support years before 1900. >>

Definitely not correct.

<< If you now add a time and date together then you get a valid timestamp,
which is what I was really wanting. Temporarily, I can fix this with an
adjustment to the time value of 2209075200000 if it is less than zero. I
think though long term the internal encodetime should be using var $5 = new
Date(0); instead of var $5 = new Date(0, 0, 0, 0, 0, 0); Probably the others
that do this too. >>

I'll see what I can do.

Tim Young
Elevate Software
www.elevatesoft.com
Image