We are facing an issue with BST and GMT time zone.
We have a community portal and the org timezone and all the Users timezone are set as BST.
Part of our functionality is to book an event and we redirect our users (on the community portal) to a third party system which displays available slots in BST.
Once the user provides their detail and confirms their booking, this third party system then POSTS back into salesforce and create a record of our custom Event booking object.
The Event Booking object has a custom field Booking_Start_Time__c and Booking_End_Time__c.
The third party system, for an event booked for 9:00 AM to 9:30 AM, send
{"Booking_Start_Time__c" : "08:00:00.000Z",
"Booking_End_Time__c" : "08:30:00.000Z"}
Essentially, they are sending the GMT time (-1 for the actual booking time) for booking start and end times.
The issue is Salesforce displays this as is i.e. "08:00" and "08:30" on the Event Booking detail page even though the User's timezone is set as BST
I am unable to explain this behaviour and would appreciate if someone can shed some light on this.
Adding some screenshots
Best Answer
All DateTimes in Salesforce are stored as GMT/UTC so that they can easily be shifted based on a user's timezone (a necessity in any organization where users are logging in from multiple time zones). So if you see GMT in the database, that's as designed. If the time isn't being shown properly to the end user, consider using a component that displays a DateTime based on a user's locale such as formatted-date-time in a LWC, or lightning:formattedDateTime in an Aura component. You can also render a DateTime in a specific timezone using the
DateTime.format()
method in Apex or a combination ofdate()
, which returns the current date in the context of the running user, andtime()
which returns the current time in the context of the running user.This outputs (I ran this as a user with an American locale and an EDT timezone):
EDIT
I think I see the problem and it's my own inexperience with "Time" custom fields (they're relatively new) as opposed to "DateTime" custom fields. Time fields don't react to a user's location. That's because "11:00", "14:00", "12:50 AM" would all be valid inputs to a Time field and - without a date component - it's not possible to know if Daylight Savings Time is in effect or how far to shift a time based on where you are in the world. See some of the notes from Salesforce regarding the Time field or this Trailblazers post. Relevant answer quoted below from Amnon Kruvi:
If you know you will only ever need to support BST timezone (and Daylight Savings isn't a factor) and no one in the org will ever be another timezone, it's probably safe to set the timezone for the org to BST and use a Time field. However, if you need to support multiple timezones I would switch to using a DateTime field instead to accurately capture times.