I have discovered bug with the ArcGIS API for JavaScript, which affects ClosestFacility calls: “timeOfDay” values are incorrectly sent to the server as a string of the date, i.e. timeOfDay: “2019-08-19T23:45:00.000Z”, however testing using the endpoint reveals it should be sent in a milliseconds since epoch (Unix) format, i.e. timeOfDay: 1566258300000. This causes the server to resort to some kind of default time, so that the wrong result is returned… Route task (I have not tested others) does correctly send the routing time parameter (startTime) in Unix format.
To confirm the issue:
Here is a Codepen demonstrating the above: https://codepen.io/stacy-rendall/pen/qBWZQJr
For some unknown reason Esri have noted this bug, but closed the issue claiming that it is "by design" (BUG-000124691: ClosestFacilityTask sends the timeOfDay parameter as.. ), this makes no sense - the bug causes the server to ignore the specified "timeOfDay", there is no way that could be "by design".
I have implemented a pretty rough workaround (calling the server directly using "esri/request") that I can share if it is useful to anyone (Esri devs?).