This function calculate the time in MS from a duration instance.
returns zero when duration is null.
int timeout = 0;
if (duration != null) {
switch (duration.timeUnit) {
case MINUTE:
timeout = 1000 * 60;
break;
case TENTH_SECOND:
timeout = 1000 * 10;
break;
case SECOND:
default:
timeout = 1000;
break;
}
timeout *= duration.timeInterval;
}
return timeout;