datetime-tz vs .NET DateTime woes (new attempt)

Posted by bronco on 21-May-2012 15:05

I have some issue with .NET  receiving DateTime from a 4GL AppServer. What I'm basically, on one  machine (so the same regional settings), is:

define output parameter dtOut as datetime-tz no-undo.

dtOut = now.

message dtOut.

he AppServer log states: 2012-05-21T21:49:17.506+02:00

This is the correct time. I run this procedure through proxygen to make an assembly.

So the AppObject outputs a DateTime. Then I execute the following statement.

MessageBox.Show(dt.ToString() + "\n" +
                 dt.ToLocalTime().ToString() + "\n" +
                 dt.ToUniversalTime().ToString());

What I get is (I'll leave the date part out):

21:49:17

23:49:17

19:49:17

This  is strange. I expected the localtime to be same as the "raw" DateTime  (the 1st). I'm on the same machine and if I ask .NET wat is the time  (DateTime.Now() then I get just what I expect: 21:49:17.

What even more surprises me that there is 4 hours between Universal time (GMT) and Localtime (which I expect to be GMT+2).

One more experiment.

            MessageBox.Show(DateTime.Now.ToString() + "\n" +
                 DateTime.Now.ToLocalTime().ToString() + "\n" +
                 DateTime.Now.ToUniversalTime().ToString());

This gives

21:49:17

21:49:17

19:49:17

And indeed, there's 2 hours between localtime and Universal and that's the way it should be (in Holland).

Can somebody tell what's going on here?

All Replies

Posted by jquerijero on 21-May-2012 17:50

It looks like the current instance of the .NET DateTime is in UTC. Check the Kind property of the .NET DateTime. If it is Unspecified then the current instance of the .NET DateTime is assumed to be UTC. Unspecified is the default value if DateTime.Kind property.

I would expect datetime-tz to always convert to .NET DateTime with Kind set to Local.

Posted by bronco on 22-May-2012 04:32

Thanks, when reading a bit further in the .NET docs my earlier mentioned case is explained.

Now I only have to find out why it goes wrong on the day time shift from summertime to wintertime. If OE sends a datetime-tz with value 2012-10-28T08:00:00+01:00, .NET receives this as 28-10-2012 9:00, as if it still were summertime. Clearly something errornous going on here. I'm currently logging this with TechSupport.

Posted by gus on 22-May-2012 08:35

It is currently summertime in Holland, is it not? I would guess the .Net DateTime stuff thinks it is still summertime because it is.

Posted by bronco on 22-May-2012 08:49

Well, at 28-10-2012 8:00 in the morning (in Holland) it's not summertime anymore. OE understands that correctly. It seems that from 28-10-2012 from 02:00+01:00 till 23:59+01:00 the DateTime on the receiving (.NET) end 'thinks' it's still the +02:00 time (which is an hour later).

Posted by gus on 22-May-2012 09:01

Do the .Net docs you have been reading discuss this topic?

Do you know if .Net uses the Olson timezone database?

--

regards,

gus bjorklund, progress software

"for large values of one, one equals two, for small values of two."

Posted by bronco on 22-May-2012 09:17

Two answers, No it didn't mention this subject. And I really don't what .NET uses internally. Can't find anything either.

I've been thinking, but I don't know who to "blame", .NET or the OpenClient. Either way, it's now at the hands of TechSupport (case: 00168941).

Thanks

Posted by gus on 22-May-2012 09:57

Well, blame me then.

Sorry, but I have been successful in preserving my ignorance of .Net. Tech support is more likely to be able to help.

Posted by numitor26 on 24-May-2012 05:53
This thread is closed