Timezone bugfix

This commit is contained in:
Kyrylo Gliebov 2018-11-20 17:41:26 +01:00 committed by Kirill Glebov
parent 91877b0570
commit 20138d3e83

View file

@ -50,15 +50,12 @@ let padInt = function (n, w) {
* Format date and time for a number of milliseconds since Epoch. * Format date and time for a number of milliseconds since Epoch.
*/ */
let formatDateTime = function (ms) { let formatDateTime = function (ms) {
let d = new Date(ms); return moment(ms).format("YYYY-MM-DD HH:mm:ss");
return ( };
padInt(d.getFullYear(), 4) + '-' +
padInt(d.getMonth() + 1, 2) + '-' + let formatDateTimeOffset = function (ms, offset) {
padInt(d.getDate(), 2) + ' ' + return moment(ms).utcOffset(offset)
padInt(d.getHours(), 2) + ':' + .format("YYYY-MM-DD HH:mm:ss");
padInt(d.getMinutes(), 2) + ':' +
padInt(d.getSeconds(), 2)
);
}; };
/* /*
@ -234,6 +231,7 @@ class Logs extends React.Component {
this.getLogs = this.getLogs.bind(this); this.getLogs = this.getLogs.bind(this);
this.loadLater = this.loadLater.bind(this); this.loadLater = this.loadLater.bind(this);
this.loadForTs = this.loadForTs.bind(this); this.loadForTs = this.loadForTs.bind(this);
this.getServerTimeOffset = this.getServerTimeOffset.bind(this);
this.journalCtl = null; this.journalCtl = null;
this.entries = []; this.entries = [];
this.start = null; this.start = null;
@ -241,12 +239,23 @@ class Logs extends React.Component {
this.hostname = null; this.hostname = null;
this.earlier_than = null; this.earlier_than = null;
this.state = { this.state = {
serverTimeOffset: null,
cursor: null, cursor: null,
after: null, after: null,
entries: [], entries: [],
}; };
} }
getServerTimeOffset() {
cockpit.spawn(["date", "+%s:%:z"], { err: "message" })
.done((data) => {
this.setState({serverTimeOffset: data.slice(data.indexOf(":") + 1)});
})
.fail((ex) => {
console.log("Couldn't calculate server time offset: " + cockpit.message(ex));
});
}
scrollToTop() { scrollToTop() {
const logs_view = document.getElementById("logs-view"); const logs_view = document.getElementById("logs-view");
logs_view.scrollTop = 0; logs_view.scrollTop = 0;
@ -287,9 +296,20 @@ class Logs extends React.Component {
matches.push("_HOSTNAME=" + this.hostname); matches.push("_HOSTNAME=" + this.hostname);
} }
let start = null;
let end = null;
if (this.state.serverTimeOffset != null) {
start = formatDateTimeOffset(this.start, this.state.serverTimeOffset);
end = formatDateTimeOffset(this.end, this.state.serverTimeOffset);
} else {
start = formatDateTime(this.start);
end = formatDateTime(this.end);
}
let options = { let options = {
since: formatDateTime(this.start), since: start,
until: formatDateTime(this.end), until: end,
follow: false, follow: false,
count: "all", count: "all",
merge: true, merge: true,
@ -320,6 +340,10 @@ class Logs extends React.Component {
this.getLogs(); this.getLogs();
} }
componentWillMount() {
this.getServerTimeOffset();
}
componentDidMount() { componentDidMount() {
if (this.props.recording) { if (this.props.recording) {
if (this.start === null && this.end === null) { if (this.start === null && this.end === null) {