diff --git a/src/ui/screens/activity-log/sections/commithistory/components/GithubCommitElement.js b/src/ui/screens/activity-log/sections/commithistory/components/GithubCommitElement.js index c2ea8ee4..36698581 100644 --- a/src/ui/screens/activity-log/sections/commithistory/components/GithubCommitElement.js +++ b/src/ui/screens/activity-log/sections/commithistory/components/GithubCommitElement.js @@ -1,30 +1,12 @@ import React from "react"; import { Box, Typography, Link } from "@mui/material"; import GitHubIcon from "@mui/icons-material/GitHub"; +import {mapDate} from "../../../../../utils/dateUtils"; import useTranslation from "../../../../../language/useTranslation"; const GithubCommitElement = ({ commit }) => { const { t } = useTranslation(); - const mapDate = (date) => { - const dateObj = new Date(date); - const today = new Date(); - - dateObj.setHours(0, 0, 0, 0); - today.setHours(0, 0, 0, 0); - - const diffTime = today - dateObj; - const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); - - if (diffDays === 0) { - return t("activityLog.gitCommits.today"); - } else if (diffDays === 1) { - return t("activityLog.gitCommits.yesterday"); - } else { - return t("activityLog.gitCommits.daysAgo", { count: diffDays }); - } - }; - return ( { textAlign: "right", }} > - {mapDate(commit.timestamp)} + {mapDate(commit.timestamp, t)} diff --git a/src/ui/utils/dateUtils.js b/src/ui/utils/dateUtils.js new file mode 100644 index 00000000..8e6cb28d --- /dev/null +++ b/src/ui/utils/dateUtils.js @@ -0,0 +1,18 @@ +export const mapDate = (date, t) => { + const dateObj = new Date(date); + const today = new Date(); + + dateObj.setHours(0, 0, 0, 0); + today.setHours(0, 0, 0, 0); + + const diffTime = today - dateObj; + const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); + + if (diffDays === 0) { + return t("activityLog.gitCommits.today"); + } else if (diffDays === 1) { + return t("activityLog.gitCommits.yesterday"); + } else { + return t("activityLog.gitCommits.daysAgo", { count: diffDays }); + } +};