Time Zone issue with Salesforce toolkit for Flex

by

Use Case for GMT +5:30

If a date is saved having the time HH hours and minutes between 0 to 29, the force-flex.swc toolkit serializes this date with time zone offset having additional 1 hour difference. So the date saved in the database will have one hour difference than actual date sent. This is because the logic written in Util.as class of the toolkit is not considering the difference between UTC and local time when the difference in minutes is negative. So the resultant time zone has additional 1 hour offset.

Consider the following case:

A date passed to the dateTimeToString function in Utis.as class in the toolkit is 16/02/2010 (mm/dd/yyyy format) and time 16 hours and 15 minutes.(Note the date specified is for GMT +5:30)

Date sent to Salesforce

The date after conversion is as shown in the soap message taken from httpfox tool of Mozilla firefox.

As seen from the soap message, the StartDateTime has the time zone set as +06:30 which is not the expected time zone.

Why this happens?

Consider the time for given date. Its 16 hours and 15 minutes.  When calculating time zone difference, the code in dateTimeToString function in Utis.as neglects the negative difference between the minutes. When the user enters 16 hours and 15 minutes, it will be 10 hours and 45 minutes in GMT(UTC). But during calculation what is happening is the difference between the hours and minutes is directly considered as time zone offset which in this case will be 6 hours (16 – 10) and -30 minutes        (15 – 45). As the –ve sign for minutes difference is neglected, it is reflected as 1 hour additional difference in calculated hour for time zone.

Fix for the Bug

To fix the bug, just put a check in Util.as class in the function dateTimeToString as shown below:

Time Zone issue Fix

I hope someone will find this helpful as I spent 2 whole days figuring out what the problem was.

Advertisements

Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: