Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit e4d72c3

Browse files
TanaseButcaruomefire
TanaseButcaru
authored andcommitted
handle 'Invalid Date' error
This closes #125
1 parent 956c76b commit e4d72c3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

www/convertUtils.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ module.exports = {
2828
*/
2929
toCordovaFormat: function (contact) {
3030
var value = contact.birthday;
31-
try {
32-
contact.birthday = new Date(parseFloat(value));
33-
} catch (exception){
34-
console.log("Cordova Contact toCordovaFormat error: exception creating date.");
31+
if (value !== null) {
32+
try {
33+
contact.birthday = new Date(parseFloat(value));
34+
35+
//we might get 'Invalid Date' which does not throw an error
36+
//and is an instance of Date.
37+
if (isNaN(contact.birthday.getTime())) {
38+
contact.birthday = null;
39+
}
40+
41+
} catch (exception){
42+
console.log("Cordova Contact toCordovaFormat error: exception creating date.");
43+
}
3544
}
3645
return contact;
3746
},

0 commit comments

Comments
 (0)