Allow multiple alarms being set for countdown widget

This commit is contained in:
Hadi Nategh 2022-03-15 16:57:56 +01:00
parent 89ebb61f76
commit 1d559e9263

View File

@ -120,10 +120,17 @@ export class et2_countdown extends et2_valueWidget {
let distance = this.time.getTime() - now.getTime();
if (distance < 0) return 0;
if (this.options.alarm > 0 && this.options.alarm == distance/1000 && typeof this.onAlarm == 'function')
let alarms = Array.isArray(this.options.alarm) ? this.options.alarm : [this.options.alarm];
for (let i=0;i<=alarms.length;i++)
{
if (alarms[i] > 0 && alarms[i] == distance/1000 && typeof this.onAlarm == 'function')
{
this.onAlarm();
}
}
let values = {
days: Math.floor(distance / (1000 * 60 * 60 * 24)),
hours: Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),