no message
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
<option value="day">Tag</option>
|
<option value="day">Tag</option>
|
||||||
<option value="week">Woche</option>
|
<option value="week">Woche</option>
|
||||||
<option value="month">Monat</option>
|
<option value="month">Monat</option>
|
||||||
|
<option value="year">Jahr</option>
|
||||||
<option value="total">Gesamt</option>
|
<option value="total">Gesamt</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
@@ -153,6 +154,34 @@
|
|||||||
const mi = String(d.getMinutes()).padStart(2,'0');
|
const mi = String(d.getMinutes()).padStart(2,'0');
|
||||||
return `${dd}.${mm}.${yyyy} ${hh}:${mi}`;
|
return `${dd}.${mm}.${yyyy} ${hh}:${mi}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function fmtDay(d) {
|
||||||
|
const dd = String(d.getDate()).padStart(2,'0');
|
||||||
|
const mm = String(d.getMonth() + 1).padStart(2,'0');
|
||||||
|
const yyyy = d.getFullYear();
|
||||||
|
return `${dd}.${mm}.${yyyy}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function monthNameDe(m) {
|
||||||
|
return ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'][m] || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// ISO Woche + ISO Jahr (wichtig: ISO-Jahr kann am Jahresrand abweichen)
|
||||||
|
function getISOWeekYear(date) {
|
||||||
|
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||||
|
// Donnerstag bestimmt ISO-Jahr
|
||||||
|
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
|
||||||
|
const isoYear = d.getUTCFullYear();
|
||||||
|
const yearStart = new Date(Date.UTC(isoYear, 0, 1));
|
||||||
|
const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
||||||
|
return { week: weekNo, year: isoYear };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function showErr(e) {
|
function showErr(e) {
|
||||||
const msg = (e && e.message) ? e.message : String(e);
|
const msg = (e && e.message) ? e.message : String(e);
|
||||||
elErr.textContent = 'JS-Fehler: ' + msg;
|
elErr.textContent = 'JS-Fehler: ' + msg;
|
||||||
@@ -242,13 +271,24 @@ return `
|
|||||||
elDate.disabled = isTotal;
|
elDate.disabled = isTotal;
|
||||||
|
|
||||||
if (data?.tStart && data?.tEnd) {
|
if (data?.tStart && data?.tEnd) {
|
||||||
const s = new Date(data.tStart * 1000);
|
const s = new Date(data.tStart * 1000);
|
||||||
const e = new Date(data.tEnd * 1000);
|
|
||||||
elPeriod.textContent = isTotal
|
if (data.range === 'total') {
|
||||||
? 'Zeitraum: Gesamt'
|
elPeriod.textContent = 'Zeitraum: Gesamt';
|
||||||
: `Zeitraum: ${fmtDateTime(s)} – ${fmtDateTime(e)}`;
|
} else if (data.range === 'day') {
|
||||||
|
elPeriod.textContent = `Zeitraum: ${fmtDay(s)}`;
|
||||||
|
} else if (data.range === 'month') {
|
||||||
|
elPeriod.textContent = `Zeitraum: ${monthNameDe(s.getMonth())} ${s.getFullYear()}`;
|
||||||
|
} else if (data.range === 'week') {
|
||||||
|
const iso = getISOWeekYear(s);
|
||||||
|
elPeriod.textContent = `Zeitraum: Woche ${iso.week} ${iso.year}`;
|
||||||
|
} else if (data.range === 'year') {
|
||||||
|
elPeriod.textContent = `Zeitraum: ${s.getFullYear()}`;
|
||||||
} else {
|
} else {
|
||||||
elPeriod.textContent = '';
|
elPeriod.textContent = '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
elPeriod.textContent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class Energy_Pie extends IPSModule
|
|||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
// ensure range valid
|
// ensure range valid
|
||||||
$range = $this->ReadAttributeString(self::ATTR_RANGE);
|
$range = $this->ReadAttributeString(self::ATTR_RANGE);
|
||||||
if (!in_array($range, ['day', 'week', 'month', 'total'], true)) {
|
if (!in_array($range, ['day', 'week', 'month', 'year', 'total'], true)) {
|
||||||
$this->WriteAttributeString(self::ATTR_RANGE, 'day');
|
$this->WriteAttributeString(self::ATTR_RANGE, 'day');
|
||||||
}
|
}
|
||||||
// ensure date valid (not empty/invalid/future)
|
// ensure date valid (not empty/invalid/future)
|
||||||
@@ -51,7 +51,7 @@ class Energy_Pie extends IPSModule
|
|||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
case 'SetRange':
|
case 'SetRange':
|
||||||
$range = (string)$Value;
|
$range = (string)$Value;
|
||||||
if (!in_array($range, ['day', 'week', 'month', 'total'], true)) {
|
if (!in_array($range, ['day', 'week', 'month', 'year', 'total'], true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->WriteAttributeString(self::ATTR_RANGE, $range);
|
$this->WriteAttributeString(self::ATTR_RANGE, $range);
|
||||||
@@ -137,6 +137,12 @@ class Energy_Pie extends IPSModule
|
|||||||
$start = strtotime(date('Y-m-01 00:00:00', $base));
|
$start = strtotime(date('Y-m-01 00:00:00', $base));
|
||||||
$end = strtotime(date('Y-m-01 00:00:00', strtotime('+1 month', $start)));
|
$end = strtotime(date('Y-m-01 00:00:00', strtotime('+1 month', $start)));
|
||||||
return [$start, $end];
|
return [$start, $end];
|
||||||
|
|
||||||
|
case 'year':
|
||||||
|
$start = strtotime(date('Y-01-01 00:00:00', $base));
|
||||||
|
$end = strtotime(date('Y-01-01 00:00:00', strtotime('+1 year', $start)));
|
||||||
|
return [$start, $end];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return [$base, $base + 86400];
|
return [$base, $base + 86400];
|
||||||
}
|
}
|
||||||
@@ -227,6 +233,9 @@ class Energy_Pie extends IPSModule
|
|||||||
case 'month':
|
case 'month':
|
||||||
$base = strtotime(($sign === -1 ? '-1 month' : '+1 month'), $base);
|
$base = strtotime(($sign === -1 ? '-1 month' : '+1 month'), $base);
|
||||||
break;
|
break;
|
||||||
|
case 'year':
|
||||||
|
$base = strtotime(($sign === -1 ? '-1 year' : '+1 year'), $base);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$this->WriteAttributeString(self::ATTR_DATE, date('Y-m-d', $base));
|
$this->WriteAttributeString(self::ATTR_DATE, date('Y-m-d', $base));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user