jamessimone / apex-rollup

Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
MIT License
222 stars 30 forks source link

Miscalculation of date boundary due to time zone differences #640

Open KomalJha01 opened 5 days ago

KomalJha01 commented 5 days ago

I've attached a PDF that explains that boundary cases of date are not handled correctly. In my case, I want to calculate the Amount (Ask_Amount__c is the lookup on contact) on the contact which is N_YEARS_AGO so when I'm taking the boundary values of dates then It does not give the correct amount.

Further details are explained in the pdf.

_Miscalculation of Date Boundary due to Time Zone Differences (1).pdf

jamessimone commented 5 days ago

Thanks for the PDF. I will take a look!

jamessimone commented 5 days ago

@KomalJha01 can you clarify on the following sentence:

we replaced the usage of Datetime.newInstance() with Datetime.newInstanceGMT()

Is that in your own code, or within Apex Rollup? Not all date literals use GMT when calculating date boundaries (see the docs on this):

Each date literal represents a range of time relative to the current day. The exact start and stop of the range depends on the date literal and the locale of the user sending the query.

Thanks!

KomalJha01 commented 5 days ago

This is my own code. Yes but when are calculating the range of date value within the boundaries then dateVal > this.bound.dateGmt() && dateVal > this.ref.dateGmt(); And then .dateGMT() gives the time shift issue results in the wrong calculation. image

jamessimone commented 4 days ago

Got it! I will get this fixed - I've had limited time this week but hoping to be able to dedicate a few hours tomorrow

KomalJha01 commented 3 days ago

Thanks!! @jamessimone