Skip to content

Js Dates converted to Apex Dates with time #3497

Open
@stackasaur

Description

@stackasaur

Description

While working on an aura enabled apex method that takes in an Apex Date, I passed in a JS Date object from my LWC. This was accidental, as usually I'd pass in an ISO date string. To my surprise the parser allowed it! But oddly, the Date in apex had an associated time. Normally, when you System.debug a date, it has a 0 time, but this Date had an actual time.

This is a pretty big issue as logic dependent on Dates such as checking if start and end DateTimes overlaps with the Date can fail dependent on time of day. In my case, the Date had a time around UTC 19:00 and thus a lot of logic would fail.

I'm sure this is more an Apex issue, so feel free to forward the info to the Apex team and close this issue

Steps to Reproduce

//Apex
@AuraEnabled(Cacheable=true)
Public static void test(Date d){
  System.debug(d);
}

//LWC 
date = new Date();
@wire(test,{d:'$date'})
wiredTest;

Workaround

Just turn the date into an ISO string.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    External: Other SalesforceCategorizes issue or PR as related to Salesforce related features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions