Urgent Help needed with Date in Calendar

  • 1
  • Problem
  • Updated 4 years ago
  • Solved
Help please,

I don't quite understand why the Date is showing correctly on the Calendar, but when I use the date in code it shows like two hours later.

Any help appreciated. Am running against a deadline.
TY.



Photo of Sofware Developer Guy

Sofware Developer Guy

  • 1,354 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Two quick questions.  What is your timezone in Salesforce Setup?  What is your timezone for your local OS?
Photo of Sofware Developer Guy

Sofware Developer Guy

  • 1,354 Points 1k badge 2x thumb
SF TimeZone:


My TimeZone:
Photo of Sofware Developer Guy

Sofware Developer Guy

  • 1,354 Points 1k badge 2x thumb
Thank you so much by the way for responding so quickly.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Ok, this makes sense then.  You're actually seeing the same times there.  Throughout Skuid we made the decision to respect your timezone in SF setup instead of your OS's timezone.  So the time you're seeing in the calendar is in PST, but the time Javascript is showing you is in your browser's timezone.  They're actually the same point in time.

Obviously, when writing a robust application, we need to deal with these cases when the user's local timezone, (Javascript's timezone) is different than the timezone they've specified in Salesforce Setup.

There's a function in Skuid's skuid.time api called skuid.time.getLocalDateTime() that you might want to use instead of skuid.time.getDateTime().  I thought this was documented, but when I checked the docs I see that it isn't. (Sorry about that).

skuid.time.getLocalDateTime() will actually return the "wrong" javascript date, but offset for the difference between the users salesforce timezone and the browser's timezone.  This however can help to handle those cases where you want your app to function correctly when the user's two timezones differ.

Does this make sense?  I'd be glad to elaborate more if necessary.
Photo of Sofware Developer Guy

Sofware Developer Guy

  • 1,354 Points 1k badge 2x thumb
Thank you,

I modified my function like so:

function getDateTime(value){
var sfDateTime = skuid.time.parseSFDateTime(value);
return skuid.time.getLocalDateTime(sfDateTime);
}

It works correctly now.

How about when I save it back to the mode: is there a trick to that too?

Thanks,
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Yeah.  

skuid.time.getRealJSDateTimeFromLocal(localDate) will convert from your offset date back to the actual "Correct" javascript date.