invalid js date from sf field after parseSFDate?!?!

  • 1
  • Question
  • Updated 4 years ago
  • Answered
It's all in the pic.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
  • confuzzed

Posted 4 years ago

  • 1
Photo of Menachem Shanowitz

Menachem Shanowitz

  • 1,074 Points 1k badge 2x thumb
Interesting.. Maybe give skuid.time.parseSFDateTime a shot
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Weird I know. I'll try it, but the SF field is type Date. Shouldn't work. One sec.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Returns false. Love Chrome developer tools! Starting to get a hang of the errors.

Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Here's a video of me unsuccessfully trying to use the date objects. 

Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Pat.

just a cursory look, but notice that your formula field returns a Date.  The parseSFDate function takes a Salesforce Date string.   Hope this helps.


parseSFDate( sfDate )

Takes a Salesforce Date string and converts it to a JavaScript Date object

PARAMETERS:

  • sfDate (string): A Salesforce date string

RETURNS:

Date

The corresponding JavaScript Date object













Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Found a post saying that this is to be expected.
http://stackoverflow.com/questions/9725299/why-does-chrome-dev-tool-show-a-dates-proto-as-invalid-date


So then my coding approach was the issue. I was trying to compare one object to another object. By definition, no two objects can ever be equal. I was really supposed to compare the values in the object. At least that's my thinking. Let me know otherwise.

So I instead I set the vars to strings using toISOString(). Now it works. :D
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Good to hear.  Happy coding.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Happy is one word for it.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Pat here is a good post about doing comparisons with Dates in JavaScript. If you just want to do > or < checks, then comparing the straight JavaScript Date objects as returned by skuid.time.parseSFDate() or skuid.time.parseSFDateTime() would be fine, e.g. 

skuid.time.parseSFDate(sfDate1) < skuid.time.parseSFDate(sfDate2)

But for testing equality it is not as easy as doing == or ===, you need to compare either the getTime() values for each Date or subtract the dates from each other and see whether the result === 0.