I have a local storage array that is mapped to a list item like this:
I use this code on mapping response from '_createdAt' to 'Time' label on the list item:
pre
var Now = new Date();
var Now2 = Now.setDate(Now.getDate());
var postDate = new Date(value);
var postDate2 = postDate.setDate(postDate.getDate());
var diffInS = (((Now2 - postDate2)/1000)-3600); // /1000 puts it in seconds... -3600 1 hour difference between database GMT and device (BST) british summer time.
alert("diffInS: " + diffInS + " diffInS type: " + typeof diffInS);
var day_diff = Math.floor(diffInS / 86400);
if (day_diff < 1){
if (diffInS < 60){
return "just now";
}
if (diffInS < 3600){
min = Math.floor( diffInS / 60 );
return min+ "m";
}
if (diffInS < 7200){
return "1hr";
}
Code: Select all
if (diffInS < 86400){ hr = Math.floor( diffInS / 3600 );
return hr + "hr";
}
}
else if (day_diff = 1 && day_diff < 14) {
return day_diff + "d";
}
else if (day_diff 14) {
week = Math.floor( day_diff / 7 );
return week + "w";
}
Code: Select all
else { return "error";
}
/pre
when testing on browser it works as expected.
the alert code alert("diffInS: " + diffInS + " diffInS type: " + typeof diffInS);/code:
when i test it on the appery test app on ios device (iphone 4s) I get the alert:
diffInS: NaN diffInS type: number
This doesn't seem to make sense to me.
I tried parseInt, and parseFloat but neither work.
any ideas?