-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
open history with open end date by default #329
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,91 +25,38 @@ export default function handleDataService() { | |
} | ||
}; | ||
|
||
// разница дат. при start=='now' считает от сегодня | ||
// при end==='now' считает до сегодня с округлением в большую сторону | ||
// может показывать часы если меньше 1 дня | ||
this.diffDates = (start, end, showHours = false, plusOne = false)=> { | ||
if (!start || !end) return undefined; | ||
var endProj; | ||
end = end === 'now' ? +new Date() : +new Date(end); | ||
start = start === 'now' ? +new Date() : +new Date(start); | ||
var _endProj = (end - start) / (24 * 60 * 60000); | ||
_endProj = plusOne ? _endProj + 1 : _endProj; | ||
if (showHours && _endProj < 1) { | ||
//если часы то возвращаю строку а не число | ||
// отнимаю 4 часа для перевода времени | ||
endProj = '' + Math.floor(_endProj * 24 - 4) | ||
} else { | ||
endProj = Math.ceil(_endProj); | ||
} | ||
return (endProj > 0) ? endProj : 0; | ||
}; | ||
|
||
// разница дат в минутах | ||
this.diffDatesInMinutes = (start, end) => { | ||
const s = new Date(start), | ||
e = new Date(end); | ||
return ((+end) - (+start)) / 60000 | ||
}; | ||
|
||
|
||
|
||
// прибавляет дни к дате | ||
this.dayPlusNDays = (dayString, n, returnString = true)=> { | ||
let d = JSON.stringify(new Date(+new Date(dayString) + n * (24 * 60 * 60000))).slice(1, 11); | ||
return returnString ? d : new Date(d) | ||
}; | ||
|
||
this.getOffset = function () { | ||
return (new Date).getTimezoneOffset(); | ||
}; | ||
|
||
// убавляет дни от даты/ можно со временем | ||
this.dayMinusNDays = (dayString,n, returnString = true,withTime=false)=> { | ||
// делаю поправку на отступ | ||
var offset = this.getOffset()/60; | ||
let d = JSON.stringify(new Date(+new Date(dayString) - | ||
n * ((24 + (withTime? offset : 0))* 60 * 60000) )).slice(1, withTime? 20 : 11); | ||
return returnString ? d : new Date(d) | ||
}; | ||
|
||
// добавляет ноль | ||
this.addZeroToDate = (d)=> { | ||
return d<10? '0' + d : d | ||
}; | ||
|
||
// можно со временем без секунд | ||
this.dateYYYYMMDD = (date,withTime = false)=> { | ||
if (!date) return null; | ||
date = typeof date ==='string'? new Date(date) : date; | ||
|
||
var ret = date.getFullYear() | ||
+ "-" + this.addZeroToDate(date.getMonth() + 1) | ||
+ "-" + this.addZeroToDate(date.getDate()); | ||
ret = !withTime? ret : `${ret}T${this.addZeroToDate(date.getHours())}:${this.addZeroToDate(date.getMinutes())}:00`; | ||
return ret | ||
}; | ||
|
||
// разбивает дни на сегменты из N дней | ||
// rangInterval параметр длины интервала графика если не указана начальная точка | ||
// start, end - Date() или undefined | ||
this.splitDate = (start, end, days = 10,rangInterval = 1)=> { | ||
end = end? end : new Date();// если нету то = текущим дате и времени | ||
end = typeof end ==='string'? end : this.dateYYYYMMDD(end,true); | ||
var _end = end? end : new Date();// если нету то = текущим дате и времени | ||
// если нету то = end - инетервал days вместе с минутами | ||
start = start? start : this.dayMinusNDays(end,rangInterval,true,true); | ||
start = typeof start ==='string'? start : this.dateYYYYMMDD(start,true); | ||
var diffDates = this.diffDates(start, end); | ||
if (diffDates <= days) return [start,end]; | ||
var ret = [start]; | ||
var iter = Math.floor(diffDates / days) + 1; | ||
var _start = start ? start : new Date(+_end - 24 * 60 * 60 * 1000 * rangInterval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
var diffDays = (_end - _start) / 1000/ 60/ 60/ 24; | ||
// здесь и ниже: не _end, а исходный end: если конец интервала не был задан, то нам нужно будет так и запрашивать последний чанк с открытым концом | ||
if (diffDays <= days) return [_start, end]; | ||
var ret = [_start]; | ||
var iter = Math.floor(diffDays / days) + 1; | ||
console.log(iter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug? |
||
for (var i = 1; i < iter; i++) { | ||
var actualD = this.dayPlusNDays(start, i * days); | ||
ret.push(actualD); | ||
// если последний проход и текущее значение не совпадает с end | ||
if (i === iter - 1 && actualD !== end) { | ||
ret.push(end); | ||
var actualD = new Date(+_start + i * days * 24 * 60 * 60 * 1000); | ||
if (actualD < _end) { | ||
ret.push(actualD); | ||
} | ||
} | ||
ret.push(end); | ||
return ret | ||
}; | ||
|
||
|
@@ -119,4 +66,4 @@ export default function handleDataService() { | |
return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
wb-mqtt-homeui (2.37.3) stable; urgency=medium | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2.37.1 ? |
||
|
||
* open history with open end date by default | ||
|
||
-- Evgeny Boger <[email protected]> Sat, 04 Jun 2022 15:20:49 +0300 | ||
|
||
wb-mqtt-homeui (2.37.0) stable; urgency=medium | ||
|
||
* Boots selection on logs page is limited to "All boots"/"Last boot" options. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это от отладки осталось?