Time and CurrentDatetime in webservice

ara3nara3n Member Posts: 9,256
edited 2010-09-21 in NAV Three Tier
It looks like the service tier in 2009 Sp1 is populating the TIme and CurrentDate based on GMT time and not based on local in C/Side.


In my example. Onrelease of Sales order the following code is run.


"Release Date" := Today;
"Release Time" := Time;



The problem is that from if you go and look at the order, it's released 5 hours in future. The client is on Eastern time zone.


I did a quick test webservice function and getcurrentdatetime

returnvalue := substrno('Current time is %1, date %1, Datetime%1',today,time,currentdatetime);

and it again returns future tune and datetime.

It looks like a bug.

I did see this thread
viewtopic.php?f=32&t=33833&hilit=date+time+webservice

but it's pre 2009 sp1.
Ahmed Rashed Amini
Independent Consultant/Developer


blog: https://dynamicsuser.net/nav/b/ara3n

Comments

  • kinekine Member Posts: 12,562
    The answer is still same, NAV cannot know in which timezone the calling client is, thus the calling application is responsible to correct the time by timezone...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ara3nara3n Member Posts: 9,256
    this is c/side code. that is executed.

    on release of sales order the code is executed. the client connected to webservice does not have access to the code.

    If you for example have oninsert trigger of a table. Date time inserted, webservice will insert the GMT time
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    Ok, does it mean that when you store 14:00 1.1.2010 into the field when running the code through webservice, you client using NAV will see "14:00 1.1.2010" instead "6:00 1.1.2010" (if the time zone is -8:00)?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ara3nara3n Member Posts: 9,256
    If TIME is executed on a service tier and lets say the time zone is -8. And it's 2 pm local time. TIME Returns 10 PM. If I login with nav client on the same time zone and look that the time field, it shows 10 pm.

    TIME does not return local time, since this is a webservice, it returns GMT time.



    same applies to datetime. it always returns GMT time.

    I have to write the code differently. to something like this.

    if isServicetier or "iswebservice" then
    "Tme Inserted" := TIme - 8hr
    else
    "time Inserted" := time;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    Ok, I understand it. It is expected for datetime variable, but using timezone for TIME variable is nonsense, because it is missing the "date" part which could be correctly shifted... I have hit similar problem with XMLPort or somewhere else...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mboon75mboon75 Member Posts: 16
    Hi,

    I'm running into the same problem. Is this going to be fixed by Microsoft?
    To my humble opinion this is a bug.

    TIME and DATETIME should look to the Date and Time settings of the server where the App Tier is running.

    Regards
  • mboon75mboon75 Member Posts: 16
    This is how Microsoft Support advises to fix this. ](*,) (BTW, they are not going to do it themselves in tabel 5900, 5901 and all other places where the TIME function is used).

    //This code write to time variable NAVTime current server time
    IF ISSERVICETIER THEN
    IF GUIALLOWED THEN BEGIN
    //>>RTC execution
    NavTime:=TIME;

    END
    ELSE BEGIN
    //WEB execution
    //get web app hours and minutes to text
    txtTime:=FORMAT(TIME,4,2);
    //take hours and minutes to separate texts
    txtHours:=COPYSTR(txtTime,1,2);
    txtMinutes:=COPYSTR(txtTime,3,2);
    //convert or just copy time to one more time variable
    EVALUATE(tmTimeUtc,txtTime);
    //Convert time to UTC and get hours
    txtHoursUTC:=COPYSTR(FORMAT(tmTimeUtc,0,9),1,2);

    // convert hoursUT and hours to integer
    EVALUATE(intHoursUTC,txtHoursUTC);
    EVALUATE(intHours,txtHours);
    // calculate difference between UTC and local time and add difference to web service time
    intHours:=intHours+intHours-intHoursUTC;
    //create local time based on UTC + time zone
    EVALUATE(NavTime,FORMAT(intHours)+txtMinutes);

    END
    ELSE BEGIN
    //>>CC execution
    NAVTime:=Time;

    I always had the assumption that we had the Middle Tier (Business Layer) to ensure all client execute the same code.
Sign In or Register to comment.