TRUNK-3829: Code improvements for calendar.js
(cherry picked from commit 79237cd1c48e12186ae8e00a2fbd93ff1b162522)