45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
const WeatherUtils = {
|
|
formatDatetimeLocal(date) {
|
|
const offsetMinutes = date.getTimezoneOffset();
|
|
const local = new Date(date.getTime() - offsetMinutes * 60 * 1000);
|
|
return local.toISOString().slice(0, 16);
|
|
},
|
|
|
|
initializeDateInputs() {
|
|
const now = new Date();
|
|
const startDate = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
|
const endDate = new Date(now.getTime() + 3 * 60 * 60 * 1000);
|
|
|
|
const startDateInput = document.getElementById('startDate');
|
|
const endDateInput = document.getElementById('endDate');
|
|
|
|
if (startDateInput) {
|
|
startDateInput.value = this.formatDatetimeLocal(startDate);
|
|
}
|
|
if (endDateInput) {
|
|
endDateInput.value = this.formatDatetimeLocal(endDate);
|
|
}
|
|
},
|
|
|
|
isDeviceOnline(lastUpdate) {
|
|
if (!lastUpdate) return false;
|
|
const lastUpdateTime = new Date(lastUpdate);
|
|
const now = new Date();
|
|
const diffMinutes = (now - lastUpdateTime) / (1000 * 60);
|
|
return diffMinutes <= 5;
|
|
},
|
|
|
|
decimalToHex(decimal) {
|
|
const num = parseInt(decimal);
|
|
if (isNaN(num)) return '';
|
|
return num.toString(16).toUpperCase().padStart(6, '0');
|
|
},
|
|
|
|
hexToDecimal(hex) {
|
|
const num = parseInt(hex, 16);
|
|
if (isNaN(num)) return '';
|
|
return num.toString();
|
|
}
|
|
};
|
|
|
|
window.WeatherUtils = WeatherUtils;
|