Botframework-solutions: Typescript: Local Timestamp overwritten in parse request

Created on 21 Jan 2020  ·  4Comments  ·  Source: microsoft/botframework-solutions

What project is affected?

Skills and VA

What language is this in?

Typescript

What happens?

When we send messages from different timezones the localTimezone is overwritten every time with the Local Server Timezone and we lose the User's Timezone.

What are the steps to reproduce this issue?

Try to send a message from a client in a Timezone and receive the message from a different timezone of the client.

What were you expecting to happen?

At least to have in the context the user timezone

Can you share any logs, error output, etc.?

This happens in the BotFrameworkAdapter, during the processActivity method and the parseRequest function.

if (typeof activity.localTimestamp === 'string') { activity.localTimestamp = new Date(activity.localTimestamp); }

Any screenshots or additional context?

Bot Services Bug customer-replied-to customer-reported

Most helpful comment

Hi @tommyJimmy87! Thanks for reporting the issue!

We reproduced the issue and we would like to validate with you the repro steps that we followed to accomplish this. Also, we will continue reproducing the issue using a C# bot in order to compare the implementations and find the next steps to solve the issue.

Repro Steps

Using the TypeScript Virtual Assistant Sample

  1. Go to the Virtual Assistant's folder
  2. Install the dependencies with npm install
  3. Compile the solution with npm run build
  4. Deploy the Virtual Assistant using the following command:
pwsh.exe -File deployment\scripts\deploy.ps1 -name "<BOT_NAME>" -location "<LOCATION>" -appId "<APP_ID>" -appPassword "<APP_PASSWORD>" -luisAuthoringKey "<LUIS_AUTHORING_KEY>" -luisAuthoringRegion "<LUIS_AUTHORING_REGION>"
  1. Open the Bot Framework Emulator and configure it to connect the Virtual Assistant running locally
    image

  2. Set a breakpoint in the line 1004 of botFrameworkAdapter.ts inside of Botbuilder library
    image

  3. Change the System Time zone to a different one (e.g. UTC+03:00 Minsk)
    image

  4. Debug the Virtual Assistant

  5. Start the chat with the Virtual Assistant using the emulator
  6. The execution will stop at the breakpoint. The activity.localTimestamp will show the datetime with the previous Local Server Timezone
    image

  7. After the assignment, the new datetime of activity.localTimestamp will have the new User's Timezone
    image

Thanks :relaxed:

All 4 comments

Hi @tommyJimmy87! Thanks for reporting the issue!

We reproduced the issue and we would like to validate with you the repro steps that we followed to accomplish this. Also, we will continue reproducing the issue using a C# bot in order to compare the implementations and find the next steps to solve the issue.

Repro Steps

Using the TypeScript Virtual Assistant Sample

  1. Go to the Virtual Assistant's folder
  2. Install the dependencies with npm install
  3. Compile the solution with npm run build
  4. Deploy the Virtual Assistant using the following command:
pwsh.exe -File deployment\scripts\deploy.ps1 -name "<BOT_NAME>" -location "<LOCATION>" -appId "<APP_ID>" -appPassword "<APP_PASSWORD>" -luisAuthoringKey "<LUIS_AUTHORING_KEY>" -luisAuthoringRegion "<LUIS_AUTHORING_REGION>"
  1. Open the Bot Framework Emulator and configure it to connect the Virtual Assistant running locally
    image

  2. Set a breakpoint in the line 1004 of botFrameworkAdapter.ts inside of Botbuilder library
    image

  3. Change the System Time zone to a different one (e.g. UTC+03:00 Minsk)
    image

  4. Debug the Virtual Assistant

  5. Start the chat with the Virtual Assistant using the emulator
  6. The execution will stop at the breakpoint. The activity.localTimestamp will show the datetime with the previous Local Server Timezone
    image

  7. After the assignment, the new datetime of activity.localTimestamp will have the new User's Timezone
    image

Thanks :relaxed:

Hi @VictorGrycuk ! Thanks for the fast answer first of all!

I don't know if I understood very well the steps, but I'll try to explain myself better with all the steps we did to reproduce the issue:

  1. First assumption is that we have the Virtual Assistant deployed locally.

  2. Second assumption is that we want to perform the test with 2 different laptops, where the first laptop is the client (for us is Teams) and the second laptop is the server where we are running the VA.

  3. Third assumption is that we have 2 different Timezone set up on the 2 laptops, let's say the first one (client) will have GMT+0300 and the server will have GMT+0100.

  4. Then after we have everything set up we try from the client to send a request to the VA through Teams.

  5. As soon as we get the request we have as parameter in the body the right timezone from the user :

Screen Shot 2020-01-23 at 14 30 02

Screen Shot 2020-01-23 at 14 29 49

  1. Inside the parse request we get the right Client Timezone :

Screen Shot 2020-01-23 at 14 34 12

  1. But then after the assignment of the variable (basically the new Date(activity.localTimestamp) ), we have the server Timezone:

Screen Shot 2020-01-23 at 14 36 52

Hey @tommyJimmy87! Thanks for the detailed steps! We will be reviewing this scenario and we will back to you later 😊.

Hi @tommyJimmy87!

We reached the conclusion that this is due to a limitation on how JavaScript handles the Date object.

However, we want to let you know that we opened the issue #1612 about this issue on the BotBuilder-JS repository. You may track the progress of this issue there, so check there as well.

As for the problem we found, when converting any date to Date object, JS converts it to UTC which essentially strips the original time zone. The only time zone that JavaScript can handle is the time zone of the system running JS.
You can check the Date documentation for information.

We will let you know any progress :relaxed:

Was this page helpful?
0 / 5 - 0 ratings