mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-24 08:53:37 +01:00
Reduce time complexity of alarms calculation
This commit is contained in:
parent
4d7dffeb24
commit
bc63d06f16
@ -86,11 +86,18 @@ var et2_countdown = /** @class */ (function (_super) {
|
||||
var distance = this.time.getTime() - now.getTime();
|
||||
if (distance < 0)
|
||||
return 0;
|
||||
var alarms = Array.isArray(this.options.alarm) ? this.options.alarm : [this.options.alarm];
|
||||
for (var i = 0; i <= alarms.length; i++) {
|
||||
if (alarms[i] > 0 && alarms[i] == Math.floor(distance / 1000) && typeof this.onAlarm == 'function') {
|
||||
this.onAlarm();
|
||||
}
|
||||
var alarms = [];
|
||||
if (Array.isArray(this.options.alarm)) {
|
||||
alarms = this.options.alarm;
|
||||
}
|
||||
else {
|
||||
alarms[this.options.alarm] = this.options.alarm;
|
||||
}
|
||||
// alarm values should be set as array index to reduce its time complexity from O(n) to O(1)
|
||||
// otherwise the execution time might be more than a second which would cause timer being delayed
|
||||
if (alarms[Math.floor(distance / 1000)] && typeof this.onAlarm == 'function') {
|
||||
console.log('alarm is called');
|
||||
this.onAlarm();
|
||||
}
|
||||
var values = {
|
||||
days: Math.floor(distance / (1000 * 60 * 60 * 24)),
|
||||
|
@ -121,14 +121,22 @@ export class et2_countdown extends et2_valueWidget {
|
||||
|
||||
if (distance < 0) return 0;
|
||||
|
||||
let alarms = Array.isArray(this.options.alarm) ? this.options.alarm : [this.options.alarm];
|
||||
|
||||
for (let i=0;i<=alarms.length;i++)
|
||||
let alarms = [];
|
||||
if (Array.isArray(this.options.alarm))
|
||||
{
|
||||
if (alarms[i] > 0 && alarms[i] == Math.floor(distance/1000) && typeof this.onAlarm == 'function')
|
||||
{
|
||||
this.onAlarm();
|
||||
}
|
||||
alarms = this.options.alarm;
|
||||
}
|
||||
else
|
||||
{
|
||||
alarms[this.options.alarm] = this.options.alarm;
|
||||
}
|
||||
|
||||
// alarm values should be set as array index to reduce its time complexity from O(n) to O(1)
|
||||
// otherwise the execution time might be more than a second which would cause timer being delayed
|
||||
if (alarms[Math.floor(distance/1000)] && typeof this.onAlarm == 'function')
|
||||
{
|
||||
console.log('alarm is called')
|
||||
this.onAlarm();
|
||||
}
|
||||
|
||||
let values = {
|
||||
|
Loading…
Reference in New Issue
Block a user