Patch by Reimar Imhof. I changed it a bit and replaced downcasts with date roles. BUG: 286876 BUG: 286984 (cherry picked from commit 4fbd2549)