fix javascript that causes preview to sometime show the wrong date