Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread DateToStr and time zones
Thu, Mar 2 2017 10:10 AMPermanent Link

Matthew Jones

Assuming I have a UTC DateTime value, how does DateToStr know what local time zone the browser is using?

--

Matthew Jones
Thu, Mar 2 2017 11:29 AMPermanent Link

Matthew Jones

Matthew Jones wrote:

> Assuming I have a UTC DateTime value, how does DateToStr know what local time zone the browser is using?

"2017-03-02T15:33:36" converted to DateTime, then output with DateToStr give me, in the UK, "2017/03/02 15:33:36".
In the USA, they are seeing "2087/03/02 15:33:36". Looks like the UTC offset is being applied to the wrong part?

Converter from text snippet:
  FormatSettings.DateSeparator := '-';
  FormatSettings.ShortDateFormat := 'yyyy-MM-dd';
  tmBuild := StrToDate(szDateStr, True); // UTC dates
//..
  FormatSettings.TimeSeparator := ':';
  FormatSettings.ShortTimeFormat := 'HH:mm:ss';
  nTime := Integer(StrToTime(szTimeStr));
  if Integer(nTime) < 0 then
     nTime := nTime + 2209075200000; // fix for EWB issue
  tmBuild := tmBuild + nTime;              


Converter to text snippet:

   FormatSettings.ShortDateFormat := 'yyyy MM dd';
   FormatSettings.DateSeparator := '/';

   szDate := DateToStr(tmValue);
   if bWithTime then
   begin
       FormatSettings.ShortTimeFormat := 'HH:mm:ss';
       Result := szDate + ' ' + Trim(TimeToStr(tmValue));

I shall dig further...

--

Matthew Jones
Thu, Mar 2 2017 11:58 AMPermanent Link

Matthew Jones

Matthew Jones wrote:

> In the USA, they are seeing "2087/03/02 15:33:36". Looks like the UTC offset is being applied to the wrong part?

Seems to be in my parser code...

--

Matthew Jones
Thu, Mar 2 2017 12:25 PMPermanent Link

Matthew Jones

Matthew Jones wrote:

> Seems to be in my parser code...

I think I've fallen over this somehow before, but Time returns a value that includes the current Date too, not just the time. Subtracting Date from it seems to make my code work, but not entirely sure why this part is being triggered!

--

Matthew Jones
Thu, Mar 2 2017 3:48 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< I think I've fallen over this somehow before, but Time returns a value that includes the current Date too, not just the time. Subtracting Date from it seems to make my code work, but not entirely sure why this part is being triggered! >>

Yes, in fact I'm pretty sure that someone requested that the current date be included as part of the Time.  I think originally it was zeroed out, but that caused some weird date calculation results...checking...nope, it was that EncodeDate wasn't zeroing out the time portion:

http://www.elevatesoft.com/incident?action=searchview&category=ewb&incident=3918&start=26&keywords=time&severity=Serious&severity=Minor

Although there could have been a request that wasn't logged as an incident report...

Tim Young
Elevate Software
www.elevatesoft.com
Fri, Mar 3 2017 3:58 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> Yes, in fact I'm pretty sure that someone requested that the current date be included as part of the Time.  I think originally it was zeroed out, but that caused some weird date calculation results...checking...nope, it was that EncodeDate wasn't zeroing out the time portion:

Perhaps the key is to document it as including the current date as well as time. I don't think either are particularly wrong. Encoding the time and adding it to an encoded date should always work. But it is perhaps interesting as to whether that then means that encoding a date and adding the current Time should work as expected or not. Obviously I expected it would work okay, without subtracting the current date too. To change it would break code that relies on it too. Hmmm. I leave it in your most capable hands to decide. 8-)


--

Matthew Jones
Fri, Mar 3 2017 10:45 AMPermanent Link

Matthew Jones

Matthew Jones wrote:

>  encoding a date and adding the current Time should work as expected

The more I think about this, the more I feel that Time should be just the time. If you want the time and date, just add them together. Or use Now. It would probably be handy to have functions to get "JustTime" and "JustDate" from any value.

--

Matthew Jones
Tue, Mar 7 2017 2:26 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< The more I think about this, the more I feel that Time should be just the time. If you want the time and date, just add them together. Or use Now. It would probably be handy to have functions to get "JustTime" and "JustDate" from any value. >>

I'll double-check, but I don't think this can be done.  With JS timestamps, there is no such thing as "just the time", thus trying to do so will result in garbage results.

Tim Young
Elevate Software
www.elevatesoft.com
Image