Page 1 of 1

ios device time

Posted: Tue Jul 28, 2015 6:55 pm
by Joe Sharples

I have a local storage array that is mapped to a list item like this:
Image

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&#46;floor( diffInS / 60 );
return min+ "m";
}

if (diffInS < 7200){
return "1hr";
}

Code: Select all

 if (diffInS < 86400){ 

hr = Math&#46;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&#46;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:
Image

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?


ios device time

Posted: Wed Jul 29, 2015 4:39 pm
by Joe Sharples

how come it shows as NaN but has the type of 'number'?

how can change the code so that the variables are used as numbers so that the if function can work?

at the moment on the browsers it shows the correct timestamp, ' justnow / m / hr / d / w' for each list item.

but on the tester app it returns "error"


ios device time

Posted: Wed Jul 29, 2015 5:26 pm
by Illya Stepanov

Hi Joe -

Since we don't know your implementation it is hard to say by this information what could be wrong here.

Try placing this before diffInS and check console output:
precode
console&#46;log(typeof postDate);
console&#46;log(typeof postDate2); /code/pre


ios device time

Posted: Thu Jul 30, 2015 4:23 pm
by Joe Sharples

Hi Illya

I added:

pre
console&#46;log("Now: "+ Now);
console&#46;log("typeof Now: "+ typeof Now);
/pre
pre
console&#46;log("Now2: "+ Now2);
console&#46;log("typeof Now2: "+ typeof Now2);
/pre
pre
console&#46;log("postDate: " + postDate);
console&#46;log("typeof postDate: " + typeof postDate);
/pre
pre
console&#46;log("postDate2: "+ postDate2);
console&#46;log("typeof postDate2: "+ typeof postDate2);
/pre

and got this:
Image

Any Ideas?


ios device time

Posted: Sun Aug 02, 2015 4:08 pm
by Joe Sharples

When I test this on ios, using 'alert' instead of 'console.log' it shows 'NaN' and type of as 'number'.


ios device time

Posted: Wed Aug 05, 2015 3:06 pm
by Joe Sharples

after testing again i've come across the error.

pre
var postDate = new Date(value);
var postDate2 = postDate&#46;setDate(postDate&#46;getDate());
/pre

postDate returns 'Invalid Date' on ios. but returns the date normally on web browser.
Therefore on browser postDate2 returns a number, where as on ios device it returns NaN.

pre
var Now = new Date();
var Now2 = Now&#46;setDate(Now&#46;getDate()); /pre
this works correctly on browser and device. Now returns the date at this instances. Now2 the date turned into a number.

how do i take a date from the database and turn it into a number that can be used to work out the difference between 2 date times?


ios device time

Posted: Wed Aug 05, 2015 5:17 pm
by Illya Stepanov

Hi Joe -

Thanks for this detailed information, we will investigate this further with our developers.


ios device time

Posted: Wed Aug 12, 2015 1:50 pm
by Alena Prykhodko

Joe,

We have checked code, it seems to be valid, works as expected on device.


ios device time

Posted: Wed Aug 19, 2015 8:53 am
by Joe Sharples

Thank you. I will test on device soon