Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

Опции темы Поиск в этой теме Опции просмотра
Старый 11.01.2011, 13:40   #1  
Blog bot is offline
Blog bot
22,737 / 777 (71) +++++++
Регистрация: 28.10.2006
In Microsoft Dynamics NAV 2009 R2 we have new feature named "Defining the Time Zone for Web Services". You can read about it at . The same feature exists in Microsoft Dynamics NAV 2009 SP1 since build 31926 with KB 2443436. However we have few support requests when NAV developers or users don't know about this feature availability or don't know how to use it.
I will try to describe in samples what results we have with different sets.

This feature is important only when you are using date; time or datetime fields and functions to create it. So I created table which has date; time; datetime and description fields

I created codeunit which will be published to Web Service and we'll call function cr_dateTime to create date = Jan 10[sup]th[/sup] 2011
Time = 3:00:00 PM
And DateTime from these values.

In Visual Studio I created C# application which just runs function from codeunit.

WSDT is reference to my Web Service codeunit

And now came main feature point: In CustomSettings.config file could be added new key: "WebServiceDefaultTimeZone".
Actually there could be few possibilities:
1. Key doesn't exists. Then WS works as before this feature implementation - WS uses UTC time zone
2. Key value is empty. The same as point 1 - uses UTC time zone
3. Key value is "UTC". This is default value in Dynamics NAV 2009 R2. WS uses UTC time zone.
4. Key value is "Server Time Zone". WS will work using server computer default time zone. If you are using any time/date functions in code then this key will get you the same results as code running on Classic Client; RTC or NAS.
5. Use any other value from available time zones constants. You can find it at Microsoft Time Zone Index Values at . Actually these values already must be in windows registry and if it doesn't exists there, you will have error during WS start.

Here are few of possible time zones values.

My local time zone is "FLE Standard Time"-GMT+02:00, and we need to remember this during execution. So I'm running function from codeunit using different sets.
  • 1. Entry created by directly codeunit run (the same as we would run CC; RTC or NAS). We have value directly what was expected - 3:00 PM. But look in values we have directly in SQL table (second table picture) where NAV stores UTC DateTime. We see that NAV accepted that 3:00PM is local time, so it subtracted 2 hours (according time zone) and wrote 13:00 to SQL (UTC time)
  • 2. Entry created by WS when there is no new featured key added (the same as empty key value or value "UTC"). Date time now is different; NAV shows 5:00 PM but SQL shows 15:00. Situation was that WS thought that time is already UTC and just wrote what it got and NAV adding my time zone (+2:00) to have "local time"
  • 3. Entry created by WS when key value is "Server Time Zone". Situation is the same as in point 1: WS received 3:00 PM, calculated UTC (-2:00), stored it to SQL and NAV shows again local time calculating it from UTC.
  • 4. Entry created by WS when key value is "Central Standard Time". This time zone is GMT-06:00. So WS calculated UTC from 15:00 + 06:00 = 21:00 and wrote it to SQL. NAV calculates and shows my local time 21:00 + 02:00 = 23:00 = 11:00 PM.

So it looks everything clear now. However there are few more points need to be mentioned.
In my samples I created datetime using function CREATEDATETIME(011011D,150000T); But what will happen if I will use function CREATEDATETIME(TODAY,TIME);? Problem is that TIME function also knows about time zones and will use it during calculation.
Look, here is example using different "WebServiceDefaultTimeZone" values, and I set to t_time value from TIME and to d_date value from TODAY. When I did tests it was 11[sup]th[/sup] of Jan 2011 about 10:15 AM morning.

You see differences?

1[sup]st[/sup] entry is by direct codeunit run - my correct time.
2[sup]nd[/sup] entry without key and here comes UTC time.
3[sup]rd[/sup] entry with "Server Time Zone" - my correct time
4[sup]th[/sup] entry with "Standard Central Time" (GMT-06:00) - correct time in that zone (10:21-2:00-6:00).

But look to date_time field - it shows correct time for my zone even everything is different. Why?

It is because datetime uses UTC - look what SQL shows.
1[sup]st[/sup] row - my local time 10:15 - 2:00(my time zone) = 08:15 UTC.
2[sup]nd[/sup] row - UTC time now is 08:18 and the same is in datetime.
3[sup]rd[/sup] row - the same as in 1[sup]st[/sup] row
4[sup]th[/sup] row - local time in that time zone is 2:21 AM; UTC time is 8:21 AM and this is in SQL.

I hope this is clear.
At least you can play with some samples and you will find the way you need to have as result.

These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.

Best Regards
Gedas Busniauskas
Microsoft Lithuania
Microsoft Customer Service and Support (CSS) EMEA

Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Часовой пояс GMT +3, время: 22:22.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.