39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
const WeatherUtils = {
|
|
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 = startDate.toISOString().slice(0, 16);
|
|
}
|
|
if (endDateInput) {
|
|
endDateInput.value = endDate.toISOString().slice(0, 16);
|
|
}
|
|
},
|
|
|
|
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;
|