Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Presto's date_trunc function when dealing with daylight savings (#…
…11509) Summary: Pull Request resolved: #11509 date_trunc truncates a datetime to a unit (second/day/year/etc.). It is currently implemented for TSwTZ to do this on the local time and convert it back to a system time which is used as the timestamp portion of the result TSwTZ. Much like date_add and date_diff, it runs into an issue with ambiguous times when the unit is less than a day. In the case of ambigous times it will return the earliest system time that can correspond to the local time, Presto Java however behaves as if the calculation was done on the system time, meaning there's no ambiguity and it can return either of the two or more ambiguous times depending on the original timestamp. To fix this, again like with date_add and date_diff, I've split the logic based on whether the unit is less than a day or at least a day. If it's less than a day, we convert the timestamp to a local time and do the truncation then compute the number of milliseconds between the original local timestamp and the local truncated timestamp. We then subtract that value from the original timestamp's system time. This removes the ambiguity, and gets behavior consistent with Presto Java. If the unit is at least a day, we still do the computation on the local time and convert it back to a system time as we did originally. This is necessary to handle cases like the days when we switch to or from daylight savings time being 23 and 25 hours respectively. Again, this is consistent with Presto Java's behavior. Reviewed By: kgpai, zacw7 Differential Revision: D65791388 fbshipit-source-id: ac80c97b0e4a83b68d52d8785e92346d52a87882
- Loading branch information