Skip to content

Commit

Permalink
fix logs sidebar dates
Browse files Browse the repository at this point in the history
  • Loading branch information
blarfoon committed Nov 5, 2024
1 parent aa98e0e commit c82a74f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GameLogEntry } from "@gd/core_module/bindings";
import { Collapsable, Spinner } from "@gd/ui";
import { createSignal, For, Match, Show, Switch } from "solid-js";
import formatDateTime from "./formatDateTime";
import { Trans } from "@gd/i18n";
import { Trans, useTransContext } from "@gd/i18n";

type LogsByTimespan = Record<string, Array<GameLogEntry>>;

Expand All @@ -15,6 +15,8 @@ export type LogsCollapsableProps = {
};

const LogsCollapsable = (props: LogsCollapsableProps) => {
const [t] = useTransContext();

const sortedLogs = () => {
return props.logGroup
.filter((log) => !log.active)
Expand All @@ -36,16 +38,20 @@ const LogsCollapsable = (props: LogsCollapsableProps) => {
const diffTime = Math.abs(today.getTime() - logDate.getTime());
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

console.log(diffDays);

let dateText: string;

if (diffDays === 0) {
dateText = "Today";
} else if (diffDays === 1) {
dateText = "Yesterday";
} else if (diffDays < 7) {
dateText = logDate.toLocaleDateString(undefined, { weekday: "long" });
dateText = t("x_days_ago", { count: diffDays });
} else {
dateText = props.title;
dateText = new Date(logDate).toLocaleDateString(undefined, {
dateStyle: "short"
});
}

return dateText;
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/locale/english/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
"handle_preferences": "Handle Preferences",
"import_instances": "Import instances",
"tracking.setting_disabled": "Disabled",
"x_days_ago": "{{count}} days ago",
"SOON": "SOON",
"tracking.setting_disabled_text": "Almost completely disables any metrics being sent to us. Doing this will also disable some functionalities like sending automatic bug reports and access to preview features.",
"tracking.setting_anonymous": "Anonymous",
Expand Down

0 comments on commit c82a74f

Please sign in to comment.