How to read the value of a countdown timer type Picker?
Using 1.3.3 and iPhone SDK 4.0, I've got a Picker in my app of type Titanium.UI.PICKER_TYPE_COUNT_DOWN_TIMER but I can't figure out how to read its value. Here's a simple example app.js:
var win1 = Titanium.UI.createWindow({
backgroundColor:'black'
});
var duration = 60000 * 5; // 5 minutes
var picker = Ti.UI.createPicker({
type:Ti.UI.PICKER_TYPE_COUNT_DOWN_TIMER,
countDownDuration:duration
});
picker.selectionIndicator = true;
win1.add(picker);
picker.addEventListener('change',function(e)
{
Ti.API.info('countDownDuration = ' + picker.countDownDuration);
Ti.API.info('value = ' + picker.value);
});
win1.open({modal:false});
When I run this app, the picker is correctly set to 0 hours 5 minutes. When I subsequently change the minutes to 6, 7, 8, 9, and 10, I get the following output:
[INFO] countDownDuration = 300000
[INFO] value = Wed Nov 29 0000 23:58:58 GMT-0800 (PST)
[INFO] countDownDuration = 300000
[INFO] value = Wed Nov 29 0000 23:59:58 GMT-0800 (PST)
[INFO] countDownDuration = 300000
[INFO] value = Thu Nov 30 0000 00:00:58 GMT-0800 (PST)
[INFO] countDownDuration = 300000
[INFO] value = Thu Nov 30 0000 00:01:58 GMT-0800 (PST)
[INFO] countDownDuration = 300000
[INFO] value = Thu Nov 30 0000 00:02:58 GMT-0800 (PST)
What gives? Obviously countDownDuration is read only, but the correlation between the user's selection and picker.value is not very clear.
How is one supposed to retrieve the user's input on one of these pickers? Thanks for any help.
4 Answers
-
One more note. It appears that the UTC time values being returned by the picker are 7 hrs 52 minutes off. If I add the following code, I can get the actual number of milliseconds that the user selected, but this seems like the very definition of the word kludge.
var offset = (7 * 60000 * 60) + (60000 * 52); var ms = (picker.value.getUTCHours() * 60000 * 60) + (picker.value.getUTCMinutes() * 60000) - offset; Ti.API.info('Milliseconds = ' + ms);
When setting the picker to 6 min, 7, min, 8 min, and 9 min, the above code returns:
[INFO] Milliseconds = 360000 [INFO] Milliseconds = 420000 [INFO] Milliseconds = 480000 [INFO] Milliseconds = 540000
Is this a bug, or is there a correct way to read a countdown picker that I'm not aware of? Or does anyone have a better workaround?
-
Even worse than this, once the timer gets to 16h 8 mins, it resets to 0. So if your code returns a negative number, you need to add back the offset, plus (16 60000 60) + (8 * 60000)
OLIVER
-
Hi, having the same problem with version 1.8.1. Don't know how to get value of count down timer. Value of countDownDuration doesn't change by using picker in app.
-
Ditto problem for me with all the latest versions … (2.x + iOS 5)