Fixing invalid date error in Safari