Does the Sample project have a bug? ‘DigitalWatch’
Does the Sample project have a bug? ‘DigitalWatch’
BY 08 Mar 2017Web Application Development
The sample project ‘DigitalWatch’ has the following code:
function updateDate(prevDay) {
var datetime = tizen.time.getCurrentDateTime(),
nextInterval,
strDay = document.getElementById("str-day"),
strFullDate,
getDay = datetime.getDay(),
getDate = datetime.getDate(),
getMonth = datetime.getMonth();
// Check the update condition.
// if prevDate is '0', it will always update the date.
if (prevDay !== null) {
if (prevDay === getDay) {
/**
* If the date was not changed (meaning that something went wrong),
* call updateDate again after a second.
*/
nextInterval = 1000;
} else {
/**
* If the day was changed,
* call updateDate at the beginning of the next day.
*/
// Calculate how much time is left until the next day.
nextInterval =
(23 - datetime.getHours()) * 60 * 60 * 1000 +
(59 - datetime.getMinutes()) * 60 * 1000 +
(59 - datetime.getSeconds()) * 1000 +
(1000 - datetime.getMilliseconds()) +
1;
}
}
if (getDate < 10) {
getDate = "0" + getDate;
}
strFullDate = arrDay[getDay] + " " + getDate + " " + arrMonth[getMonth];
strDay.innerHTML = strFullDate;
// If an updateDate timer already exists, clear the previous timer.
if (timerUpdateDate) {
clearTimeout(timerUpdateDate);
}
// Set next timeout for date update.
timerUpdateDate = setTimeout(function() {
updateDate(getDay);
}, nextInterval);
}
1. At first the method ‘updateDate(prevDay)’ is called with 0 parameter;
2. In the end this method sets a timeout with the particular time interval to call itself again but with the other parameters (0 ‘Sun’, 1 ‘Mon’, 2 ‘…’, 3, 4, 5, 6);
If the application is started on Monday (1 is a parameter for Monday) the method sets the correct time interval (23:59:59:1000 minus actual time) however the wrong time interval (1 second) is set if the application is started on Sunday (0 is a parameter for Sunday), so this updateDate(prevDay) method is called every second the whole day until the next day.
So I’ve changed the argument to -1 and the application works fine now.
Does the Sample project have a bug? ‘DigitalWatch’
The sample project ‘DigitalWatch’ has the following code:
1. At first the method ‘updateDate(prevDay)’ is called with 0 parameter;
2. In the end this method sets a timeout with the particular time interval to call itself again but with the other parameters (0 ‘Sun’, 1 ‘Mon’, 2 ‘…’, 3, 4, 5, 6);
If the application is started on Monday (1 is a parameter for Monday) the method sets the correct time interval (23:59:59:1000 minus actual time) however the wrong time interval (1 second) is set if the application is started on Sunday (0 is a parameter for Sunday), so this updateDate(prevDay) method is called every second the whole day until the next day.
So I’ve changed the argument to -1 and the application works fine now.
I don’t think it is normal. How do you think?
BY
16 Apr 2025
Tizen Studio
BY
04 Nov 2024
Tizen Studio
BY
02 Apr 2024
Tizen Studio