Add ability to configure the locale timezone (#2523)

This commit is contained in:
Arthur Knoepflin authored and GitHub committed 2021-04-20 09:26:52 -04:00
1 parent 8d42d40433
commit 52ebcc4fdb
11 files changed
+84 -8

No files matched your search

+6 -1
View File
@@ -6,9 +6,11 @@ import DOMPurify from "dompurify";
import debounce from "lodash/debounce";
import { action, computed, observable } from "mobx";
import { observer } from "mobx-react";
import moment from "moment-timezone";
import { Align, ListOnScrollProps } from "react-window";
import { SearchStore, searchStore } from "../../../common/search-store";
import { userStore } from "../../../common/user-store";
import { cssNames } from "../../utils";
import { Button } from "../button";
import { Icon } from "../icon";
@@ -79,12 +81,15 @@ export class LogList extends React.Component<Props> {
@computed
get logs() {
const showTimestamps = logTabStore.getData(this.props.id).showTimestamps;
const { preferences } = userStore;
if (!showTimestamps) {
return logStore.logsWithoutTimestamps;
}
return this.props.logs;
return this.props.logs
.map(log => logStore.splitOutTimestamp(log))
.map(([logTimestamp, log]) => (`${moment.tz(logTimestamp, preferences.localeTimezone).format()}${log}`));
}
/**
+10
View File
@@ -146,6 +146,16 @@ export class LogStore {
return stamp.toISOString();
}
splitOutTimestamp(logs: string): [string, string] {
const extraction = /^(\d+\S+)(.*)/m.exec(logs);
if (!extraction || extraction.length < 3) {
return ["", ""];
}
return [extraction[1], extraction[2]];
}
getTimestamps(logs: string) {
return logs.match(/^\d+\S+/gm);
}