Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 13 of 13 total
Thread date problem
Sat, Jun 15 2013 4:58 AMPermanent Link

Paul Waegemans

IMS bvba

Avatar

This code is OK:

Columns['datum'].Asdatetime:=StrToDate(DateToStr(date));

Paul.


"Tim Young [Elevate Software]" wrote:

Christian,

<< My Delphi Http server prepares Json data for a TDataSet.LoadRows(). The
datetime columns I set like this

Result := MilliSecondsBetween(myDateTime, EncodeDate(1970, 1, 1); >>

You're going to need to convert MyDateTime from local to UTC (including DST)
before doing this calculation.  On the EWB side, EWB simply uses a local
representation for DateToStr(), etc. so that the user sees their correct
local date/time.

<< My timezone is UTC+1, so I think, EWB treats datetimes in a dataset as
UTC datetimes. >>

Yes, that is correct.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jun 17 2013 1:41 AMPermanent Link

Christian Kaufmann

><< My timezone is UTC+1, so I think, EWB treats datetimes in a dataset as
>UTC datetimes. >>

So I think I missunderstod the UTC parameter in DateToStr and other
functions:
- DateTime values should always be / are UTC in EWB
- UTC = False: The value is converted based onl local timezone
- UTC = True: The value is converted to UTC

is that correct? And if I use StrToDate() I always get an UTC value?

This becomes tricky, because if I enter the date 17 June 2013 early in
the morning here in Switzerland, users in Canada will see 16 June
2013. This makes sence for timestamps, but not in cases when I want to
deal with dates only (e.g. date of an event).

How can I get the timezone on serverside? What about that:

MyRequest.RequestHeaders.Values['X-Timezone']   :=
IntToStr(TimeZone(EncodeDate(1970, 1, 1)));

Then I use this value for the conversion on the serverside.

cu Christian
Tue, Jun 18 2013 1:21 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< So I think I missunderstod the UTC parameter in DateToStr and other
functions:
- DateTime values should always be / are UTC in EWB
- UTC = False: The value is converted based onl local timezone
- UTC = True: The value is converted to UTC

is that correct? >>

Not quite - the UTC parameter normally indicates that the *value being
provided* is either UTC or not.  For example, if you set the UTC parameter
to True for StrToDateTime(), you are telling the function that the string
representation of the date/time that you're sending it is already UTC, so it
doesn't need to convert it.

<< And if I use StrToDate() I always get an UTC value? >>

Yes, the resulting DateTime value is always assumed to be UTC (milliseconds
since midnight Jan 1, 1970).  The question is whether it is the correct UTC
date, due to how you set the UTC parameter when you called StrToDate(),
combined with the date string that you set for the first parameter.

<< This becomes tricky, because if I enter the date 17 June 2013 early in
the morning here in Switzerland, users in Canada will see 16 June 2013. >>

Yes, that is correct.  I'll have to see about adding an option to specify
whether you want date values to localize or not in database operations.

<< How can I get the timezone on serverside? >>

I'll get these surfaced as methods of the TServerRequest, but you can use
them anyways right now:

For translating to/from UTC:

uses ewbhttpcommon

function LocalToGMT(LocalTime: TDateTime;
                   IncludeDST: Boolean=True): TDateTime;
function GMTToLocal(GMTTime: TDateTime;
                   IncludeDST: Boolean=True): TDateTime;

For translating to/from the EWB raw DateTime format:

uses ewbcommon

function DateTimeToUnix(Value: TDateTime): Int64;
function UnixToDateTime(UMSec: Int64): TDateTime;

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image