1

Does Salesforce have a bug in the day calculation logic if the hours is 00?

May 9th 2016 is a Monday. But Salesforce always returns Sunday. I guess when the hours is 00:00, its considering it as previous day?

Date currentDate = Date.newInstance(2016,5,9);
System.debug(currentDate);
System.debug(((DateTime)currentDate).format('EEE',String.valueOf(UserInfo.getTimeZone())));

The error mentioned above is consistent irrespective of whichever timezone I am in. I tried changing my User records Timezone values as well.

The date mentioned above is just an example. It holds true for any date.

Has someone noticed this ever or mine is a bad code? If so can someone correct me?

Also the Salesforce documentation says, for finding the start of the week, if its US based locale its Sunday and if its UK based locale its Monday. How do I determine which locales are US based and which are UK based? And is there any other type of locales apart from US and UK?

//This line returns me a Sunday if I set my locale to US 
//and Monday if I set my locale to UK
currentDate.toStartOfWeek();

1 Answer 1

0

The documentation states: newInstance(year, month, date) - Constructs a Date from Integer representations of the year, month (1=Jan), and day.

But in what timezone, it doesn't say. A fixed one (GMT+0?), the one from the org or the one from the user? Those could be three different timezones. I don't know which one it is, but apparently the user timezone differs from the one that Salesforce uses to create the newInstance. And since that creates a date with time 0:00, only one timezone difference can put you on a different date as well.

See also this question

1
  • This is true for any timezone and any method which you use to fetch the date.
    – Sathya
    Commented May 11, 2016 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .